Bug? Strange Syntax error

corwin42

Expert
Licensed User
Longtime User
Why does this code raise a syntax error (Does it in B4A, too. So it is consistent)?

B4X:
Sub Process_Globals
    Type MyType (test As String)
 
    Private gVariable As MyType
End Sub

Sub AppStart (Args() As String)
    GetVariable.Initialize
 
    GetVariable.test = "Test"
End Sub

Public Sub GetVariable As MyType
    Return gVariable
End Sub

The syntax error is on line "GetVariable.test = "Test"
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is indeed a bug or limitation. A sub call statement cannot be in the left side of an assignment.

Note that it will work properly if you implement it as a property (in a class):
B4X:
Sub Class_Globals
   Private gVariable As MyType
End Sub

Public Sub Initialize

End Sub

Public Sub getVariable As MyType
  Return gVariable
End Sub

B4X:
Dim c As YourClass
c.Initialize
c.Variable.Initialize
c.Variable.test = 10
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…