Hi Guys and Gals,
I am new to B4A however I am experienced with Basic (I go all the way back to the ARPANET days.) I have a test program which reads a location from the phone and sends it to a mySQL database when I click a button. The routine works fine the first click however it fails on every additional attempt until I close the program and re-load. Then I get one more successful iteration. I am sure its that I am not closing something properly however from the minimal documentation I can find I cannot figure what is the issue. Please take a look at my code and tell me if you see anything wrong. I am using LocationManagerEx and one of the mySQL libraries. Forget which one as I have tried 3 so far. I am clicking Button1 to run the test.
I am new to B4A however I am experienced with Basic (I go all the way back to the ARPANET days.) I have a test program which reads a location from the phone and sends it to a mySQL database when I click a button. The routine works fine the first click however it fails on every additional attempt until I close the program and re-load. Then I get one more successful iteration. I am sure its that I am not closing something properly however from the minimal documentation I can find I cannot figure what is the issue. Please take a look at my code and tell me if you see anything wrong. I am using LocationManagerEx and one of the mySQL libraries. Forget which one as I have tried 3 so far. I am clicking Button1 to run the test.
B4X:
#Region Project Attributes
#ApplicationLabel: com.android.lalo
#VersionCode: 1
#VersionName: PreRel_1
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Button1 As Button
Dim Button2 As Button
Dim lv1 As ListView
Dim la As Double
Dim lo As Double
Dim AdoConn As AdoConnection
Dim AdoRec As AdoRecordset
Dim iResult As Int
Dim sResult As String
Dim LabelResults As Label
Dim myLoc As LocationManagerEx
Dim LocResult As Location
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Test2Layout1")
LabelResults.Text = "Ready."
End Sub
Sub Activity_Resume
LabelResults.Text = "Ready."
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
Button1.Color = Colors.Magenta
myLoc.Initialize("Loc1")
myLoc.requestMobileLocation
End Sub
Sub Loc1_locationchanged(locArg As Location)
Dim bResult As Boolean
Dim tmpStr As String
Button1.Color = Colors.Green
la = locArg.Latitude
lo = locArg.Longitude
'connect to the cloud server
AdoConn.ConnectionString( "23.22.237.49","3161","","reminders","xxxxxxxx","xxxxxxxx")
AdoConn.ConnectionTimeout = 2
AdoConn.LoginTimeout = 2
AdoConn.SocketTimeout = 2
tmpStr = "INSERT INTO latlon (user_id, lat, lon) VALUES (1, " & la & ", " & lo & ")"
AdoConn.InitializeEvent
AdoConn.Open
'iResult = AdoConn.ExecuteInsertCommand(tmpStr)
iResult = AdoConn.Execute(tmpStr)
LabelResults.Text = iResult
AdoConn.CommitTrans
AdoConn.Close
Button1.Color = Colors.White
End Sub
Last edited: