Android Question [CLOSED] Global variable isn't (order of execution?)

TyneBridges

Member
Licensed User
Longtime User
I have the following in my first activity (Main)

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim DBFileName As String: DBFileName = "Diary.db"
Dim DBFileDir As String: DBFileDir = File.DirDefaultExternal
Dim DBTableName As String: DBTableName = "DEntries"
Dim AppName As String: AppName = "Diary"
Dim SQL1 As SQL
End Sub

The second activity (BrowseData) intended to be called by a button press in the first contains the following.

Query = "Select Dt, Weather, Entry from " & DBTableName & " order by Dt"

This refuses to compile and gives

Error parsing program.
Error description: Undeclared variable 'dbtablename' is used before it was assigned any value.

The variable SQL1 gives a similar error, although both are defined as Global variables right at the start of the program.

I've read the tutorial on Android process and activities and I assume the problem arises because Main is not compiled first. However, I can't see how to ensure that it is. Surely Global variables don't have to be defined in each module, otherwise they aren't really Global...?

Thanks for any help.
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
You need to prefix it with the module name, in this case main.dbtablename
 
Upvote 0

TyneBridges

Member
Licensed User
Longtime User
Thanks! I didn't expect that because it seems to go against the definition of a Global variable but, once I've done it, the project compiles.
 
Upvote 0
Top