vb程序总是提示下标越界,高手帮帮忙啊!
PrivateDeclareSubSleepLib"kernel32"(ByValdwmillisecondsAsLong)PrivateSubCommand1_Clic...
Private Declare Sub Sleep Lib "kernel32" (ByVal dwmilliseconds As Long)
Private Sub Command1_Click()
MSComm1.CommPort = Val(Text1.Text)
MSComm1.PortOpen = True
If MSComm1.PortOpen = True Then
Picture1.BackColor = vbRed
End If
End Sub
Private Sub Command2_Click()
MSComm1.PortOpen = False
If MSComm1.PortOpen = False Then
Picture1.BackColor = vbBlack
End If
End Sub
Private Sub Command3_Click()
Dim a(1) As Byte
Dim b() As Byte
Dim s As String
a(0) = 0
a(1) = 15
MSComm1.Output = a
Sleep (30)
b = MSComm1.Input
s = CStr(b(0))
Text2.Text = s
End Sub
Private Sub Command4_Click()
On Error Resume Next
Dim a(1) As Byte
Dim b() As Byte
Dim s As String
Dim l(18) As Long
Dim u(18) As Single
Dim i As Integer
Dim VREF As Single
VREF = 2.495
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
MSComm1.InputLen = 38
a(0) = CByte(Val(Text2.Text))
a(1) = 15
MSComm1.Output = a
Sleep (50)
b = MSComm1.Input
i = 1
For i = 1 To 18
l(i - 1) = CLng(b(i * 2)) * 255 + CLng(b(i * 2 + 1))
Next i
i = 1
For i = 1 To 18
u(i - 1) = (CSng(l(i - 1)) - CSng(l(16))) / (CSng(l(17)) - CSng(l(16))) * VREF * 25.875622
Text3(i - 1).Text = CStr(u(i - 1))
Next i
End Sub
Private Sub Command5_Click()
End
End Sub
Private Sub Command6_Click()
Dim a(2) As Byte
Dim i As Integer
If i = 1 Then
a(0) = 0
a(1) = &HF0
a(2) = CByte(Val(Text4.Text))
MSComm1.Output = a
End If
End Sub
s = CStr(b(0))提示下标越界 展开
Private Sub Command1_Click()
MSComm1.CommPort = Val(Text1.Text)
MSComm1.PortOpen = True
If MSComm1.PortOpen = True Then
Picture1.BackColor = vbRed
End If
End Sub
Private Sub Command2_Click()
MSComm1.PortOpen = False
If MSComm1.PortOpen = False Then
Picture1.BackColor = vbBlack
End If
End Sub
Private Sub Command3_Click()
Dim a(1) As Byte
Dim b() As Byte
Dim s As String
a(0) = 0
a(1) = 15
MSComm1.Output = a
Sleep (30)
b = MSComm1.Input
s = CStr(b(0))
Text2.Text = s
End Sub
Private Sub Command4_Click()
On Error Resume Next
Dim a(1) As Byte
Dim b() As Byte
Dim s As String
Dim l(18) As Long
Dim u(18) As Single
Dim i As Integer
Dim VREF As Single
VREF = 2.495
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
MSComm1.InputLen = 38
a(0) = CByte(Val(Text2.Text))
a(1) = 15
MSComm1.Output = a
Sleep (50)
b = MSComm1.Input
i = 1
For i = 1 To 18
l(i - 1) = CLng(b(i * 2)) * 255 + CLng(b(i * 2 + 1))
Next i
i = 1
For i = 1 To 18
u(i - 1) = (CSng(l(i - 1)) - CSng(l(16))) / (CSng(l(17)) - CSng(l(16))) * VREF * 25.875622
Text3(i - 1).Text = CStr(u(i - 1))
Next i
End Sub
Private Sub Command5_Click()
End
End Sub
Private Sub Command6_Click()
Dim a(2) As Byte
Dim i As Integer
If i = 1 Then
a(0) = 0
a(1) = &HF0
a(2) = CByte(Val(Text4.Text))
MSComm1.Output = a
End If
End Sub
s = CStr(b(0))提示下标越界 展开
3个回答
展开全部
Private Sub Command3_Click()
Dim a(1) As Byte
Dim b() As Byte
Dim s As String
a(0) = 0
a(1) = 15
MSComm1.Output = a
Sleep (30)
b = MSComm1.Input
s = CStr(b(0))
Text2.Text = s
End Sub
Dim b() As Byte b元素个数为0
因此CStr(b(0))报错,看看是不是你原来要写cstr(a(0))?
Dim a(1) As Byte
Dim b() As Byte
Dim s As String
a(0) = 0
a(1) = 15
MSComm1.Output = a
Sleep (30)
b = MSComm1.Input
s = CStr(b(0))
Text2.Text = s
End Sub
Dim b() As Byte b元素个数为0
因此CStr(b(0))报错,看看是不是你原来要写cstr(a(0))?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询