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.
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>DIRPORTBB'00010000';ATMEL0=IN,1=OUT/PIC0=OUT,1=IN;-----ConfigSerialUARTforsending:#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;#defineSer1_TXDELAY1;Txdelay#define Ser1_TXDELAYms 1 ; Tx delay (min:1/1.3ms);#defineSer1_TXDELAYus300;Txdelay(min:300/400us)DimResultasLongser1send254;clearLCDser1send1-----;LongtoStringResult=4123456789Ser1PrintLongToString(Result);LCDDisplay=4123456789StringtoLong;Result=StringToLong("4,123,456,789");Ser1PrintResult;LCDDisplay=4123456789
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
' 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
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.
;StringParsing#chip tiny85,8#DEFINE SYSDEFAULTCONCATSTRING 4#option explicit#include<SoftSerial.h>DIRPORTBB'00010000';ATMEL0=IN,1=OUT/PIC0=OUT,1=IN;-----ConfigSerialUARTforsending:#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;#defineSer1_TXDELAY1;Txdelay;#defineSer1_TXDELAYms1;Txdelay(min:1/1.3ms)#define Ser1_TXDELAYus 500 ;Txdelay(min:300/400us);VarDimResultStrasStringDimTempStrasStringDimindexasbyte;ScreenRoutinegosubClearLCDser1send255ser1send8;LCDBackLightOnpause500;SetupVarResultStr="0123456789AABBCCDDEE"TempStr="";Parsingforindex=1tolen(ResultStr);ifval(Mid(ResultStr,index,1))>44orVal(Mid(TempStr,index,1))<58then;ifCHR(mid(ResultStr,index,1))="A"thenifmid(ResultStr,index,1)="A"thenTempStr=TempStr+"#"elseTempStr=TempStr+Mid(ResultStr,index,1)endifnext;ResultResultStr=mid(TempStr,20);DisplayLine1ser1send254ser1send128Ser1PrintResultStr;DisplayLine2ser1send254ser1send192Ser1Printlen(ResultStr)endClearLCD:ser1send254;clearLCDser1send1pause200return
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
I will have to look into this.
Please use VAL() This is an overloaded function and StringToWord() would give the same result.
Evan
Thank's Evan, it's work fine, also how can I format
the the Val to String with coma delimited
regards.
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
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
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.
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.
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.
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.
:-)
Many thank's Evan
JB - here is a Sub() that works.
I have now tested, as follows:
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.
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.
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.
:-)
What is the question?
if there's no DIM, does the var should work
no DIM ?
If you have #option explicit then you need to DIM all variables.
Got an example to help me understand?
No , I found out my mistake.