Problème avec Code Module

ciginfo

Well-Known Member
Licensed User
Longtime User
I'm studing Code Module
Bonjour,

In Code Module
Sub CALCULE
Dim a, b, x As Int
x = a + b
End Sub

In main
Sub BtnCalcule_Click
code.a = 3
code.b = 2
code.CALCULE
LblResult.Text = code.x
End Sub

Thanks. I don't understand the tuto very well.

Why it returns 0 and not 5
 

ciginfo

Well-Known Member
Licensed User
Longtime User
It is

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim a, b, x As Int
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You should dim the three variables in Process_Globals of the code module.
But not in the Sub CALCULE routine.

It would be more universal to use a code like this one:
Main module
B4X:
LblResult.Text = code.CALCULE(a1, a2)

And in the code module
B4X:
Sub CALCULE(a As Int, b As Int) as Int
  Return (a + b)
End Sub
Best regards.
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Ah yes i understand now.
"Dim a, b, x as Int" was in Sub Process_Global in code module but also in Sub CALCULE.
With dim only in Sub Process_Global it works

Thanks
 
Upvote 0
Top