How to Pass Values/Varaibles between forms?

I have a VB6.0 app with a lot of interaction between forms.  I hate using global variables but it seesm like this is the only way to pass information from one form to another.  For example I am on frmClientMaint, which is used to maintain the general information (name, address, contact, phone etc..) about a client.  I have another form (frmClientItem) that is used to maintian a list of products which this client can order.  The user presses a button on frmClientMaint to present frmClientItem.  frmClientItem needs to know which client is being worked on so I place this value in a global variable prior to executing, like this:

gCurrClientId = wkClientId
frmClientItem.Show vbmodal

gCurrClientID is defined in Module 1 as 'Public gCurrClientID As Long'.  It seems like there must be a better way of doing this but I haven't uncovered it yet.

What techniques to the experts use?
LVL 1
mlcktmguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

List244Commented:
If you want to know IMMEDIATELY what they do, you can create a function on the second form like:

public function MyFunc(byref Var)
//Var will have been passed to here
end function

If you need it more permanently... then you can have the same thing only in MyFunc you would take
that var and save it to a private variable, either way you do not need a public variable.


http://www.developerfusion.co.uk/show/51/6/


So basically the workaround of a public variable is to call a function on the other form which is public
and have that store the value in its own private variable.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark_FreeSoftwareCommented:
'Declaration needed:
Private sYourValHere As String

'Property Get/Let (for retreiving value)
Public Property Get YourValHere() As String
   YourValHere = sYourValHere
End Property

Public Property Let YourValHere(ByVal vNewValue As String)
   sYourValHere = vNewValue
End Property

'Usage:
Private Sub Form_Load()
   Form1.YourValHere = "test"
   MsgBox Form1.YourValHere
End Sub
0
mlcktmguyAuthor Commented:
Both solutions are valid and address my situation, hoever list244 was first so I will award the point to him.  Thatnks for your responses.
0
Mark_FreeSoftwareCommented:
ok
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.