Menu

Error: Array/Function STRINGTOWORD has not been declared

Help
JB
2024-06-25
2024-07-02
  • JB

    JB - 2024-06-25

    Hi everyone,

    I hope this request is easy to fix.

    I'm looking to work with (Function STRINGTOWORD) and after trying an code example from GCBASIC documentation String Manipulation section, I've got this error

    (Error: Array/Function STRINGTOWORD has not been declared)

    I assumed all examples code are fully documented with all the declarations and so on, to avoid any confusion
    but It seem I'm out of luck with this one.

    Also, does this code error (if it is) is repeated for all the sample code in the GBasic documentation.

    see code listing.

    Thank's to all for helping.

    #chip tiny85,8
    #option explicit
    
    ; ----- Variables
        dim bytevar as Byte
        dim wordvar as Word
        dim longvar as long
    
        bytevar = 0
        wordvar = 0
        longvar = 0
    
        ; ----- Main body of program commences here.
    
         #option Explicit
    
        ; do
             wait 100 ms
    
             Wordvar = StringToWord( "65535" )
            ; HSerPrint WordVar
            ; HSerPrintCRLF
    
          ;   wait 1 s
         ; loop
        end
    
     
  • Anobium

    Anobium - 2024-06-25

    I will have to look into this.

    Please use VAL() This is an overloaded function and StringToWord() would give the same result.

    Evan

     
  • JB

    JB - 2024-06-25

    Thank's Evan, it's work fine, also how can I format
    the the Val to String with coma delimited
    regards.

     
  • JB

    JB - 2024-06-25

    I'm looking to get a word or long var, and format it as a string with coma. as 65,535 / 4,123,456,789

     
  • Anobium

    Anobium - 2024-06-25

    Try the attached .h file. Please replace the existing file in your lowlevel folder.

    Now supports StringToByte, StringToWord and now... supports commas as in "65,535" and "4,123,456,789"

    Please test and let me know the result.

    Evan

     
  • JB

    JB - 2024-06-25

    Thank's Evan for a quick reply .

    I did test the StringToLong and LongTo String
    (see the result from the code listing ; LCD Display = xxxxxxx)

    I guess it's working fine now, and if you can explain how
    to format the LongToString to be displayed as : 4,123,456,789 on the LCD
    maybe there's a format function that I'm not aware as:
    1,234,567,890
    12,555.00 with comma, and/or period if needed.

    #chip tiny85,8 
    
    #option explicit
    #include <SoftSerial.h>
    DIR PORTB B'00010000'    ; ATMEL 0=IN, 1=OUT / PIC 0=OUT, 1=IN
    
        ; ----- Config Serial UART for sending:
        #define Ser1_BAUD 4800     ; baudrate must be defined
        #define Ser1_TXPORT PORTB  ; I/O port (without .bit) must be defined
        #define Ser1_TXPIN 4       ; portbit  must be defined
        #define Ser1_INVERT ON     ; Polarity inverted On/Off
        ;#define Ser1_TXDELAY 1    ; Tx delay
        #define Ser1_TXDELAYms 1    ; Tx delay (min:1/1.3ms)
        ;#define Ser1_TXDELAYus 300    ; Tx delay (min:300/400us)
    
    Dim Result as Long
    ser1send 254 ;clear LCD
    ser1send 1
    
    -----
    
    ;Long to String
    Result = 4123456789
    Ser1Print LongToString(Result)  ; LCD Display = 4123456789
    
    String to Long
    ;Result = StringToLong("4,123,456,789")
    ;Ser1Print Result               ; LCD Display = 4123456789
    
     
  • Anobium

    Anobium - 2024-06-26

    I would create a function to:

    Iterate through the string and output a "," every three chars. Iteration needs to be right to left ( reverse through the string).

    "4123456789", so handle as 987 then "," then 654 etc. As you putting onto an LCD then you can address the LCD.

     
  • JB

    JB - 2024-06-26

    I guess with the "LEN" and "RIGHT" String manipulation or so.
    please take your time, I don't want to give you more work as it is.
    Thank you Evan for you r great support.

     
  • Anobium

    Anobium - 2024-06-26

    A quicker way... see attached.

    This walks the string number and then shows on the screen with commas ( or whatever char you want ). It may not be perfect but this is a really easy way to do things.

    :-)

        ' max number 4294967295
        Sub FormatCommaNumberToString ( in _invalue as Long, _LCDXPos, _LCDYPos ) 
    
    
            Dim _tempString as String
            // Assing long number as a string
            _tempString = LongToString( _invalue )
    
            Dim _stringindex, _pointer, _pointvalue as Byte
            _pointer = 1
    
            For _stringindex = len(_tempString) to 1 Step -1
    
                Locate _LCDYPos, _LCDXPos
                Print CHR(_tempString(_stringindex))
                _LCDXPos--
                _pointer++
    
                If _pointer MOD 4 = 0  AND len(_tempString) <> _pointer then 
                    Locate _LCDYPos, _LCDXPos
                    Print  ","
                    _LCDXPos--
                    _pointer++
                End If
    
            Next
    
        End Sub
    
     
  • JB

    JB - 2024-06-26

    Many thank's Evan

     
  • Anobium

    Anobium - 2024-06-26

    JB - here is a Sub() that works.

        ' max number 4294967295
        Sub FormatCommaNumberToString ( in _invalue as Long, in _LCDXPos, in _LCDYPos ) 
    
            Dim _tempString as String
            // Assing long number as a string
            _tempString = LongToString( _invalue )
    
            Dim _stringindex, _pointer, _pointvalue as Byte
            _pointer = 0
    
            For _stringindex = len(_tempString) to 1 Step -1
    
    
                If _pointer MOD 3 = 0  AND len(_tempString) <> _pointer and _stringindex <> len(_tempString) then 
                    Locate _LCDYPos, _LCDXPos
                    Print  ","
                    _LCDXPos--
                End If
    
                Locate _LCDYPos, _LCDXPos
                Print CHR(_tempString(_stringindex))
                _LCDXPos--
                _pointer++
    
            Next
    
        End Sub
    

    I have now tested, as follows:

    Longvar = StringToLong( "4294967295" )
    Print LongVar
    Locate 1,0
    Dim LCDXPos, LCDYPos as Byte 
    LCDXPos = 19
    LCDYPos = 1
    FormatCommaNumberToString( LongVar, LCDXPos, LCDYPos )
    wait 1 s: CLS
    FormatCommaNumberToString( 0, LCDXPos, LCDYPos )
    wait 1 s: CLS
    FormatCommaNumberToString( 1, LCDXPos, LCDYPos )
    wait 1 s: CLS
    FormatCommaNumberToString( 10, LCDXPos, LCDYPos )
    wait 1 s: CLS
    FormatCommaNumberToString( 100, LCDXPos, LCDYPos )
    wait 1 s: CLS
    FormatCommaNumberToString( 1000, LCDXPos, LCDYPos )
    wait 1 s: CLS
    FormatCommaNumberToString( 10000, LCDXPos, LCDYPos )
    wait 1 s: CLS
    FormatCommaNumberToString( 10000, LCDXPos, LCDYPos )
    wait 1 s: CLS
    FormatCommaNumberToString( 100000, LCDXPos, LCDYPos )
    wait 1 s: CLS
    FormatCommaNumberToString( 1000000, LCDXPos, LCDYPos )
    wait 1 s: CLS
    FormatCommaNumberToString( 10000000, LCDXPos, LCDYPos )
    wait 1 s: CLS
    FormatCommaNumberToString( 100000000, LCDXPos, LCDYPos )
    wait 1 s: CLS
    FormatCommaNumberToString( 1000000000, LCDXPos, LCDYPos )
    wait 1 s: CLS
    FormatCommaNumberToString( 4294967295, LCDXPos, LCDYPos )
    
     
  • JB

    JB - 2024-06-27

    Thank you Evan,

    Also I'm coding about String parsing:

    If I may ask about "Conditional Operation"

    All attempt to use does not work properly.

    Compiling work fine no error, what could be my mistake.

    Is it possible to use multiple condition as and / or on the same line

    if mid(ResultStr,index,1)= "A" then
    or
    if CHR(mid(ResultStr,index,1))= "A" then
    or
    if val(Mid(ResultStr,index,1)) > 44 or Val(Mid(TempStr,index,1)) < 58 then

    Many Thank's again Evan.

    ;String Parsing
    #chip tiny85,8
    #DEFINE  SYSDEFAULTCONCATSTRING  4
    #option explicit
    
    #include <SoftSerial.h>
    DIR PORTB B'00010000'    ; ATMEL 0=IN, 1=OUT / PIC 0=OUT, 1=IN
    
        ; ----- Config Serial UART for sending:
        #define Ser1_BAUD 4800     ; baudrate must be defined
        #define Ser1_TXPORT PORTB  ; I/O port (without .bit) must be defined
        #define Ser1_TXPIN 4       ; portbit  must be defined
        #define Ser1_INVERT ON     ; Polarity inverted On/Off
        ;#define Ser1_TXDELAY 1    ; Tx delay
        ;#define Ser1_TXDELAYms 1    ; Tx delay (min:1/1.3ms)
        #define Ser1_TXDELAYus 500    ; Tx delay (min:300/400us)
    
    ;Var
    Dim ResultStr as String
    Dim TempStr as String
    Dim index as byte
    
    ;Screen Routine
    gosub ClearLCD
      ser1send 255
      ser1send 8   ;LCD BackLight On
      pause 500
    
    ;Setup Var
    ResultStr =  "0123456789AABBCCDDEE"
    TempStr = ""
    
    ;Parsing
    for index = 1 to len(ResultStr)
        ;if val(Mid(ResultStr,index,1)) > 44 or Val(Mid(TempStr,index,1)) < 58 then
        ;if CHR(mid(ResultStr,index,1))= "A" then
        if mid(ResultStr,index,1)= "A" then
          TempStr = TempStr + "#"
        else
          TempStr = TempStr + Mid(ResultStr,index,1)
        end if
    next
    
    
    ;Result
    ResultStr = mid(TempStr,20)
    
    ;Display Line 1
    ser1send 254
    ser1send 128
    Ser1Print ResultStr
    
    ;Display Line 2
    ser1send 254
    ser1send 192
    Ser1Print len(ResultStr)
    
    end
    
    ClearLCD:
      ser1send 254 ;clear LCD
      ser1send 1
      pause 200
    return
    
     
    • Anobium

      Anobium - 2024-06-27

      Yes that should work but very very inefficient.

      if ResultStr(index) > 44 etc will work. Why ? a string is held in RAM and you can address each part of the string like an array.

       
  • JB

    JB - 2024-07-02

    You're right Evan,

    Why? ,.....( a string is held in RAM and you can address each part of the string like an array )

    I mostly use var - > ResultStr = "0123456789AABBCCDDEE" for a quick test

    and it's work in PBP3, Picaxe, Positron, and GBasic it seem.

    Why? it's working

    I realy don't know, you're the best qualified person to answer this enigma.

     
    • Anobium

      Anobium - 2024-07-02

      :-)

      What is the question?

       
  • JB

    JB - 2024-07-02

    if there's no DIM, does the var should work

     
  • Anobium

    Anobium - 2024-07-02

    no DIM ?

    If you have #option explicit then you need to DIM all variables.

    if there's no DIM, does the var should work

    Got an example to help me understand?

     
  • JB

    JB - 2024-07-02

    No , I found out my mistake.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.