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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RaiseEvent Oddity

Status
Not open for further replies.

IanAble

Programmer
Jan 24, 2005
112
GB
Hi There,

I'm getting some weird behaviour trapping events within a collection class.

The basic structure is
1. A form with 4 TextBoxes.
2. Each TextBox is referenced WithEvents in a class called clsKey.
3. The referenced TextBox.OnFocus Event is used to raise an event called ActivateKey, which has clsKey.Me as the parameter.
4. Each clsKey is referenced WithEvents in the collection object of a class called clsKeys.

Now here's the thing. When any of the TextBoxes get the TextBox.OnFocus event raises the ActivateKey event. However, this event is only trapped in clsKeys if the TextBox is not null.

Here's the code:
|Class clsKey|

Private WithEvents ctlTextBox As TextBox
Public Event ActivateKey(ByVal ActiveKey As clsKey)

Private Sub ctlTextBox_GotFocus()
RaiseEvent ActivateKey(Me)
End Sub

|Class clsKeys|

Private WithEvents objKey As clsKey
Private objActiveKey As clsKey

Private Sub objKey_ActivateKey(ByVal ActiveKey As clsKey)
Set objActiveKey = ActiveKey
End Sub


Any ideas anyone?
 
Can you also include the code that:

1. instantiates the two classes
2. ties an instance of a textbox on a form to your ctlTextBox variable.

Thx

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top