以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]读com端口,索引超出了数组界限 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=118080) |
-- 作者:wangjh8888 -- 发布时间:2018/4/24 17:21:00 -- [求助]读com端口,索引超出了数组界限 老师 我下面代码 在计时器读取com1的GPS数据,有时会出现: .NET Framework 版本:2.0.50727.5472 Foxtable 版本:2018.3.9.1 错误所在事件:窗口,GPS接收,TimerTick 详细错误信息: 索引超出了数组界限。 问题在哪里? 怎么处理? Dim s As String Dim COMStr As String = e.Form.Controls("ComboBox_com").value s = Ports(COMStr).ReadExisting If S.Length > 0 AndAlso S.Contains("$GPGGA") Then \'判断是否含有 字符串 "$GPGGA" S = S.Remove(0,S.IndexOf("$GPGGA")) Else Return End If Dim rs1() As String = s.Split(vbcrlf ) Dim rs_max,rs_long As Integer rs_max = 20 rs_long = rs1.Length -1 If rs_max < rs1.Length Then rs_long = rs_max End If For i As Integer = 0 To rs_long -1 Dim cs1() As String = rs1(i).Split(",") If cs1.Length = 15 And cs1(0) = "$GPGGA" And cs1(6) = "1" Then e.Form.Controls("TextBox_GPStxt").value = rs1(i) e.Form.Controls("TextBox_gpsn").value = cs1(7) \' 卫星数 End If Next |
-- 作者:有点甜 -- 发布时间:2018/4/24 17:49:00 -- 加入msgbox弹出值看一下
Dim cs1() As String = rs1(i).Split(",")
msgbox(cs1.length)
If cs1.Length = 15 AndAlso cs1(0) = "$GPGGA" AndAlso cs1(6) = "1" Then
|
-- 作者:wangjh8888 -- 发布时间:2018/4/24 19:25:00 -- 嗯嗯 大部分是 15,13,18,20 |
-- 作者:有点蓝 -- 发布时间:2018/4/24 20:27:00 -- 按2楼方法改后还有问题么? |