decimal to string conversions

Charlie_M

Member
Licensed User
Hi Gang,

I have variable that is dimensioned as a Double and I want to place a value in it from a edittext box. Do I need to do any string conversions first? I read that B4A handles this automatically, but I get compilation errors.

For example here is some sudo code:

Dim I as Double

I = edittext1.text
 

Mahares

Expert
Licensed User
You can trap the error like this:
B4X:
Dim I as double
If IsNumber(Edittext1.Text) Then
         I=Edittext1.text
Else
         Msgbox("Edit text box is not a number","")
End If
 
Upvote 0

Charlie_M

Member
Licensed User
Thanks. Do I need to trap the error? and Actually If I have something like

Dim I as Double

I = EditText1.text

It won't compile. I get a slew of error messages. So I am guessing that this sort of thing is not allowed.
 
Upvote 0

klaus

Expert
Licensed User
The error you get is not a compiling error but a runtime error !
I suspect that your EditText1 view is empty.
So EditText1.Text is an empty string which cannot be converted into a Double!
You should either enter a default value into EditText1 or trap the error.
This code does work !
B4X:
Dim i As Double
EditText1.Text = "0"
i = EditText1.Text
Best regards.
 
Upvote 0

Beja

Expert
Licensed User
Thank you klaus Is this documented somewhere?

Null value can not be accepted as numeric variable and this I think is true
for all languages, not just b4a.
Also check if the (number) in the edit text box does not contain a null char, like:
"12 " because the space will render the whole value as if it is NULL. so make
sure there is no space anywhere inside the quotation marks.
 
Upvote 0
Top