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

Discussion in 'Android Questions' started by TyneBridges, Jul 11, 2015.

  1. TyneBridges

    TyneBridges Member Licensed 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.
  2. RandomCoder

    RandomCoder Well-Known Member Licensed User

    You need to prefix it with the module name, in this case main.dbtablename
  3. TyneBridges

    TyneBridges Member Licensed 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.
    RandomCoder likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice