Okay, so I've written a more comprehensive Val() function that converts integers and floats (using the built-in functionality described above) as well as hex and binary strings. Hex values can begin with either "0x" or "#" ...I know there's a standard prefix for binary values, but I can't recall what it is--I've used "$"
Local Value%
Print Val("37")
Print Val("3-7")
Print Val("50.1")
Print Int(Val("0xFFFF"))
Print Val("#FF")
Value = Val("$10010010")
Print Value
End
Function Val#(StringNumeric$)
Local Num# = 0
Local Hex1 = (Left$(StringNumeric$,1)="#")
Local Hex2 = (Left$(StringNumeric$,2)="0x")
Local Binary = (Left$(StringNumeric$,1)="$")
Local c
If Hex1 Or Hex2
StringNumeric$ = Upper(StringNumeric$)
For c=(Hex1 + (Hex2 * 2) + 1) To Len(StringNumeric$)
Select Mid$(StringNumeric$,c,1)
Case "1","2","3","4","5","6","7","8","9","0"
Num# = (Num# * 16) + Asc(Mid$(StringNumeric$,c,1))-48
Case "A","B","C","D","E","F"
Num# = (Num# * 16) + Asc(Mid$(StringNumeric$,c,1))-55
Default
Return Num#
End Select
Next
Else
If Binary
For c=2 To Len(StringNumeric$)
Select Mid$(StringNumeric$,c,1)
Case "1"
Num# = (Num# * 2) + 1
Case "0"
Num# = (Num# * 2)
Default
Return Num#
End Select
Next
Else
Num# = StringNumeric$
EndIf
EndIf
Return Num#
End Function
Anybody have any suggestions? Otherwise, I'll post it over in the code archives.