I am trying to create a basic example of raising an event in vb.net, and I am hoping that by studying it thoroughly I can upgrade the way my system receives data from serial port.
Right now I have a system that receives the incoming data from serial port via timers, the problem is there are certain events in a system that conflicts in my timer. Because of this I am planning to change the way I received the data from serial ports, instead of timer I want to use vb.net raiseevent.
Unfortunately I can't find a simple example on how to use this event, by searching thoroughly I saw the MSDN's post about this topic and it is here. So, how do I use this example? I tried using it below like that
Public Event TimeExpired(ByVal Status As String)
Public Sub RaiseTimeExpiredEvent()
RaiseEvent TimeExpired("Your time has run out")
MessageBox.Show(TimeExpired())
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
RaiseTimeExpiredEvent()
End Sub
It's not working working, the error is
Error 1 'Public Event TimeExpired(Status As String)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. C:\Users\Cary\Desktop\Projects\Testing\Testing\Testing\Form1.vb 5 25 Testing
Because of that error I tried to do it like this
Class Form1
Public Event TimeExpired(ByVal Status As String)
Public Sub RaiseTimeExpiredEvent()
RaiseEvent TimeExpired("Your time has run out")
MessageBox.Show(TimeExpired())
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
RaiseEvent TimeExpired()
End Sub
End Class
But the error states
Error 2 Argument not specified for parameter 'Status' of 'Public Event TimeExpired(Status As String)'. C:\Users\Cary\Desktop\Projects\Testing\Testing\Testing\Form1.vb 11 9 Testing