Android Question Edit Text Issue

MCU01

Member
Licensed User
Longtime User
Hi all,

I have the following very simple code,

Sub edtTest_EnterPressed
If edtTest.Text > 120 Then
Msgbox("PLEASE, ENTER A NUMBER OF SECONDS BETWEEN 0 AND 120","INVALID ENTRY")
edtTest.Text = ""
End If
End Sub


The input for edtTest is numerical. It works fine. However, if I press enter when there is nothing (" ") in the box then I get a bunch errors,

Error occurred on line: 349 (Main)
java.lang.NumberFormatException: Invalid double: ""
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseDouble(StringToReal.java:248)
at java.lang.Double.parseDouble(Double.java:295)
at b4a.example.main._edtincrement_enterpressed(main.java:1143)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.EditTextWrapper$2.onEditorAction(EditTextWrapper.java:107)
at android.widget.TextView.onEditorAction(TextView.java:5384)
at com.android.internal.widget.EditableInputConnection.performEditorAction(EditableInputConnection.java:138)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:297)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:77)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)


Any help is appreciated. Thank you.
 

stevel05

Expert
Licensed User
Longtime User
Yes an empty string "" does not convert to a Double. By doing a numeric test you are forcing the program to convert the string to a number. Test for the empty string before you check the range.
 
Upvote 0

MCU01

Member
Licensed User
Longtime User
Thanks Steve. That worked. Is there anyway to check if a string is numerical like in VB6. Something like,

If edtTest.Text.IsNumerical Then

Thanks in advance.
 
Upvote 0

MCU01

Member
Licensed User
Longtime User
Thank you Erel. I printed out the beginner's manual, but I haven't seen this function IsNumber in it. Is there anywhere where I can find all the functions available in B4A? Thank you again. Robert.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…