Android Question Easy Question I believe its a No

brianwiz12

Active Member
Licensed User
Longtime User
Hello,

Looking around the forums I found call sub and process class but I believe from reading this is not possible.

Basically in VB to reference and change someone on a different form you would type. main1.button.whatever

Now in Basic 4 Android I have put in this code with no issues except when running the programs obviously
B4X:
quotes.btnOne.Text = "Me"

What I'm looking at is a situation where someone completes something then I change the color of the button on the main module.

Maybe I'm missing the thread or the point.
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
I think that I understand what you want. The problem is that the Views in an Activity are not accessible directly from outside of the Activity in which they are used. The problem is simple enough though. Either create Process Global variables which you can set and read from anywhere or just use CallSub2 or CallSub3 to call a routine in the Activity you want to return to and pass it the one or two parameters that you want to set.
 
Upvote 0

brianwiz12

Active Member
Licensed User
Longtime User
Thank you for confirming that I can change something from a sub module to the main module. I will continue the work and type back if I'm still stuck some code
 
Upvote 0

brianwiz12

Active Member
Licensed User
Longtime User
Here is my code that actually accomplishes turning the label green and putting a Y in it if one thing in another module is completed. If anyone wants to improve on it please share.

Main Module
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim score As Char
    Dim score1 As Char
End Sub

Activity Create
B4X:
label2.Text = score

If label2.Text = score Then label2.color = Colors.Green

label3.Text = score1
label3.Color = Colors.Red

If label3.Text = score1 Then label3.color = Colors.Green

Second Module Next Button

B4X:
Sub btnnext_click
quotes.score1 = "Y"
StartActivity("quote2")
Activity.finish
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
or just use CallSub2 or CallSub3 to call a routine in the Activity you want...

We can summarize by saying:

do not write the code directly within the event procedure, but write into it just a call to a routine code. Like:
B4X:
Sub btnDoSomething_Click
    DoSomething
End Sub

' elsewhere...

Sub DoSomething
End Sub


This should always be the best method, with any language.
 
Upvote 0
Top