Tuesday, March 20, 2012

SmallBasic String to Number conversion

It turns out that I don't need to do this as MS SmallBasic keeps everything in string. So, you don't need to mess with it.

Sub AtoI
'tstring - string containing number
istring=0
isign=1
iperiod=0

For s=1 To Text.GetLength(tstring)
iindex=Text.GetIndexOf(tempNum,Text.GetSubText(tstring,s,1))
If iindex=0 Then
istring=0
s=Text.GetLength(tstring+1)
ElseIf iindex=1 then
isign=-1
elseif iindex=2 then
iperiod=1
Else
istring=(istring*10)+(iindex-3)
iperiod=iperiod*10
EndIf
EndFor
istring=(istring/iperiod)*isign
EndSub

No comments: