B b4anewbie New Member Sep 19, 2014 #1 hi guys I just got a problem . I need to convert an edittext string into a number so as to use for a calculation . I have tried the following : Dim i AsInt i = EditText.Text + 1 but unfortunately it doesn't work at all ! please someone tell me how to do that . in vb we do sth like this : Val(sting) but I don't know how it is done in B4A . by the way , I've searched allover the forum but nothing found ! Thanks in advance
hi guys I just got a problem . I need to convert an edittext string into a number so as to use for a calculation . I have tried the following : Dim i AsInt i = EditText.Text + 1 but unfortunately it doesn't work at all ! please someone tell me how to do that . in vb we do sth like this : Val(sting) but I don't know how it is done in B4A . by the way , I've searched allover the forum but nothing found ! Thanks in advance
Erel B4X founder Staff member Licensed User Longtime User Sep 21, 2014 #2 Your code is correct. The compiler will convert the string automatically. However you should use IsNumber to make sure that the text is actually a valid number: Code: Copy If IsNumber(EditText.Text) Then Dim i As Int = EditText.Text + 1 End If Upvote 0
Your code is correct. The compiler will convert the string automatically. However you should use IsNumber to make sure that the text is actually a valid number: Code: Copy If IsNumber(EditText.Text) Then Dim i As Int = EditText.Text + 1 End If
netsistemas Active Member Licensed User Longtime User Sep 29, 2015 #3 You can include this function is yout favorite module (utils). public Sub Val(Txt As String) As Double If IsNumber(Txt) Then Return Txt Else Return 0 End If End Sub And you can replace txt by txt.replace(",",".") or similar in evaluated code. Upvote 0
You can include this function is yout favorite module (utils). public Sub Val(Txt As String) As Double If IsNumber(Txt) Then Return Txt Else Return 0 End If End Sub And you can replace txt by txt.replace(",",".") or similar in evaluated code.