String Functions issues

Questions about the BASICtools and MakeItC
olzeke51
Posts: 274
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina
Contact:

String Functions issues

Postby olzeke51 » Sat Nov 11, 2017 3:10 am

Hello BasicChip,

While investigating string functions for an LCD based Dice Roller project, I came across 2 errors in Strings.
'
Error 1:
this BT based 'Help'; topic [STR] example fails:: "
bst = 123 + "test123"
bst will remain empty.... --BUT it will work if the 'test123' part is FIRST!!!"
'
Error 2:
' the following line is copied from the BT based 'Help'; topic [String Functions]
' it fails to compile
'ast = ast + "abcd" + str(2 + 44 / 23) + str(len(cst)) + "zcxv" + chr(13) + "more stuff" + bst
Programming Flash 1114...

ast = ast + "abcd" + str(2 + 44 / 23) + str(len(cst)) + "zcxv" + chr(13) + "more stuff" + bst
-ERROR C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 43: Expected Operand

ast = ast + "abcd" + str(2 + 44 / 23) + str(len(cst)) + "zcxv" + chr(13) + "more stuff" + bst
-ERROR C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 43: expected expression

ast = ast + "abcd" + str(2 + 44 / 23) + str(len(cst)) + "zcxv" + chr(13) + "more stuff" + bst
-First ERROR at line :43

I did test each of the "STR(functions)" individually and printed out their results -- see the .jpg
'
the attached files :: the .jpg shows Error 1 only - as I commented out the "Error 2" statement.
:: the .bas is my program with Error 2 enabled (and 'bst' is still empty

STRING_VARS_errs.bas
Error 2 enabled
(1.52 KiB) Downloaded 2 times

*
*
string-var-errs.jpg
a run with Error 1
string-var-errs.jpg (100.17 KiB) Viewed 49 times

olzeke51
Posts: 274
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina
Contact:

Re: String Functions issues

Postby olzeke51 » Sat Nov 11, 2017 3:17 pm

Some troubleshooting results, that might shed some light on the Error 2:
original code and errors:: on a Vista Home SP1; latest (5 days ago) 'setupBasic.exe',

Code: Select all

Programming Flash 1114...

ast = ast + "abcd" + str(2 + 44 / 23) + str(len(cst)) + "zcxv" + chr(13) + "more stuff" + bst
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 44: Expected Operand

ast = ast + "abcd" + str(2 + 44 / 23) + str(len(cst)) + "zcxv" + chr(13) + "more stuff" + bst
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 44: expected expression

'
1) replaced the '+' with '&' - no apparent change
'
2) using the '&' ; I moved some text between the two str() functions
and got different error messages::

Code: Select all

   Programming Flash 1114...

ast = ast & "abcd" & str(2 + 44 / 23) & "zcxv" & str(len(cst)) & chr(13) & "more stuff" & bst
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 43: expected comparison operator

ast = ast & "abcd" & str(2 + 44 / 23) & "zcxv" & str(len(cst)) & chr(13) & "more stuff" & bst
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 43: Expected Operand

ast = ast & "abcd" & str(2 + 44 / 23) & "zcxv" & str(len(cst)) & chr(13) & "more stuff" & bst
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 43: expected expression

ast = ast & "abcd" & str(2 + 44 / 23) & "zcxv" & str(len(cst)) & chr(13) & "more stuff" & bst
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 43: Expected Operand

ast = ast & "abcd" & str(2 + 44 / 23) & "zcxv" & str(len(cst)) & chr(13) & "more stuff" & bst
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 43: expected expression

'
3) with just one of the str() functions in line::

Code: Select all

Programming Flash 1114...

ast = ast & "abcd" & str(2 + 44 / 23) & "zcxv" & chr(13) & "more stuff" & bst
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 44: expected comparison operator

ast = ast & "abcd" & str(2 + 44 / 23) & "zcxv" & chr(13) & "more stuff" & bst
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 44: Expected Operand

ast = ast & "abcd" & str(2 + 44 / 23) & "zcxv" & chr(13) & "more stuff" & bst
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 44: expected expression


4) removed the str(2+44/33) part only [str(len)) is back in]::

Code: Select all

Programming Flash 1114...

ast = ast & "abcd" & "zcxv" & str(len(cst)) & chr(13) & "more stuff" & bst
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 44: expected comparison operator

ast = ast & "abcd" & "zcxv" & str(len(cst)) & chr(13) & "more stuff" & bst
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 44: Expected Operand

ast = ast & "abcd" & "zcxv" & str(len(cst)) & chr(13) & "more stuff" & bst
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 44: expected expression

'
5) putting the 'text' between the str() changes the error printouts !!!
AND just either str(), added this error also!!! "expected comparison operator"
HTH - GaryZ

basicchip
Posts: 759
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: String Functions issues

Postby basicchip » Sun Nov 12, 2017 12:52 am

As the doctor said, "well don't do that"

the multiple str functions in the statement are too complex to be handled in a single line. I'll have to fix that example in the help files.
So you should be able to do --

Code: Select all

ast = "something" + str(something)
ast = ast + str(something


That's for the first error, can you boil down the next one?

olzeke51
Posts: 274
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina
Contact:

Re: String Functions issues

Postby olzeke51 » Sun Nov 12, 2017 1:01 am

in the event you would need to take an integer (say of a temperature) and add it
to the word F or C, it would take two statements::

Code: Select all

Programming Flash 1114...

  bst = STR(123) + "test123"
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 18: expected comparison operator

  bst = STR(123) + "test123"
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 18: Expected Operand

  bst = STR(123) + "test123"
-ERROR  C:/Users/Olzeke51/Documents/Coridium/DICEer/STRING_VARS_errs.bas: 18: expected expression

  bst = STR(123) + "test123"
-First ERROR at line  :18

'
you are right - the examples need to be changed

basicchip
Posts: 759
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: String Functions issues

Postby basicchip » Sun Nov 12, 2017 1:03 am

And the initial bst confuses the compiler with the implied string function. So it looks like you will need to do str(first_number)

Code: Select all

bst = 123+"something"            ' DOES NOT work
bst = "something" + 123          ' works
bst = str(123)+"something"      ' seems to not work as a single line either


I'll look into fixing that.

olzeke51
Posts: 274
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina
Contact:

Re: String Functions issues

Postby olzeke51 » Sun Nov 12, 2017 1:05 am

Error 2 might be tied into the same underlying issue of "Error 1'
'
it will have to be broken up into multiple statements
and the examples reworked.

end of line

olzeke51
Posts: 274
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina
Contact:

Re: String Functions issues

Postby olzeke51 » Sun Nov 12, 2017 12:22 pm

did some further testing, in this order :: str(len(cst))
1) text + str(len)................ ok
2) text + 123............................. ok
3) text + 123 + str(len)................ ok
4) text + 456 + text +123 + str(len)..compiles but locks up at 'Executing"
5) text + 456 + text.................... ok
6) ext + 456 + text +123.............. compiles but locks up at 'Executing"
7) text + 456 + text + str(len)........ ok
8) text + str(len) + text + str(len)... no compiles
9) text + str(len) + text............... no compiles
10)text + str(987) + text.............. no compiles
11)text + 567 + text + str(987)....... compiles but locks up at 'Executing"

'
and this is the code::

Code: Select all

#if  defined LPC1114
#include "LPC11xx.bas"

#else
  #error undefined CPU type   
#endif         

' * * * * * * * * * *
MAIN:

DIM ast(30) as string
DIM bst(30) as string
DIM cst(30) as string

 ast = "abcd"
  bst = "wxyz"
 cst = "123456789012345678901234567890"
 
 print "ast is ", ast
 print "bst is ", bst
 print "cst is ", cst
 
 ast = ast + "abcd" +   "zcxv" + 567 + "more stuff" + bst + str(987)

print  ast


   END

'
and the thot plickens
HTH - maybe you can spot a common denominator, stack issue, string nesting ???
GaryZ


Return to “Software issues”

Who is online

Users browsing this forum: No registered users and 4 guests