Globals Declaration Help

jawahar

Member
Licensed User
Longtime User
Hi,
I am learning Basic 4 Android. I added a new code module and added the code below.There is no compilation error but the variables TMin and TMax are highlighted in red color. If I declare the same in Process_Globals instead of Globals then this does not happen. Why is this so?

Thanks & regards,

Jawahar

'Code module
'Subs in this code module will be accessible from all modules.

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

Dim Tests() As Long
End Sub
Sub Globals
Dim TMin As Long, TMax As Long
End Sub


Sub GetBounds()
Dim i As Long

TMin=Tests(0)
TMax = TMin
For i = 1 To Tests.Length-1
If Tests(i) <
TMin Then TMin = Tests(i)
If Tests(i) >
TMax Then TMax = Tests(i)
Next
End Sub
 

Geezer

Active Member
Licensed User
Longtime User

Sub Globals does not exist by default in a code module, so is created as a regular sub routine.

Therefore, the TMin and TMax variables only exist in the Globals sub.

If you wish them to be accessible for other subs in your code module, move them to the Process_Globals section.
 
Upvote 0

jawahar

Member
Licensed User
Longtime User
If there is no provision for module level globals then why does the compiler not throw an error while compiling?

Jawahar
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…