Accessing Class Properties from Other Subs

byoung

Member
Joined
Jan 23, 2003
Messages
9
I have a Class oMenu that I have defined in a sub called cmdBox1_Click

I have another event called cmdBox2_Click tha I want to access the properties, etc from the object defined in cmdBox1_Click.

Any way to do this?

Example:

Sub cmdBox1_Click

Dim oMenu as New oClassMenu

Set the property here...
oMenu.MenuSelection = "Edit"

End Sub

Sub cmdBox2_Click

Want to access the property MenuSelection set from cmdBox1_ Click sub

msgbox( oMenu.MenuSelection)

End Sub
 
Your best bet is to define oMenu at the form level instead of inside the cmdBox1_Click event. Then its accessible anywhere on the form. From within cmdBox2_Click, you can first check if its been set with something like:
Code:
If Not (oMenu Is Nothing) Then
     Use oMenu
End If

At least, thats how youd check it in VB6 - I think its the same syntax :)

-nerseus
 
Back
Top