C Charlie_M Member Licensed User Longtime User Jun 4, 2013 #1 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
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
M Mahares Expert Licensed User Longtime User Jun 4, 2013 #2 You can trap the error like this: Code: Copy 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
You can trap the error like this: Code: Copy Dim I as double If IsNumber(Edittext1.Text) Then I=Edittext1.text Else Msgbox("Edit text box is not a number","") End If
C Charlie_M Member Licensed User Longtime User Jun 4, 2013 #3 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
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.
klaus Expert Licensed User Longtime User Jun 4, 2013 #4 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 ! Code: Copy Dim i As Double EditText1.Text = "0" i = EditText1.Text Best regards. Upvote 0
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 ! Code: Copy Dim i As Double EditText1.Text = "0" i = EditText1.Text Best regards.
C Charlie_M Member Licensed User Longtime User Jun 4, 2013 #5 Thank you klaus Is this documented somewhere? Upvote 0
Beja Expert Licensed User Longtime User Jun 5, 2013 #7 Thank you klaus Is this documented somewhere? Click to expand... 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
Thank you klaus Is this documented somewhere? Click to expand... 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.