Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing VB Module Value From One Module To Another VB Module In Same P

Status
Not open for further replies.

Kevsim

Instructor
Apr 18, 2000
385
AU
I have a module,( Module1 ) and the variable “A”, I then set the variable to equal 5, while in this module (Module1).
I call another module ( Module2 ) before Module1 ends ( End Sub ), how can I hold the value of “A” created in Module1 to Module2?
Also if I change the value in Module 2 to say, 7, how do I carry this value back to Module1 before End Sub.

I would appreciate some advise.
kevsim
 
Use a Public variable defined outside any procedure.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
[/code]
Public Sub sub1()
Dim A As Integer
A = 2
Call sub2(A)
MsgBox A
End Sub

Public Sub sub2(ByRef intA As Integer)
intA = 7
End Sub
[/code]
Although you can do it with a global variable, there is no need. If you pass a variable by reference it is a pointer to that variable. So if you change it in another sub then it changes the orginal variable.

What does the msgbox print? 7
 
PHV,MajP,
I thank you both for the advise, all working OK.
MajP, I like your method.
kevsim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top