动态数组Redim 传参数的问题
Private sendbuff() As Byte '
private sub senddata()
Do While j < singlenum
GetNum=.......
ReDim sendbuff(12 + GetNum) '第一次循环通过,第二次出错 "This array is fixed or temporarily locked "
sendbuff(0)=170
sendbuff(1)=170
;
;
If Not sendsucc(sendbuff, lenbuff) Then
is_sendbool = False
MsgBox ( "通信错误过多,停止发送! ")
closehandle(hcomm)
Exit Do
End If
end sub
Private Function sendbuff(buff() As Byte, sLen As Long) As Boolean
Dim answer As Long
Dim ret As Long
ret = WriteFile(hComm, buff(1), sLen, answer, 0) 'hComm 打开Comm1
Sleep 10
sendbuff= ret
End Function
'打开串口
hComm = CreateFile( "COM1 ", GENERIC_READ Or GENERIC_WRITE, 0, ByVal 0&, OPEN_EXISTING, FILE_FLAG_POSIX_SEMANTICS, 0)
[解决办法]
我想你需要延迟一会,就是你发送太快了,该内存正在被使用,你试图重定义内存快大小
你单步调式,看还是这个错误不??
If Not sendsucc(sendbuff, lenbuff) Then
is_sendbool = False
MsgBox ( "通信错误过多,停止发送! ")
closehandle(hcomm)
Exit Do
End If
doevents
[解决办法]
检查的方法,如果你怀疑参数问题的话就不要作为参数传出。把那个函数写入主函数看看
[解决办法]
动态数组当做参数;调用后不可重新Redim.