Accessing Class Properties from Other Subs

byoung

Newcomer
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 it's accessible anywhere on the form. From within cmdBox2_Click, you can first check if it's been set with something like:
Visual Basic:
If Not (oMenu Is Nothing) Then
    ' Use oMenu
End If

At least, that's how you'd check it in VB6 - I think it's the same syntax :)

-nerseus
 
Back
Top