求助:运行时出现错误!

lqg1999 2007-01-08 10:50:05
本人vb初学者,有个问题希望高手看一下:
现在做个通过串口采集下位仪表的小程序,单步运行的时候能采集到值,可是全部运行就出现错误:实时错误 '5'
无效的过程调用或参数

然后我点“调试”按钮,就进入到:

Function RecvCmdCom(buf As String) As String

Dim strRead As String
Dim intBeginBit As Integer
Dim intEndBit As Integer

intBeginBit = InStr(1, buf, ",")
intEndBit = InStr(intBeginBit, buf, ":")
strRead = Mid(buf, intBeginBit + 1, intEndBit - intBeginBit - 1)

RecvCmdCom = Str(Val("&H" & strRead))

End Function

光标停在strRead = Mid(buf, intBeginBit + 1, intEndBit - intBeginBit - 1)
这个语句上。

请问各位高手,这个这么解决呢?是什么原因?
...全文
188 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
tmd007 2007-01-08
  • 打赏
  • 举报
回复
Function RecvCmdCom(buf As String) As String

Dim strRead As String
Dim intBeginBit As Integer
Dim intEndBit As Integer

intBeginBit = InStr(1, buf, ",")'这句加个判断
if intBeginBit = 0 then '如果buf 中没有"," ,那么
RecvCmdCom=""
exit function
end if
intEndBit = InStr(intBeginBit, buf, ":")'这句加个判断
if intEndBit = 0 then '如果buf 中没有":" ,那么
RecvCmdCom=""
exit function
end if
strRead = Mid(buf, intBeginBit + 1, intEndBit - intBeginBit - 1)

RecvCmdCom = Str(Val("&H" & strRead))

End Function

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧