nfordbscndrd Well-Known Member Licensed User Longtime User Feb 2, 2011 #1 Is there a simple replacement in B4A for VB's "Val" command; e.g.: i = Val(editText1) ? I've spent a lot of time experimenting and searching for an answer and can't find it. Last edited: Feb 3, 2011
Is there a simple replacement in B4A for VB's "Val" command; e.g.: i = Val(editText1) ? I've spent a lot of time experimenting and searching for an answer and can't find it.
Erel B4X founder Staff member Licensed User Longtime User Feb 3, 2011 #2 Basic4android automatically converts strings to numbers as needed: Code: Copy Dim i As Int i = EditText.Text + 3 You can also use IsNumber to check if the string can be converted to number. Upvote 0
Basic4android automatically converts strings to numbers as needed: Code: Copy Dim i As Int i = EditText.Text + 3 You can also use IsNumber to check if the string can be converted to number.
nfordbscndrd Well-Known Member Licensed User Longtime User Feb 3, 2011 #3 Erel said: Basic4android automatically converts strings to numbers as needed: Code: Copy Dim i As Int i = EditText.Text + 3 You can also use IsNumber to check if the string can be converted to number. Click to expand... I tried that and got an error. Edit: I just tried it again using If IsNumber(EditText) Then i = EditText Else i = 0 and didn't get the error. I didn't realize that IsNumber was a requirement. Last edited: Feb 3, 2011 Upvote 0
Erel said: Basic4android automatically converts strings to numbers as needed: Code: Copy Dim i As Int i = EditText.Text + 3 You can also use IsNumber to check if the string can be converted to number. Click to expand... I tried that and got an error. Edit: I just tried it again using If IsNumber(EditText) Then i = EditText Else i = 0 and didn't get the error. I didn't realize that IsNumber was a requirement.
W WZSun Member Licensed User Longtime User Feb 3, 2011 #4 Maybe this will work If IsNumber(EditText.text) Then i = EditText.text Else i = 0 Upvote 0
nfordbscndrd Well-Known Member Licensed User Longtime User Feb 3, 2011 #5 WZSun said: Maybe this will work If IsNumber(EditText.text) Then i = EditText.text Else i = 0 Click to expand... We crossed posts. I put that in an edit to my last post 10 minutes ago. I was hoping I did it before anyone had time to reply. You're just too fast! The documentation does not read like IsNumber is a requirement, but it appears to be. I'll have to go to the Wish List forum and put in a vote for Val(string). It also seems that when an EditText view is set to NUMBERS for Input Type, the value returned should be a number instead of a string, but maybe there is some practical reason for returning a string that I'm not considering. Upvote 0
WZSun said: Maybe this will work If IsNumber(EditText.text) Then i = EditText.text Else i = 0 Click to expand... We crossed posts. I put that in an edit to my last post 10 minutes ago. I was hoping I did it before anyone had time to reply. You're just too fast! The documentation does not read like IsNumber is a requirement, but it appears to be. I'll have to go to the Wish List forum and put in a vote for Val(string). It also seems that when an EditText view is set to NUMBERS for Input Type, the value returned should be a number instead of a string, but maybe there is some practical reason for returning a string that I'm not considering.
Erel B4X founder Staff member Licensed User Longtime User Feb 3, 2011 #6 EditText.Text is always a string. The compiler automatically adds the code required to parse the string as a number when needed. If the EditText.Text is empty or contains any string value that cannot be parsed as a number it will throw an error. IsNumber is a safety check to make sure that the value can be parsed correctly. Upvote 0
EditText.Text is always a string. The compiler automatically adds the code required to parse the string as a number when needed. If the EditText.Text is empty or contains any string value that cannot be parsed as a number it will throw an error. IsNumber is a safety check to make sure that the value can be parsed correctly.