Yves Mazzon Member Licensed User Longtime User Nov 11, 2014 #1 Hello all, I'm new with B4a so please bear with me. In my program the operator enter a value let say 2.65 in the edit text box, how can I extract the numerical value from the text to be able to use it in an equation? many thanks. Yves
Hello all, I'm new with B4a so please bear with me. In my program the operator enter a value let say 2.65 in the edit text box, how can I extract the numerical value from the text to be able to use it in an equation? many thanks. Yves
Erel B4X founder Staff member Licensed User Longtime User Nov 11, 2014 #2 1. Make sure that the string is a valid number. 2. Assign it to a floating point variable. Code: Copy Dim num As Double If IsNumber(EditText1.Text) Then num = EditText1.Text End If Upvote 0
1. Make sure that the string is a valid number. 2. Assign it to a floating point variable. Code: Copy Dim num As Double If IsNumber(EditText1.Text) Then num = EditText1.Text End If
Yves Mazzon Member Licensed User Longtime User Nov 11, 2014 #3 Erel said: 1. Make sure that the string is a valid number. 2. Assign it to a floating point variable. Code: Copy Dim num As Double If IsNumber(EditText1.Text) Then num = EditText1.Text End If Click to expand... Many thanks Erel, So the if condition is just to make sure a numerical value is entered. I suppose the dot of 2.65 example will be taken as a fraction too. Regards, Yves Upvote 0
Erel said: 1. Make sure that the string is a valid number. 2. Assign it to a floating point variable. Code: Copy Dim num As Double If IsNumber(EditText1.Text) Then num = EditText1.Text End If Click to expand... Many thanks Erel, So the if condition is just to make sure a numerical value is entered. I suppose the dot of 2.65 example will be taken as a fraction too. Regards, Yves
klaus Expert Licensed User Longtime User Nov 11, 2014 #4 If the user is supposed to enter only numbers you should set EditText1.InputType = EditText1.INPUT_TYPE_DECIMAL_NUMBERS to limit the authorized characters. EDIT: changed INPUT_TYPE_NUMBERS to INPUT_TYPE_DECIMAL_NUMBERS Last edited: Nov 11, 2014 Upvote 0
If the user is supposed to enter only numbers you should set EditText1.InputType = EditText1.INPUT_TYPE_DECIMAL_NUMBERS to limit the authorized characters. EDIT: changed INPUT_TYPE_NUMBERS to INPUT_TYPE_DECIMAL_NUMBERS
Yves Mazzon Member Licensed User Longtime User Nov 11, 2014 #5 klaus said: If the user is supposed to enter only numbers you should set EditText1.InputType = EditText1.INPUT_TYPE_NUMBERS to limit the authorized characters. Click to expand... Many thanks Klaus, So I will have to assign a value to input type number to INPUT_TYPE_NUMBERS ? something like: dim INPUT_TYPE_NUMBERS as int INPUT_TYPE_NUMBERS = 4 'This should take care of the dot too for a value for example of 2.65? Regards, Yves Upvote 0
klaus said: If the user is supposed to enter only numbers you should set EditText1.InputType = EditText1.INPUT_TYPE_NUMBERS to limit the authorized characters. Click to expand... Many thanks Klaus, So I will have to assign a value to input type number to INPUT_TYPE_NUMBERS ? something like: dim INPUT_TYPE_NUMBERS as int INPUT_TYPE_NUMBERS = 4 'This should take care of the dot too for a value for example of 2.65? Regards, Yves
klaus Expert Licensed User Longtime User Nov 11, 2014 #7 You are right, it must be INPUT_TYPE_DECIMAL_NUMBERS ! INPUT_TYPE_NUMBERS allows only integers. Changed it in post #4. Upvote 0
You are right, it must be INPUT_TYPE_DECIMAL_NUMBERS ! INPUT_TYPE_NUMBERS allows only integers. Changed it in post #4.