Keith_McCloy
Member
- Joined
- Dec 13, 2011
- Messages
- 6
- Programming Experience
- 10+
My reference for this is Francesco Balena's Visual Basic.NET from 2002, so it may be out of date.
I have created a simple class (MyNameClass) of two strings (first and last names) and an Event, FullName(ByVal fullName As String) that just contains a Constructor (New(astring, bstring)) and a Function (XFullName() to create and return the Full Name as the join of the two strings, as well as a RaiseEvent FullName(astring). Then I created a simple application that created an array called names() of type MyNameClass by placing values in the two fields for each entry in the array, and a button that created and displayed the full name.
First I tried inserting an AddHandler names(kurrent).FullName, AddressOf FullNameEvent in this Button1_Click sub and a Sub;-
Sub FullNameEvent(ByVal astring As String)
Dim bstring As String = Nothing
bstring = "Event Full Name used for " & astring
MsgBox(bstring, MsgBoxStyle.OkOnly, "Event Trapping")
End Sub
But whilst the processing passed through the AddHandler commmand it never went into the FullNameEvent Sub. So, then I removed that AddHandler and tried adding a Sub to AddHandler p.FullName, AddressOf FullNameEvent for each member of the array of names(). Bu that does not work either. The program works; but the event trapping message does not happen.
I would appreciate any advice. :friendly_wink:
I have created a simple class (MyNameClass) of two strings (first and last names) and an Event, FullName(ByVal fullName As String) that just contains a Constructor (New(astring, bstring)) and a Function (XFullName() to create and return the Full Name as the join of the two strings, as well as a RaiseEvent FullName(astring). Then I created a simple application that created an array called names() of type MyNameClass by placing values in the two fields for each entry in the array, and a button that created and displayed the full name.
First I tried inserting an AddHandler names(kurrent).FullName, AddressOf FullNameEvent in this Button1_Click sub and a Sub;-
Sub FullNameEvent(ByVal astring As String)
Dim bstring As String = Nothing
bstring = "Event Full Name used for " & astring
MsgBox(bstring, MsgBoxStyle.OkOnly, "Event Trapping")
End Sub
But whilst the processing passed through the AddHandler commmand it never went into the FullNameEvent Sub. So, then I removed that AddHandler and tried adding a Sub to AddHandler p.FullName, AddressOf FullNameEvent for each member of the array of names(). Bu that does not work either. The program works; but the event trapping message does not happen.
I would appreciate any advice. :friendly_wink: