B4J Question Edittext invalid double

patrickfailing

New Member
Licensed User
Longtime User
I have a regular edittext box with numbers only. When I press done with the box being empty I get the number format exception, Invalid double. I need to know how to set it so that if this happens and an empty string is sent that I can either insert an alert or put in a set value and not have the edittext box close. Any help would be greatly appreciated. Thanks.

B4X:
Sub EditText1_EnterPressed
     
      If EditText1.Text > 1000 Then EditText1.Text = 1000
      If EditText1.Text < 1 Then EditText1.Text = 0
      Packet = "f" & EditText1.Text
      astreams.Write(Packet.GetBytes("UTF8"))
      ToggleButton1.Checked = False
 

cyiwin

Active Member
Licensed User
Longtime User
Not sure if this helps with an empty string but you may want to try IsNumber.
B4X:
If IsNumber(EditText1.Text) = True Then
....
End If
or assign a variable to EditText1
B4X:
Dim Ans As Double

Ans = EditText1.Text
If IsNumber(Ans) = True Then
.....
End If
 
Upvote 0
Top