以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  串口监视器,DataReceived参数“Length”必须大于或等于 0  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=170159)

--  作者:tommyfung
--  发布时间:2021/7/14 10:51:00
--  串口监视器,DataReceived参数“Length”必须大于或等于 0
串口监视器,DataReceived参数“Length”必须大于或等于 0。System.ArgumentException: 参数“Length”必须大于或等于 0。
   在 Microsoft.VisualBasic.Strings.Left(String str, Int32 Length)
   在 UserCode.DataReceived(DataReceivedEventArgs e)


不知道问题出在哪儿?谢谢!

Dim s As String
s = e.Port.ReadExisting()
\'s = "LBL11A1512109+UBS"


If len(s) < 3 Then Return

\' * check COM Input Type : LBL = Scanner ID for Label Printing
If left(s,3) = "LBL" Then
    
    s = left( s, If(len(s)<25,22, s.IndexOf("LBL",17)) )
.....

End If
[此贴子已经被作者于2021/7/14 10:57:34编辑过]

--  作者:有点蓝
--  发布时间:2021/7/14 11:14:00
--  
s = left( s, If(len(s)<25,22, s.IndexOf("LBL",17)) )
改为

if len(s)<25
s=  left( s, 22)
else
dim idx as integer = s.IndexOf("LBL",17)
if idx > -1 then
s=  left( s, idx)
end if
end if