Returning the value of a string (like val(string) )

Maartensaps

Member
Licensed User
Longtime User
I used to program in Clipper and Qbasic and in those there was a simple way to return the value of a string (if the string contains digits)
It was VAL(string) and it would return the value of "string" starting at the first character, until the last or until the first non-digit-character.
Basically it is the opposite of CHR(int)

I would like to use it to convert stored strings (in a preference file) back to its numbers.
Now I use a sub that compares and returns, but with multi-digit strings this becomes quit complex. Especially if a decimal sign is used.:BangHead:

Did I miss it? or is it not there?
And... will it be there in the future ?

Maarten
 

Maartensaps

Member
Licensed User
Longtime User
Great !!!

Isn't life amazing.

And I was building complicated subroutines with iterations that tested for numbers and decimal points etc etc etc... duh!

Thanks!
 

Taha

Member
Licensed User
Longtime User
Basic4android compiler will convert strings automatically.
For example this code is valid:
B4X:
Dim i As Int = "34" * 2

Can you make the same with:

B4X:
Dim i As Int = "34 * 2"

:sign0089:
 

Mahares

Expert
Licensed User
Longtime User
B4X:
Dim i As Int = "34 * 2"   'Not valid
B4X:
Dim i As String = "34 * 2"   'returns: 34*2
B4X:
Dim i As String = "34 * 2"
Dim Member() As String 
Member=Regex.Split("\*",i) 
Msgbox(Member(0) *Member(1),"")  'returns 68
B4X:
Dim i As Int = "34" * 2 'returns 68
B4X:
Dim i As Int = "34" * "2" 'returns 68
 
Top