Bug? Beta 2.0 - Types

splatt

Active Member
Licensed User
Longtime User
Working on a program at the moment and added a new type declaration. Getting an error when compiling.

I've created a new test project to test it in isolation and this is the code:

B4X:
'Activity module
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.
     Type TrackData(TrackPath As String, Track As String)
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Dim ThisTrack As TrackData
   ThisTrack.Initialize
   ThisTrack.TrackPath = ""
   ThisTrack.Track = ""
   DoSomething
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub DoSomething
   ThisTrack.TrackPath = File.DirAssets
   ThisTrack.Track = "Hello.mp3"
End Sub


Compiling code. Error
Error parsing program.
Error description: Undeclared variable 'thistrack' is used before it was assigned any value.
Occurred on line: 30
ThisTrack.Path = File.DirAssets

Is this related to latest changes?
 

splatt

Active Member
Licensed User
Longtime User
You should declare ThisTrack in Sub Process_Globals or Sub Globals. Otherwise it will be a local variable. This means that there is no ThisTrack variable in Sub DoSomething.

:BangHead:
 
Top