我试图将一些VB6代码转换为VB.Net
{{ piedata|tojson }}
我的问题是:
什么是VB.Net中的Private Sub MSComm1_OnComm()
Dim RxNumeric As String
Dim i As Integer
Rx = MSComm1.Input
RxNumeric = ""
For i = 1 To Len(Rx)
SReply(i - 1) = Asc(Mid(Rx, i, 1))
RxNumeric = RxNumeric + " " + Hex(SReply(i - 1))
Next i
txtWindow.Text = RxNumeric
Replied = True
End Sub
?
如果这应该在MSComm1_OnComm
内,我应该包括什么?
答案 0 :(得分:1)
Imports System.IO.Ports
WithEvents MSComm1 As SerialPort
Private Sub MSComm1_DataReceived(ByVal eventSender As System.Object, ByVal eventArgs As SerialDataReceivedEventArgs) Handles MSComm1.DataReceived
Dim RxNumeric As String
Dim i As Short
Dim Rx As String = MSComm1.ReadExisting
RxNumeric = ""
For i = 1 To Len(Rx)
SReply(i - 1) = Asc(Mid(Rx, i, 1))
RxNumeric = RxNumeric & " " & Hex(SReply(i - 1))
Next i
txtWindow.Text = RxNumeric
Replied = True
End Sub
答案 1 :(得分:0)
与@ EJD的答案相同,但优化:
<
胜过Int16,>
个)和Int32
和managed
对象Using
我也可以摆脱SReply阵列,但我离开了 - 只是为了可读性。