[Solved]Non stop errors even on code as simple as "sub globals"
Apologies in advance for the long post but I don't know what I can do apart from ask for advice.
I am having weird non stop and bizarre errors with B4A. No matter what I do the compiler gives the exact same error for completely impossible unrelated things.
I removed everything except....
and even then get told the sub globals has a syntax error
I have removed pages of code and still get errors only then with things like the single line "sub globals" claiming it has a syntax error.
The problems only started when I added a simple routine to create and write a map (the map is called m2 in the code). I suddenly got compile errors saying
"Error parsing program.
Error description: An item with the same key has already been added."
Giving me the error line number as the line that wrote the map I removed that line and the error changed, same exact error message but different line.
Eventually I removed the whole process of creating the map by commenting it out but the same error messages continued only now about non related code that I know works and has not been changed (non map related) like
It got to the stage where I removed the entire routine completely so no mention of maps except the already existing contact chooser sub and even then it gave me an error saying that the first line below has a syntax error...
But it doesn't it just says "sub globals" how can this code below be an error causing line?
I can't change that line, there's nothing wrong with it.
If I post the bulk of the code can someone please verify I am not going mad by looking in particular at the map routine near the end and checking I really have not made some stupid error?
I know the code all worked.
It seems weird that even if I remove the map creating routine by commenting it out I still get errors with the same warning about a key yet for things like msgbox lines where it worked fine before. And if I comment out those I get other errors until it gets to the point where I get told sub globals is a syntax error and I can't comment that out or then I get an error that it's missing.
I feel like smashing my pc
My activity (back to original code including map routine) is as follows:
And my service is:
Please can someone confirm that I am indeed sane and there is no reason for the relentless errors that even occur on lines of code as simple as "sub globals"?
I can load previously saved apps and they don't give me the errors but what could possibly make B4A think even the sub globals line is an error yet the exact same code in another app works flawlessly?
Dave
Apologies in advance for the long post but I don't know what I can do apart from ask for advice.
I am having weird non stop and bizarre errors with B4A. No matter what I do the compiler gives the exact same error for completely impossible unrelated things.
I removed everything except....
B4X:
Sub Process_Globals
Dim player As MediaPlayer
Dim phonenumber As String
Dim p As Phone
Dim pe2 As PhoneEvents
Dim serialnumber As String
Dim tempstring, password As String
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
StartService(incomingdata)
End Sub
Sub Activity_Resume
End Sub
I have removed pages of code and still get errors only then with things like the single line "sub globals" claiming it has a syntax error.
The problems only started when I added a simple routine to create and write a map (the map is called m2 in the code). I suddenly got compile errors saying
"Error parsing program.
Error description: An item with the same key has already been added."
Giving me the error line number as the line that wrote the map I removed that line and the error changed, same exact error message but different line.
Eventually I removed the whole process of creating the map by commenting it out but the same error messages continued only now about non related code that I know works and has not been changed (non map related) like
B4X:
Msgbox("Now please press ok to pick the mobile phone number I should contact for help, and send reports to. You can change this later.", "Press ok to continue")
It got to the stage where I removed the entire routine completely so no mention of maps except the already existing contact chooser sub and even then it gave me an error saying that the first line below has a syntax error...
But it doesn't it just says "sub globals" how can this code below be an error causing line?
B4X:
Sub Globals
Dim enterpassword As InputDialog
End Sub
I can't change that line, there's nothing wrong with it.
If I post the bulk of the code can someone please verify I am not going mad by looking in particular at the map routine near the end and checking I really have not made some stupid error?
I know the code all worked.
It seems weird that even if I remove the map creating routine by commenting it out I still get errors with the same warning about a key yet for things like msgbox lines where it worked fine before. And if I comment out those I get other errors until it gets to the point where I get told sub globals is a syntax error and I can't comment that out or then I get an error that it's missing.
I feel like smashing my pc
My activity (back to original code including map routine) is as follows:
B4X:
Sub Process_Globals
Dim player As MediaPlayer
Dim phonenumber As String
Dim p As Phone
Dim pe As PhoneEvents
Dim serialnumber As String
Dim tempstring, password As String
Sub Globals
Dim enterpassword As InputDialog
End Sub
Sub Activity_Create(FirstTime As Boolean)
StartService(incomingdata)
If FirstTime Then
' check for saved settings
'If File.Exists(File.DirInternal, "file.ini") = False Then setup
player.Initialize( )
player.Load(File.DirAssets, "slide.mp3")
' code removed to make post shorter, just initialises some panels but
' has remained unchanged and is not causing any issues
End If
End Sub
Sub Activity_Resume
End Sub
Sub Button_changenumber_Click
' Get and verify password
enterpassword.Input = enterpassword.INPUT_TYPE_TEXT
tempstring = enterpassword.Show("Please enter your password in order to change the contact number I will use.", "Please enter your password", "Ok", "","", Null)
tempstring = enterpassword.Input
tempstring = tempstring.ToLowerCase
tempstring = tempstring.Trim
'If password matches the stored password then pick a new contact number
If tempstring = password Then picknum
'If the password entered does not match the password stored then let the user know
If tempstring <> password Then Msgbox("You entered the wrong password", "Error")
End Sub
Sub picknum
' Pick a contact number
Dim Contacts As Contacts
Dim tempnum As String
tempnum = "N/A"
Dim list1 As List
Do Until tempnum <> "N/A"
list1 = Contacts.GetAll
Dim listOfNames As List
listOfNames.Initialize
'Create a list with the contacts names
For i = 0 To list1.Size - 1
Dim c As Contact
c = list1.Get(i) 'fetch the Contact from the original list
If c.DisplayName.IndexOf("@") = -1 Then 'remove email only contacts
listOfNames.Add(c.DisplayName)
End If
Next
Dim res As Int
res = InputList(listOfNames, "Choose a mobile phone number (eg mum or dads)", -1)
If res <> DialogResponse.CANCEL Then
Dim name As String
name = listOfNames.Get(res)
Dim c As Contact
'find the original contact based on the chosen name
For i = 0 To list1.Size
c = list1.Get(i)
If c.DisplayName = name Then Exit
Next
Dim m As Map
m = c.GetPhones
If m.Size > 0 Then
tempnum = m.GetKeyAt(0)
Else
tempnum = "N/A"
End If
End If
Loop
phonenumber = tempnum
ToastMessageShow(phonenumber, True)
End Sub
Sub setup
' Initialise the map that stores the users preferences
Dim m2 As Map
m2.Initialize
' Create a password
enterpassword.Input = enterpassword.INPUT_TYPE_TEXT
tempstring = enterpassword.Show("This seems to be the first time you have run this app, please create a password then click on ok. Please remember this password for future use.", "Choose a password", "Ok", "","", Null)
password = enterpassword.Input
password = password.ToLowerCase
password = password.Trim
serialnumber = p.getsimserialnumber
' get a default number to store
Msgbox("Now please press ok to pick the mobile phone number I should contact for help, and send reports to. You can change this later.", "Press ok to continue")
'picknum
'm2.Put("hint", password)
'm2.Put("originalsim", serialnumber)
'm2.Put("phonenumber", phonenumber)
'File.WriteMap(File.DirInternal, "file.ini", m2)
'Msgbox(password, "Your password is....")
End Sub
And my service is:
B4X:
'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim PE As PhoneEvents
Dim SI As SmsInterceptor
Dim message, sentby As String
Dim n As Notification
Dim player2 As MediaPlayer
Dim simserial As String
Dim GPS1 As GPS
Dim latitude, longitude As String
Dim ph As Phone
End Sub
Sub Service_Create
PE.Initialize("PE")
SI.Initialize("SI")
End Sub
Sub Service_Start
End Sub
Sub SI_MessageReceived (From As String, Body As String)
message = Body.ToLowerCase
' If the soundsiren command was issued then do the following
If message.IndexOf("soundsiren") >-1 Then
player2.Initialize
player2.Looping = True
player2.Load(File.DirAssets, "siren.mp3")
player2.Play
End If
'If the stopsiren command was issued then stop playing the siren
If message.IndexOf("stopsiren") >-1 Then
player2.Looping = False
player2.Stop
End If
End Sub
Sub Service_Destroy
End Sub
Please can someone confirm that I am indeed sane and there is no reason for the relentless errors that even occur on lines of code as simple as "sub globals"?
I can load previously saved apps and they don't give me the errors but what could possibly make B4A think even the sub globals line is an error yet the exact same code in another app works flawlessly?
Dave
Last edited: