corwin42 Expert Licensed User Longtime User Feb 18, 2016 #1 Why does this code raise a syntax error (Does it in B4A, too. So it is consistent)? Code: Copy 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"
Why does this code raise a syntax error (Does it in B4A, too. So it is consistent)? Code: Copy 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 Feb 18, 2016 #2 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): Code: Copy Sub Class_Globals Private gVariable As MyType End Sub Public Sub Initialize End Sub Public Sub getVariable As MyType Return gVariable End Sub Code: Copy Dim c As YourClass c.Initialize c.Variable.Initialize c.Variable.test = 10
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): Code: Copy Sub Class_Globals Private gVariable As MyType End Sub Public Sub Initialize End Sub Public Sub getVariable As MyType Return gVariable End Sub Code: Copy Dim c As YourClass c.Initialize c.Variable.Initialize c.Variable.test = 10