用VB运行时出现要求对象是怎么回事呀?求高手指点一下! 5
OptionExplicitDimccount(20)AsLongDimwtimeAsIntegerDimissingAsIntegerDimisstopAsBoolea...
Option Explicit
Dim ccount(20) As Long
Dim wtime As Integer
Dim issing As Integer
Dim isstop As Boolean
Dim aa(0) As Byte
Dim jiaoyan(0) As Byte
Dim indata As String
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Function DecToHex(DecNumber As Integer) As String '转换成十六进制字符串
If DecNumber <= 15 Then
DecToHex = " 0" & Hex(DecNumber)
Else: DecToHex = " " & Hex(DecNumber)
End If
End Function
Function DecToHex3(DecNumber As Integer) As String '转换成十六进制字符串
If DecNumber <= 15 Then
DecToHex3 = " 0" & Hex(DecNumber)
Else: DecToHex3 = " " & Hex(DecNumber)
End If
End Function
Function DecToHex2(DecNumber As Integer) As String '转换成十六进制字符串
If DecNumber <= 15 Then
DecToHex2 = "0" & Hex(DecNumber)
Else: DecToHex2 = Hex(DecNumber)
End If
End Function
Function CToHex2(bnum As String) As Integer '字符串转换成十六进制数
Dim S1 As String
Dim s, S2 As Integer
Dim i As Integer
S2 = 0
For i = 1 To Len(bnum)
S1 = Mid(bnum, i, 1)
s = CDec(S1) * 16 ^ (Len(bnum) - i)
S2 = S2 + s
Next i
CToHex2 = S2
End Function
Private Sub MSComm1_OnComm()
Dim MSComm1
Dim intno As Integer
Dim intcom As Integer
Dim indata As String
Dim i As Integer
Dim j As Long
Dim jy As Byte
Dim InByte() As Byte '存储数据的缓冲区'定义一个二进制指针放接收到的数据
Select Case MSComm1.CommEvent '选择事件
Case comEvReceive '接收到字符
intcom = MSComm1.InBufferCount
If intcom > 12 Then
intno = (intcom - intcom Mod 13) \ 13
For i = 0 To intno - 1
ReDim InByte(13)
InByte() = MSComm1.Input '数据转移到指针
jy = InByte(0)
For j = 1 To 11
jy = jy Xor InByte(j)
Next j
If InByte(0) = &HBB And InByte(1) = &HFF And jy = InByte(12) Then
If InByte(4) = &H5 Then
Select Case InByte(5)
Case &HC
'确定
Text5.SelText = "确定" & " "
Case &HD
'取消
Text5.SelText = "取消" & " "
Case &HE
'加
Text5.SelText = "F1" & " "
Case &HF
Text5.SelText = "F2" & " "
Case &HA
Text5.SelText = "0" & " "
Case &HB
Text5.SelText = "." & " "
Case Else
'显示输入的字符
Text5.SelText = CDec(InByte(5)) & " "
End Select
End If 'InByte(4) = &H5
If InByte(4) = &HA Then
If InByte(5) = &HAA Then '总线是否忙
isbuzy = False
End If
End If
For j = 0 To 12
indata = indata & DecToHex3(CDec(InByte(j)))
Next j
Text2.SelText = indata
indata = ""
End If 'InByte(0) = &HBB And InByte(1) = &HFF
Next i
End If 'UBound(InByte) = 12
Case comEventRxOver '接收缓冲区满的处理
MsgBox "接收缓冲区满了!" '发出警告
Case comEventTxFull
MsgBox "传输缓冲区满了!"
End Select
Exit Sub
err1:
MsgBox Err.Description
End Sub
这只是一小部分的程序,实在补充不下了,太长了。 展开
Dim ccount(20) As Long
Dim wtime As Integer
Dim issing As Integer
Dim isstop As Boolean
Dim aa(0) As Byte
Dim jiaoyan(0) As Byte
Dim indata As String
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Function DecToHex(DecNumber As Integer) As String '转换成十六进制字符串
If DecNumber <= 15 Then
DecToHex = " 0" & Hex(DecNumber)
Else: DecToHex = " " & Hex(DecNumber)
End If
End Function
Function DecToHex3(DecNumber As Integer) As String '转换成十六进制字符串
If DecNumber <= 15 Then
DecToHex3 = " 0" & Hex(DecNumber)
Else: DecToHex3 = " " & Hex(DecNumber)
End If
End Function
Function DecToHex2(DecNumber As Integer) As String '转换成十六进制字符串
If DecNumber <= 15 Then
DecToHex2 = "0" & Hex(DecNumber)
Else: DecToHex2 = Hex(DecNumber)
End If
End Function
Function CToHex2(bnum As String) As Integer '字符串转换成十六进制数
Dim S1 As String
Dim s, S2 As Integer
Dim i As Integer
S2 = 0
For i = 1 To Len(bnum)
S1 = Mid(bnum, i, 1)
s = CDec(S1) * 16 ^ (Len(bnum) - i)
S2 = S2 + s
Next i
CToHex2 = S2
End Function
Private Sub MSComm1_OnComm()
Dim MSComm1
Dim intno As Integer
Dim intcom As Integer
Dim indata As String
Dim i As Integer
Dim j As Long
Dim jy As Byte
Dim InByte() As Byte '存储数据的缓冲区'定义一个二进制指针放接收到的数据
Select Case MSComm1.CommEvent '选择事件
Case comEvReceive '接收到字符
intcom = MSComm1.InBufferCount
If intcom > 12 Then
intno = (intcom - intcom Mod 13) \ 13
For i = 0 To intno - 1
ReDim InByte(13)
InByte() = MSComm1.Input '数据转移到指针
jy = InByte(0)
For j = 1 To 11
jy = jy Xor InByte(j)
Next j
If InByte(0) = &HBB And InByte(1) = &HFF And jy = InByte(12) Then
If InByte(4) = &H5 Then
Select Case InByte(5)
Case &HC
'确定
Text5.SelText = "确定" & " "
Case &HD
'取消
Text5.SelText = "取消" & " "
Case &HE
'加
Text5.SelText = "F1" & " "
Case &HF
Text5.SelText = "F2" & " "
Case &HA
Text5.SelText = "0" & " "
Case &HB
Text5.SelText = "." & " "
Case Else
'显示输入的字符
Text5.SelText = CDec(InByte(5)) & " "
End Select
End If 'InByte(4) = &H5
If InByte(4) = &HA Then
If InByte(5) = &HAA Then '总线是否忙
isbuzy = False
End If
End If
For j = 0 To 12
indata = indata & DecToHex3(CDec(InByte(j)))
Next j
Text2.SelText = indata
indata = ""
End If 'InByte(0) = &HBB And InByte(1) = &HFF
Next i
End If 'UBound(InByte) = 12
Case comEventRxOver '接收缓冲区满的处理
MsgBox "接收缓冲区满了!" '发出警告
Case comEventTxFull
MsgBox "传输缓冲区满了!"
End Select
Exit Sub
err1:
MsgBox Err.Description
End Sub
这只是一小部分的程序,实在补充不下了,太长了。 展开
3个回答
展开全部
哪一行报需要对象错误啊?
追问
没有显示哪一行需要要求对象,就是运行的时候出现要求对象这四个字,不知道哪里有问题,看了看程序感觉应该没有啥问题啊。我对VB 不是很懂啊!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
跟踪一下,看运行那一句出现错误:要对象!这样才好修改呀..
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询