I have the need to cast a string (contained into an array of strings) into a Long, or a Float. I've already tried to assign the string to a Long variable, but with no luck.
In general, what I need to do is:
Public results(7) as String*100
Public policy as Long
...
policy = results(2) 'e.g. results(2) contains the string 12
policy = policy+30 'this sum must return 42, now returns 1230 (string concatenation)
I've found functions to convert from number to string, but not vice-versa.
The following code is working correctly for me:
Public results(7) As String * 100
Public policy As Long
BeginProg
results(2) = "12"
Scan (1,Sec,3,0)
policy = results(2) 'e.g. results(2) contains the string 12
policy = policy+30 'this sum must return 42
NextScan
EndProg
When you do Variable1 = Variable2 in CRBasic, it does an implicit type cast. A string should always be cast into a Long or Float before you try adding a number to it. The '+' operator has odd behavior in some cases when used on strings.
Ok, that works for me.
Sorry, my code was a little different, actually. I summed 30 "inline", sort of
policy = results(2)+30
which actually concateneted the string "30" to results(2)