CallSub3 Warning Msg

Shahabg

Member
Licensed User
Longtime User
I have this line
CallSub3(Main, m_MainSub, "Start", "")
in version 2.70
I get red line which indicates "cannot access exclude:main" message,
but the call works fine.
what is the issue?
thanks
 

Shahabg

Member
Licensed User
Longtime User
Erel,
Yes it does, here is the msg
Parsing code. 0.06
Compiling code. Error
Error compiling program.
Error description: Cannot access excluded module: main
Occurred on line: 171
CallSub3(Main, m_MainSub, "Start", "")
Word: main
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Your library cannot have any dependence upon an external module and so cannot know about specific modules and their Subs. You can however pass the information to the module at runtime. For example a trivial code 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 A As String
   Dim S As String
End Sub

Sub Initialize(Act As String, Subname As String)
   A = Act
   S = Subname
End Sub

Sub CallMeBack(p1 As String, p2 As String)
   CallSub3(A, S, p1, p2)
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that it is better to set the "target" type to Object:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim A As Object
    Dim S As String
End Sub

Sub Initialize(Target As Object, Subname As String)
    A = Act
    S = Subname
End Sub

Sub CallMeBack(p1 As String, p2 As String)
    CallSub3(A, S, p1, p2)
End Sub

Then when you initialize the object you should write:
B4X:
Dim c As Class1
c.Initialize(Me, "SomeSub")
 
Upvote 0

Nb1320

Member
Licensed User
Longtime User
I know this is old, but I have the same problem and I do not understand the help given by Erel and agraham. Can someone please elaborate?
In the menu module I have this:
B4X:
If KeyCode = KeyCodes.KEYCODE_BACK AND sm.isVisible = False Then
    If Msgbox2("Exit Program?", "EXIT", "Yes", "", "No", Null) =DialogResponse.POSITIVE Then
        Activity.Finish
            Main.ExitProg = True

And then this in the main:
B4X:
Dim ExitProg As Boolean        : ExitProg = False

Sub Activity_Resume

    If ExitProg = True Then
        ExitApplication
    End If
   
End Sub

Anything would be helpful, thank you!
 
Upvote 0

Nb1320

Member
Licensed User
Longtime User
I apologize, I did not read the first posting before I said that I had the same problem. What I posted was actually my problem, I just seen his after searching the forum. The error reads :
B4X:
Parsing code.                          0.02
Compiling code.                        Error
Error compiling program.
Error description: Cannot access excluded module: main
Occurred on line: 73
            Main.ExitProg = True
Word: main
And in the keycode back statement before was where the error is :
B4X:
Main.ExitProg = True

Sorry for the misunderstanding, but I hope someone can help.
 
Upvote 0

Similar Threads

Top