Variables

M

mikeymay

I am naming a boolean variable, say Var1 from a textbox in
a user form, I am wanting to call up that variable in a
subsequent sub routine within the macro, but Var1 in the
subsequent code is always empty...

What am I doing wrong
 
M

mikeymay

Did post in Programming, but it seemed to disappear.
Thought maybe someone had deleted it as it was in wrong
board......
 
H

Harald Staff

Frank Kabel said:
Hi
then you have to dim this variable as global (outside your procedure)

Have to ? What happened to "One way is to ..." ? <g>

Best wishes Harald
 
M

mikeymay

Tried 'Global Var1 as Boolean' and Var1 is still empty
when code runs.

I have dimensioned Var1 as global in my module and Var1 is
being named in a rountine within the Form (won't let me
dim as Global in Form Declarations) When the code in my
module runs and I want to call up Var1 it's empty.

???????
 
H

Harald Staff

Reposting it here then:

Apart from globals, my preference is to pass variables to the macros that
need them, like this:

Sub tester()
Dim B As Boolean
B = True
Call NextOne(B)
B = Not B
Call ThirdOne(B, "Simon says:")
End Sub

Sub NextOne(B As Boolean)
MsgBox "Next one says " & B
End Sub

Sub ThirdOne(B As Boolean, S As String)
MsgBox S & vbNewLine & B
End Sub

HTH. Best wishes Harald
 
Top