Android Question How do I extract the numeric value of a text input?

DTB Radio

Member
Licensed User
Longtime User
I want to enter a number into a text box that's already set for numeric input, then get its actual numeric value into a variable for numeric operations. What I'm doing now is this:

B4X:
dim aVariable as long
aVariable = EditText.text

This works ok for most of what I'm doing, but when I try to do this,

B4X:
If aVariable > 999999999999 Then
    Msgbox("Please enter a number of 999999999999 or less", "Invalid Input")
end if

It doesnt catch it even if the number entered is higher than 999999999999. What am I missing?
 

JTmartins

Active Member
Licensed User
Longtime User
Are you raising an event to check what value is inserted ?

A button could do it.

See the example, works ok here
 

Attachments

  • test.zip
    7.3 KB · Views: 299
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I want to enter a number into a text box that's already set for numeric input, then get its actual numeric value into a variable for numeric operations. What I'm doing now is this:

B4X:
dim aVariable as long
aVariable = EditText.text

This works ok for most of what I'm doing, but when I try to do this,

B4X:
If aVariable > 999999999999 Then
    Msgbox("Please enter a number of 999999999999 or less", "Invalid Input")
end if

It doesnt catch it even if the number entered is higher than 999999999999. What am I missing?


It works perfectly!

B4X:
EditText1.InputType = EditText1.INPUT_TYPE_NUMBERS

B4X:
Sub Button1_Click
    Dim aVariable As Long
    aVariable = EditText1.Text
    Log("EditText1.Text = " & EditText1.Text)
    Log("aVariable = " & aVariable)
    If aVariable > 999999999999 Then
        Msgbox("Please enter a number of 999999999999 or less", "Invalid Input")
    End If   
End Sub
 
Upvote 0

DTB Radio

Member
Licensed User
Longtime User
It works perfectly!

B4X:
EditText1.InputType = EditText1.INPUT_TYPE_NUMBERS

B4X:
Sub Button1_Click
    Dim aVariable As Long
    aVariable = EditText1.Text
    Log("EditText1.Text = " & EditText1.Text)
    Log("aVariable = " & aVariable)
    If aVariable > 999999999999 Then
        Msgbox("Please enter a number of 999999999999 or less", "Invalid Input")
    End If  
End Sub


Thanks for the help, everyone! I wont get time today to try any of that yet, but I will asap.
 
Upvote 0
Top