makis_best Well-Known Member Licensed User Longtime User Jun 27, 2019 #1 Hi I have two classes, class A and class B. Inside class B some variables are filled with data let say Variable A1 and A2 How I can pass the data from A1 and A2 into class A Thank you.
Hi I have two classes, class A and class B. Inside class B some variables are filled with data let say Variable A1 and A2 How I can pass the data from A1 and A2 into class A Thank you.
LucaMs Expert Licensed User Longtime User Jun 27, 2019 #2 https://www.b4x.com/etp.html?vimeography_gallery=1&vimeography_video=254684276 Upvote 0
S sorex Expert Licensed User Longtime User Jun 28, 2019 #3 you could pass it as variables to a sub call or place the variables in the main code module and use main.varname. Upvote 0
you could pass it as variables to a sub call or place the variables in the main code module and use main.varname.
rraswisak Active Member Licensed User Longtime User Jun 28, 2019 #4 Sub from Class_A Code: 'Class_A Sub WhoAreYou(name As String, age As Int) Msgbox("My name is " & name & " and i'm " & age & " years old","Hi there...") End Sub Sub from Class_B Code: 'Class_B Sub Call_ClassA_Sub 'initialize the class object and call the sub Dim classA As Class_A classA.WhoAreYou("John", 20) End Sub Upvote 0
Sub from Class_A Code: 'Class_A Sub WhoAreYou(name As String, age As Int) Msgbox("My name is " & name & " and i'm " & age & " years old","Hi there...") End Sub Sub from Class_B Code: 'Class_B Sub Call_ClassA_Sub 'initialize the class object and call the sub Dim classA As Class_A classA.WhoAreYou("John", 20) End Sub
LucaMs Expert Licensed User Longtime User Jun 28, 2019 #5 rraswisak said: 'Class_A Public Sub WhoAreYou(name As String, age As Int) Msgbox("My name is " & name & " and i'm " & age & " years old","Hi there...") End Sub Click to expand... I would use always the "scope" (Public, above). rraswisak said: 'Class_B Sub Call_ClassA_Sub 'initialize the class object and call the sub Dim classA As Class_A classA.Initialize classA.WhoAreYou("John", 20) End Sub Click to expand... Bad names (Dim objA would be a little bit better) and you forgot to initialize classA (which is an object of type Class_A), you have only declared it. It's ok. [to show a MsgBox - better a MsgBoxAsync - the object must be declared in an Activity] Last edited: Jun 28, 2019 Upvote 0
rraswisak said: 'Class_A Public Sub WhoAreYou(name As String, age As Int) Msgbox("My name is " & name & " and i'm " & age & " years old","Hi there...") End Sub Click to expand... I would use always the "scope" (Public, above). rraswisak said: 'Class_B Sub Call_ClassA_Sub 'initialize the class object and call the sub Dim classA As Class_A classA.Initialize classA.WhoAreYou("John", 20) End Sub Click to expand... Bad names (Dim objA would be a little bit better) and you forgot to initialize classA (which is an object of type Class_A), you have only declared it. It's ok. [to show a MsgBox - better a MsgBoxAsync - the object must be declared in an Activity]
makis_best Well-Known Member Licensed User Longtime User Jun 28, 2019 #6 The only problem is, when initialize class variables dim again and loose the data stored inside Upvote 0
S sorex Expert Licensed User Longtime User Jun 28, 2019 #7 then use a global one in your main module which won't be recreated when creating a new class variable. Upvote 0
then use a global one in your main module which won't be recreated when creating a new class variable.
makis_best Well-Known Member Licensed User Longtime User Jun 28, 2019 #8 @sorex I think that I will do for my project I think it is the simplest solution Upvote 0