以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]未将对象引用设置到对象的实例  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=137458)

--  作者:YDS
--  发布时间:2019/7/6 14:46:00
--  [求助]未将对象引用设置到对象的实例
.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2019.7.8.1
错误所在事件:计划LLNJ
详细错误信息:
未将对象引用设置到对象的实例。

我的电脑上未出现任何问题,发布以后本机测试没有问题,传给客户以后出现如上问题,计划LLNJ的代码如下:
Static V As Integer
Dim ck As String = Functions.Execute("GET","串口号","LLNJ","值")
If Ports.Contains(ck) Then
    If Ports(ck).IsOpen Then
        If V < 1 Or V > 3 Then
            V = 1
        End If
        vars("sj" & V) = Nothing
        vars("jsln") = V
        Dim ff As uInteger() = {&H0 & V,&H03,&H00,&H00,&H00,&H02}
        Dim aa As Integer = CRC16(ff,ff.Length)
        Dim crc As String = DecToHex(aa).ToUpper()
        crc = crc.PadLeft(4,"0")
        Dim crcl As Integer = HexToDec(crc.SubString(2,2))
        Dim crch As Integer = HexToDec(crc.SubString(0,2))
        Dim Val() As Byte = New Byte() {V,3,0,0,0,2,crcl,crch}
        Ports(ck).Write(Val, 0, Val.Length)
        V = V + 1
    End If
End If

--  作者:有点蓝
--  发布时间:2019/7/6 14:56:00
--  
看看是哪一句代码有问题:http://www.foxtable.com/webhelp/topics/1485.htm

Functions.Execute("GET","串口号","LLNJ","值")这个函数有什么代码?

CRC16有定义这个全局函数吗

Dim ff As uInteger() = {&H0 & V,&H03,&H00,&H00,&H00,&H02} ‘这里有个空格,去掉

--  作者:YDS
--  发布时间:2019/7/6 15:14:00
--  
Dim ff As uInteger() = {&H0 & V,&H03,&H00,&H00,&H00,&H02} ‘这里需要有个空格吧   V是个变量  
我把下面代码输入命令窗口
Dim V As Integer
Dim ff As uInteger() = {&H0 & V,&H03,&H00,&H00,&H00,&H02}
Dim aa As Integer = CRC16(ff,ff.Length)
Dim crc As String = DecToHex(aa).ToUpper()
crc = crc.PadLeft(4,"0")
Dim crcl As Integer = HexToDec(crc.SubString(2,2))
Dim crch As Integer = HexToDec(crc.SubString(0,2))
Output.Show(crcl)
Output.Show(crch)
输出
197
218

Output.Show(Functions.Execute("GET","串口号","LLNJ","值"))   输出   COM3  都没有问题

--  作者:YDS
--  发布时间:2019/7/6 15:15:00
--  
Dim V As Integer
v = 1
Dim ff As uInteger() = {&H0 & V,&H03,&H00,&H00,&H00,&H02}
Dim aa As Integer = CRC16(ff,ff.Length)
Dim crc As String = DecToHex(aa).ToUpper()
crc = crc.PadLeft(4,"0")
Dim crcl As Integer = HexToDec(crc.SubString(2,2))
Dim crch As Integer = HexToDec(crc.SubString(0,2))
Output.Show(crcl)
Output.Show(crch)
输出
196
11

--  作者:有点蓝
--  发布时间:2019/7/6 15:34:00
--  
直接在函数里调试,那一句代码有问题?
--  作者:YDS
--  发布时间:2019/7/6 15:45:00
--  
调试的时候没有问题,是在运行中出现的问题

.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2019.7.8.1
错误所在事件:自定义函数LLNJ
详细错误信息:
调用的目标发生了异常。
索引超出了数组界限。

这个是刚刚出现的问题

--  作者:有点蓝
--  发布时间:2019/7/6 16:18:00
--  
把messagebox改为使用output.show静默调试,打开命令窗口看结果

这种提示是索引使用超界,检查代码中使用索引的地方,看看哪句代码后有问题

--  作者:YDS
--  发布时间:2019/7/8 13:08:00
--  
现在有成了这个错误了,而且不是一直存在,有时候没有问题,有时候运行一会就出现问题
.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2019.7.9.1
错误所在事件:自定义函数LLNJ
详细错误信息:
调用的目标发生了异常。
索引超出范围。必须为非负值并小于集合大小。
参数名: index

--  作者:YDS
--  发布时间:2019/7/8 13:13:00
--  
Dim jssj As String
Dim sj As String = args(0)
vars("sj" & vars("jsln")) = vars("sj" & vars("jsln")) & "-" & sj
vars("sj" & vars("jsln")) = vars("sj" & vars("jsln")).Trim("-")
jssj = vars("sj" & vars("jsln"))
If vars("kln") = 1 Then
    If jssj > "" Then
        If jssj.Contains("-") Then
            Dim V() As String = jssj.split("-")
            If V.Length = 9 Then
                Dim dll As String = Functions.Execute("GET","地址","拉力","值")
                Dim dnj As String = Functions.Execute("GET","地址","扭矩","值")
                Dim dzs As String = Functions.Execute("GET","地址","转速","值")
                If jssj.StartsWith(dnj & "-3-4-") Then
                    Dim s,str As String
                    Dim v1 As Integer
                    s = DecToBin(V(3)).PadLeft(8,"0") & DecToBin(V(4)).PadLeft(8,"0") & DecToBin(V(5)).PadLeft(8,"0") & DecToBin(V(6)).PadLeft(8,"0")
                    Dim bmlx As String = Functions.Execute("GET","编码类型","扭矩","值")
                    v1 = Functions.Execute("SN",s,bmlx)
                    Dim bl As Double = Functions.Execute("GET","分辨率","扭矩","值")
                    Dim vv As Double = v1 * bl
                    If math.Abs(vv) < Functions.Execute("GET","极限值","扭矩","值") Then
                        If forms("主窗口").opened Then
                            Forms("主窗口").Controls("nj").text = vv
                        End If
                    End If
                ElseIf jssj.StartsWith(dll & "-3-4-") Then
                    Dim s,str As String
                    Dim v1 As Integer
                    s = DecToBin(V(3)).PadLeft(8,"0") & DecToBin(V(4)).PadLeft(8,"0") & DecToBin(V(5)).PadLeft(8,"0") & DecToBin(V(6)).PadLeft(8,"0")
                    Dim bmlx As String = Functions.Execute("GET","编码类型","拉力","值")
                    v1 = Functions.Execute("SN",s,bmlx)
                    Dim bl As Double = Functions.Execute("GET","分辨率","拉力","值")
                    Dim vv As Double = v1 * bl
                    If math.Abs(vv) < Functions.Execute("GET","极限值","拉力","值") Then
                        If forms("主窗口").opened Then
                            Forms("主窗口").Controls("ll").text = vv
                        End If
                    End If
                ElseIf jssj.StartsWith(dzs & "-3-4-") Then
                    Dim s,str As String
                    Dim v1 As Integer
                    s = DecToBin(V(3)).PadLeft(8,"0") & DecToBin(V(4)).PadLeft(8,"0")
                    v1 = BinToDec(s)
                    Dim bl As Double = Functions.Execute("GET","分辨率","转速","值")
                    Dim vv As Double = v1 * bl
                    If math.Abs(vv) < Functions.Execute("GET","极限值","转速","值") Then
                        If forms("主窗口").opened Then
                            Forms("主窗口").Controls("zs").text = vv
                        End If
                    End If
                End If
            End If
        End If
    End If
End If

--  作者:有点蓝
--  发布时间:2019/7/8 13:49:00
--  
代码我看不出有什么问题,调试看看到哪一句代码开始出错?