我这样做是正确的,附上事件处理程序 [英] Am I doing this right, attach event handlers
本文介绍了我这样做是正确的,附上事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在做的最好的黑客工作的最新问题是我是否正确地附上了事件处理程序?我试图得到一些代码工作,我写了点点滴滴,想在一个程序中得到它。在代码的测试位中我有
Hi All,
My latest question from the wonderful hacking job I am doing is 'Am I attaching the event handler right?' I am trying to get some code working, I have written bits and pieces and would like to get it all in one program. In the test bit of code I have
AddHandler myComPort.DataReceived, AddressOf port_ATE
这会附加事件处理程序,因此在复制它时我将名称更改为
This attaches the event handler, so when copying it over I changed the name to
AddHandler AteComPort.DataReceived, AddressOf port_ATE
我还更改了以下各种名称
I have also changed the various names as below
Private Sub port_ATE(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
'ATE Event Handler
TmrNoDataAtPortATE.Enabled = False
InputDataATE = AteComPort.ReadExisting
Reply_Status_ATE = REPLY_ATE.YES_REPLY
If InputDataATE <> [String].Empty Then
Me.BeginInvoke(New SetTextCallbackATE(AddressOf SetTextATE), New Object() {InputDataATE})
' MsgBox("here!")
Else
MsgBox("null")
End If
TmrNoDataAtPortATE.Enabled = False
If (Reply_Status_ATE = REPLY_ATE.TIMEOUT_REPLY) Then
Data_Back_ATE = "TIMEOUT"
ElseIf (Reply_Status_ATE = REPLY_ATE.YES_REPLY) Then
TmrNoDataAtPortATE.Enabled = False
End If
End Sub
工作版!
working version !
Private Sub port_ATE(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
NoDataAtPort.Enabled = False
InputData = myComPort.ReadExisting
Reply_Status = REPLY.YES_REPLY
If InputData <> [String].Empty Then
Me.BeginInvoke(New SetTextCallback(AddressOf SetText), New Object() {InputData})
' MsgBox("here!")
Else
MsgBox("null")
End If
TmrNoDataAtPort.Enabled = False
If (Reply_Status = REPLY.TIMEOUT_REPLY) Then
Data_Back = "TIMEOUT"
ElseIf (Reply_Status = REPLY.YES_REPLY) Then
NoDataAtPort.Enabled = False
End If
End Sub
我认为他们是一样的!任何人都可以发现差异!请帮助!!
I think they are the same! can anyone spot a difference! Please help!!
推荐答案
在VB.NET中,您可以为一个过程添加一个Handles
子句将被识别为事件处理程序。
In VB.NET, you can add aHandles
clause to a procedure and it will be recognized as the event handler.
Private Sub port_DataReceived_1(ByVal sender As Object, _
ByVal e As SerialDataReceivedEventArgs) Handles AteComPort.DataReceived
NoDataAtPort.Enabled = False
InputData = myComPort.ReadExisting
Reply_Status = REPLY.YES_REPLY
If InputData <> [String].Empty Then
Me.BeginInvoke(New SetTextCallback(AddressOf SetText), New Object() {InputData})
' MsgBox("here!")
Else
MsgBox("null")
End If
TmrNoDataAtPort.Enabled = False
If (Reply_Status = REPLY.TIMEOUT_REPLY) Then
Data_Back = "TIMEOUT"
ElseIf (Reply_Status = REPLY.YES_REPLY) Then
NoDataAtPort.Enabled = False
End If
End Sub
这篇关于我这样做是正确的,附上事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文