Question about EditText and multiplication

marbellapc

Member
Licensed User
Longtime User
Hello, I have a problem with a ToggleButton which starts the GPS or pause, well the thing is that it works, but I do not NumberFormatException error I have to go to the Options menu and back out to the main screen.

In Designer I changed the INPUT TYPE: TEXT > NUMBERS, and what I have set EditText INPUT_TYPE_NUMBERS and multiply by 1000 so that when multiplied by the contents of EditText me in x seconds.

I wanted to ask this would be the right way, or am I wrong and to multiply the contents of an EditText by a number, it is otherwise?

Is that when I changed the type, the GPS does not stop the time stated in the EditText.

Previous contents of the ToggleButton:
B4X:
Sub ToggleButton_GPS_CheckedChange(Checked As Boolean)
    Dim gpsTime As String
   gpsTime = EditText_timeGPS.Text * 1000
   If Checked = True Then
   ToastMessageShow("Dispositivo GPS: Iniciado", True)
   GPS1.Start(gpsTime, 0)
    Else    
   ToastMessageShow("Dispositivo GPS: Pausado", True)
   GPS1.Stop
    End If
End Sub
Content updated ToggleButton:
B4X:
Sub ToggleButton_GPS_CheckedChange(Checked As Boolean)
    Dim gpsTime As String
   gpsTime = EditText_timeGPS.INPUT_TYPE_NUMBERS * 1000
   If Checked = True Then
   ToastMessageShow("Dispositivo GPS: Iniciado", True)
   GPS1.Start(gpsTime, 0)
    Else    
   ToastMessageShow("Dispositivo GPS: Pausado", True)
   GPS1.Stop
    End If
End Sub
 

lagore

Active Member
Licensed User
Longtime User
You should have declared gpsTime as a long
B4X:
Dim gpstime As Long
   gpstime = EditText1.Text * 5
the GPS.Start is expecting a long I think that may be your problem.
 
Last edited:
Upvote 0

marbellapc

Member
Licensed User
Longtime User
Lagore Thanks for answering, and I feel the delay in replying, I've been very busy these days.
Is supposed to be 20 seconds, you have to write 20000 milliseconds, correct? or am I wrong?

The application goes well, the problem is not initialized when starting the application, for that I have to go into options, where is the EditText of time and return to the main screen and so and if it starts well and does not fail.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
As Edward suggested, I think that you should declare your variable as long:
B4X:
Sub ToggleButton_GPS_CheckedChange(Checked As Boolean)
    Dim gpsTime As Long
    gpsTime = EditText_timeGPS.Text * 1000
    If Checked = True Then
    ToastMessageShow("Dispositivo GPS: Iniciado", True)
    GPS1.Start(gpsTime, 0)
    Else    
    ToastMessageShow("Dispositivo GPS: Pausado", True)
    GPS1.Stop
    End If
End Sub
 
Upvote 0
Top