Answered by:
Converting to VB from C# RaiseEvent problem???

Question
-
User1894305733 posted
Hi I have the following code:
1 Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs) 2 MyBase.OnInit(e) 3 4 Dim login As Login = TryCast(Control, Login) 5 If Extender.AdapterEnabled AndAlso (login IsNot Nothing) Then 6 RegisterScripts() 7 login.LoggingIn += OnLoggingIn() 8 login.LoggedIn += OnLoggedIn() 9 login.LoginError += OnLoginError() 10 _state = State.LoggingIn 11 End If 12 End Sub
I get errors on line 7, 8 and 9 stating that I should use RaiseEvent to obviously raise an event. I am stuck with this after searching google but I can find no real explanation of this in terms of the login control can anyone help? Or at least point me in the right direction?
Regards
Tuppers
Saturday, May 16, 2009 7:10 AM
Answers
-
User541108374 posted
Hi,
unlike C#, VB.NET doesn't use the += syntax to add an eventhandler. Instead you should write it like this:
AddHandler login.LogginIn, AddressOf OnLoggingIn
Grz, Kris.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, May 16, 2009 7:28 AM -
User1894305733 posted
Hi thanks for the swift reply works now!
My code is:
1 Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs) 2 MyBase.OnInit(e) 3 4 Dim login As Login = TryCast(Control, Login) 5 If Extender.AdapterEnabled AndAlso (login IsNot Nothing) Then 6 RegisterScripts() 7 AddHandler login.LoggingIn, AddressOf OnLoggingIn 8 AddHandler login.LoggedIn, AddressOf OnLoggedIn 9 AddHandler login.LoginError, AddressOf OnLoginError 10 _state = State.LoggingIn 11 End If 12 End Sub
Again thanks! New to this VB stuff so learning all the time!
Tuppers
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, May 16, 2009 7:39 AM
All replies
-
User541108374 posted
Hi,
unlike C#, VB.NET doesn't use the += syntax to add an eventhandler. Instead you should write it like this:
AddHandler login.LogginIn, AddressOf OnLoggingIn
Grz, Kris.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, May 16, 2009 7:28 AM -
User1894305733 posted
Hi thanks for the swift reply works now!
My code is:
1 Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs) 2 MyBase.OnInit(e) 3 4 Dim login As Login = TryCast(Control, Login) 5 If Extender.AdapterEnabled AndAlso (login IsNot Nothing) Then 6 RegisterScripts() 7 AddHandler login.LoggingIn, AddressOf OnLoggingIn 8 AddHandler login.LoggedIn, AddressOf OnLoggedIn 9 AddHandler login.LoginError, AddressOf OnLoginError 10 _state = State.LoggingIn 11 End If 12 End Sub
Again thanks! New to this VB stuff so learning all the time!
Tuppers
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, May 16, 2009 7:39 AM -
User541108374 posted
Hi,
well perhaps this can help you in your effort while learning VB.NET: VB.NET & C# comparison cheat sheets.
Grz, Kris.
Saturday, May 16, 2009 7:55 AM