VB代码 转换C#代码
第一段:Dim a(8), b(8), c(8) As Single
For x = 1 To 8
a(x) = 0
b(x) = 0
c(x) = 0
Next x
N = Len(dec2bin("&h" & Text4(1).Text))
For x = 1 To N
a(x) = Mid((dec2bin("&h" & Text4(1).Text)), N - x + 1, 1)
Next x
N = Len(dec2bin("&h" & Text4(2).Text))
For x = 1 To N
b(x) = Mid((dec2bin("&h" & Text4(2).Text)), N - x + 1, 1)
Next x
N = Len(dec2bin("&h" & Text4(3).Text))
For x = 1 To N
c(x) = Mid((dec2bin("&h" & Text4(3).Text)), N - x + 1, 1)
Next x
第二段:
On Error Resume Next
Dim buffer() As Byte
Dim i As Integer
Select Case MSComm3.CommEvent
Case comEvReceive
buffer = MSComm3.Input
For i = 0 To UBound(buffer)
If Len(Hex(buffer(i))) = 1 Then
strData = strData & "0" + Hex(buffer(i))
Else
strData = strData & Hex(buffer(i))
End If
Next i
Text4(0).Text = Mid(strData, 1, 2)
Text4(1).Text = Mid(strData, 3, 2)
Text4(2).Text = Mid(strData, 5, 2)
Text4(3).Text = Mid(strData, 7, 2)
Text4(4).Text = Mid(strData, 9, 2)
strData = ""
If Text4(4).Text = Right("0" & Hex(Val("&h" & Text4(0).Text) + Val("&h" & Text4(1).Text) + Val("&h" & Text4(2).Text) + Val("&h" & Text4(3).Text)), 2) Then
Call yunxian
' Text2(0).Text = Text4(0).Text
' Text2(1).Text = Text4(1).Text
' Text2(2).Text = Text4(2).Text
' Call yunxian1
Else
Text4(0).Text = ""
Text4(1).Text = ""
Text4(2).Text = ""
Text4(3).Text = ""
Text4(4).Text = ""
End If
MSComm3.InBufferCount = 0
End Select