VB6到VB.NET等价

时间:2015-07-30 16:30:19

标签: vb.net vb6

我试图将一些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内,我应该包括什么?

2 个答案:

答案 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,
  • 不要使用LEGACY方法(赞成>个)和
  • 利用Int32
  • managed对象
Using

我也可以摆脱SReply阵列,但我离开了 - 只是为了可读性。