String to Int ???

jnbarban

Member
Licensed User
Longtime User
Do you Know how to do that :

B4X:
if MyTextBox.text > 0  then
...
end if

( MyTextBox.text = "1234")

i've got this error : " NumberFormatException"

It is not possible to do somthing like cint(MyTextBox.text) in order to get me a Integer of my text value ?
 

vangogh

Active Member
Licensed User
Longtime User
to "bypass" a null string, I always use

"0" & MyTextBox.text > 0

so it the textbox is empty, this gives

"0" & "" = 0

if it is "1234" -> "01234" > 0

it works :sign0137:
 
Upvote 0

fabero

Member
Licensed User
Longtime User
to "bypass" a null string, I always use

"0" & MyTextBox.text > 0

so it the textbox is empty, this gives

"0" & "" = 0

if it is "1234" -> "01234" > 0

it works :sign0137:

Can someone explain more a bit? I've the same problem.. :BangHead::BangHead:
 
Upvote 0

vangogh

Active Member
Licensed User
Longtime User
simply use the debugger and try my suggestion step by step... it works :cool:

my post isn't a problem but a workaround :sign0060:
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Can someone explain more a bit? I've the same problem.. :BangHead::BangHead:

Let's say the user enters nothing in the text box

Since you're checking 0 & textbox.text, it will read "0" which is a number, instead of crashing.

You can also just use IsNumber () to check if it's valid first
 
Last edited:
Upvote 0
Top