M Mark Stuart Well-Known Member Licensed User Longtime User Aug 17, 2025 #1 Hi all, This pertains to using an Activity and not B4XPages, which I don't use. I have a Type structure defined in the Main Activity and need to use it in another Activity called AddItem. How do I reference the Main Type structure in the AddItem Activity? Regards, Mark Stuart
Hi all, This pertains to using an Activity and not B4XPages, which I don't use. I have a Type structure defined in the Main Activity and need to use it in another Activity called AddItem. How do I reference the Main Type structure in the AddItem Activity? Regards, Mark Stuart
JohnC Expert Licensed User Longtime User Aug 17, 2025 #2 Just move the Type structure to the "Process_Globals" section of a Code module and reference it as CodeModuleName.TypeStructureName from both activities. Upvote 0
Just move the Type structure to the "Process_Globals" section of a Code module and reference it as CodeModuleName.TypeStructureName from both activities.
M Mark Stuart Well-Known Member Licensed User Longtime User Aug 17, 2025 #3 Thank you John as I searched the forum and didn't find a mention on the use of a Type definition and its multi use. So thank you again. Mark Upvote 0
Thank you John as I searched the forum and didn't find a mention on the use of a Type definition and its multi use. So thank you again. Mark
M Mark Stuart Well-Known Member Licensed User Longtime User Aug 18, 2025 #4 JohnC said: Just move the Type structure to the "Process_Globals" section of a Code module and reference it as CodeModuleName.TypeStructureName from both activities. Click to expand... Got to the computer and created the Code module and copied the Type into the Process_Globals as: Type Item (Name As String, Country As String, Phone As String, Email As String) In the Main activity, in the Process_Globals I started typing the reference to the Type in the code module - it wouldn't reference even the code module name and obviously therefore couldn't see the Process_Globals I created there. It doesn't take the Public word before the Type either. I don't use Types at all in my apps, so I'm new to using them. What am I doing wrong? Upvote 0
JohnC said: Just move the Type structure to the "Process_Globals" section of a Code module and reference it as CodeModuleName.TypeStructureName from both activities. Click to expand... Got to the computer and created the Code module and copied the Type into the Process_Globals as: Type Item (Name As String, Country As String, Phone As String, Email As String) In the Main activity, in the Process_Globals I started typing the reference to the Type in the code module - it wouldn't reference even the code module name and obviously therefore couldn't see the Process_Globals I created there. It doesn't take the Public word before the Type either. I don't use Types at all in my apps, so I'm new to using them. What am I doing wrong?
JohnC Expert Licensed User Longtime User Aug 18, 2025 #5 To use a Type, you need to DIM a variable as that type: B4X: Expand Collapse Copy (CodeModule) Sub Process_Globals Type ItemType (Name As String, Country As String, Phone As String, Email As String) End Sub (Activity Code) Dim MyItem as CodeModuleName.ItemType MyItem.Name = "John" MyItem.Country = "US" MyItem.Phone = "123-456-7890" MyItem.Email = "[email protected]" Last edited: Aug 18, 2025 Upvote 0
To use a Type, you need to DIM a variable as that type: B4X: Expand Collapse Copy (CodeModule) Sub Process_Globals Type ItemType (Name As String, Country As String, Phone As String, Email As String) End Sub (Activity Code) Dim MyItem as CodeModuleName.ItemType MyItem.Name = "John" MyItem.Country = "US" MyItem.Phone = "123-456-7890" MyItem.Email = "[email protected]"
M Mark Stuart Well-Known Member Licensed User Longtime User Aug 18, 2025 #6 Where in the Main module is the Dim placed? Upvote 0
JohnC Expert Licensed User Longtime User Aug 18, 2025 #7 Mark Stuart said: Where in the Main module is the Dim placed? Click to expand... You can place the DIM line in a Process_Globals, Globals or any other sub depending how much scope you want that variable to have. Upvote 0
Mark Stuart said: Where in the Main module is the Dim placed? Click to expand... You can place the DIM line in a Process_Globals, Globals or any other sub depending how much scope you want that variable to have.
M Mark Stuart Well-Known Member Licensed User Longtime User Aug 18, 2025 #8 Well it seems I've figured it out with placing the Type in a Code module and then referencing the Type in my code as the following.I don't have to "re-declare" the Type in the Main Activity module as you've suggested. Here's the code in use in the Main Activity module: B4X: Expand Collapse Copy Sub LoadList clvItems.Clear For Each it As Item In AppTypes.SavedListItems '<-- notice the Item. This is the Code module declaration Type. Dim pnl As B4XView = CreateItemPanel(it) clvItems.Add(pnl, it) Next End Sub B4X: Expand Collapse Copy Sub Process_Globals ' Extended structured Type Type Item (Name As String, Country As String, Phone As String, Email As String) Public SavedListItems As List End Sub John, is this what and how you were referring to the structure and use of the Type? Upvote 0
Well it seems I've figured it out with placing the Type in a Code module and then referencing the Type in my code as the following.I don't have to "re-declare" the Type in the Main Activity module as you've suggested. Here's the code in use in the Main Activity module: B4X: Expand Collapse Copy Sub LoadList clvItems.Clear For Each it As Item In AppTypes.SavedListItems '<-- notice the Item. This is the Code module declaration Type. Dim pnl As B4XView = CreateItemPanel(it) clvItems.Add(pnl, it) Next End Sub B4X: Expand Collapse Copy Sub Process_Globals ' Extended structured Type Type Item (Name As String, Country As String, Phone As String, Email As String) Public SavedListItems As List End Sub John, is this what and how you were referring to the structure and use of the Type?
JohnC Expert Licensed User Longtime User Aug 18, 2025 #9 Mark Stuart said: John, is this what and how you were referring to the structure and use of the Type? Click to expand... Yes, as I mentioned you can place the DIM (or "public") in the Process_Globals sub. Upvote 0
Mark Stuart said: John, is this what and how you were referring to the structure and use of the Type? Click to expand... Yes, as I mentioned you can place the DIM (or "public") in the Process_Globals sub.
LucaMs Expert Licensed User Longtime User Aug 18, 2025 #10 Once you declare the Type in a Process_Globals, you don't have to (and can't) do it elsewhere; you can create variables of that type (Dim... and Initilalize) anywhere. The best place to declare the Type is in the Main Activity (or in the B4XMainPage), as it's mandatory to have it there if you want(ed) to serialize (B4XSerializator) variables of that type. Mark Stuart said: B4XPages, which I don't use. Click to expand... This is not a good idea, at all. Last edited: Aug 18, 2025 Upvote 0
Once you declare the Type in a Process_Globals, you don't have to (and can't) do it elsewhere; you can create variables of that type (Dim... and Initilalize) anywhere. The best place to declare the Type is in the Main Activity (or in the B4XMainPage), as it's mandatory to have it there if you want(ed) to serialize (B4XSerializator) variables of that type. Mark Stuart said: B4XPages, which I don't use. Click to expand... This is not a good idea, at all.
M Mark Stuart Well-Known Member Licensed User Longtime User Aug 18, 2025 #11 I don't see how b4xpages is any benefit to my projects. Upvote 0
LucaMs Expert Licensed User Longtime User Aug 18, 2025 #12 Mark Stuart said: I don't see how b4xpages is any benefit to my projects. Click to expand... You can see it here: https://www.b4x.com/android/forum/threads/b4x-b4xpages-what-exactly-does-it-solve.119078/#content Upvote 0
Mark Stuart said: I don't see how b4xpages is any benefit to my projects. Click to expand... You can see it here: https://www.b4x.com/android/forum/threads/b4x-b4xpages-what-exactly-does-it-solve.119078/#content
M Mark Stuart Well-Known Member Licensed User Longtime User Aug 18, 2025 #13 No, I don't think I'll be going to b4xpages. Nothing there is a benefit to me or is required to using b4xpages in my apps. I'm fine where I am. And I don't like ppl saying its a mistake not to use b4xpages. Not appropriate in a forum. In the past looking at the 3 pages example, I can't believe how you have to manage each page declaration and show of it. What a waste of functionality and coding time. Just imagine an app with lots of activities/pages. What a nightmare! Upvote 0
No, I don't think I'll be going to b4xpages. Nothing there is a benefit to me or is required to using b4xpages in my apps. I'm fine where I am. And I don't like ppl saying its a mistake not to use b4xpages. Not appropriate in a forum. In the past looking at the 3 pages example, I can't believe how you have to manage each page declaration and show of it. What a waste of functionality and coding time. Just imagine an app with lots of activities/pages. What a nightmare!
LucaMs Expert Licensed User Longtime User Aug 18, 2025 #14 Mark Stuart said: And I don't like ppl saying its a mistake not to use b4xpages. Not appropriate in a forum. Click to expand... So from now on (or before? ) you don't like me anymore, but I didn't write that it's a mistake but that it's not a good idea: LucaMs said: This is not a good idea, at all. Click to expand... Mark Stuart said: Nothing there is a benefit to me or is required to using b4xpages in my apps Click to expand... There are at least those 20 good reasons (tutorial) to choose B4XPages projects; perhaps the descriptions don't convey the idea as well as practice would. Mark Stuart said: I'm fine where I am Click to expand... And I'm happy for you. I'm sorry you're not switching to B4XPages, because for every member I convince to use them, I get €300... from the Pope Of course, I mean, I wouldn't have any advantage in convincing you. I highly recommend it because the benefits are so many and useful, but if you don't believe me... that's okay, I like you anyway Mark Stuart said: And I don't like ppl saying its a mistake not to use b4xpages Click to expand... Upvote 0
Mark Stuart said: And I don't like ppl saying its a mistake not to use b4xpages. Not appropriate in a forum. Click to expand... So from now on (or before? ) you don't like me anymore, but I didn't write that it's a mistake but that it's not a good idea: LucaMs said: This is not a good idea, at all. Click to expand... Mark Stuart said: Nothing there is a benefit to me or is required to using b4xpages in my apps Click to expand... There are at least those 20 good reasons (tutorial) to choose B4XPages projects; perhaps the descriptions don't convey the idea as well as practice would. Mark Stuart said: I'm fine where I am Click to expand... And I'm happy for you. I'm sorry you're not switching to B4XPages, because for every member I convince to use them, I get €300... from the Pope Of course, I mean, I wouldn't have any advantage in convincing you. I highly recommend it because the benefits are so many and useful, but if you don't believe me... that's okay, I like you anyway Mark Stuart said: And I don't like ppl saying its a mistake not to use b4xpages Click to expand...
M Mark Stuart Well-Known Member Licensed User Longtime User Aug 18, 2025 #15 Based on forum standards I guess I should be saying to you: please start a new thread on this and continue your discussion there. Last edited: Aug 19, 2025 Upvote 0
Based on forum standards I guess I should be saying to you: please start a new thread on this and continue your discussion there.
LucaMs Expert Licensed User Longtime User Aug 18, 2025 #16 Mark Stuart said: Based forum standards i guess I should be saying to you: please start a new thread on this and continue your discussion there. Click to expand... Correct Upvote 1
Mark Stuart said: Based forum standards i guess I should be saying to you: please start a new thread on this and continue your discussion there. Click to expand... Correct