动态数组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)