Princesk 2021-03-19 10:51 采纳率: 0%
浏览 34

Vbs脚本类型不匹配 [String"check_error"]

写了一个挂载xshell的脚本有函数,但是就是说类型有问题,代码如下


Function error (count0)
           xsh.Screen.Send("check_error:" + count0)
           xsh.Screen.Send(VbCr)
           xsh.Dialog.MsgBox("reboot:" +count0)
           xsh.Dialog.MsgBox("check route")
End Function


Sub Main

             dim j:j=2
             error(j)
             xsh.Screen.Send(" route  -ne ")


End Sub

' Function check2(kjl)
        ' check(kjl) = 2
        ' xsh.Screen.Send(" route  -ne | grep 0.0.0.0 | wc -l ")
        ' xsh.Screen.Send(VbCr)
        ' screenrow = xsh.Screen.CurrentRow
        ' data = xsh.Screen.Get(screenrow-1,1,screenrow-1,20)
        ' if CInt(Instr(1,data,"4",1)) = "1"  Then
            ' check(kjl) = 0

        ' End If
' end function

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-24 00:38
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    这段代码的问题在于 error 函数的返回值。在 VBA 中,函数的返回值应该是一个数字或字符串,而不是一个变量。在这个例子中,你尝试返回一个整数(count0),但在调用 error 函数时,它实际上是被传递给 error 函数的参数。

    为了解决这个问题,你需要将 error 函数修改为:

    Function error(count0 As Integer)
        xsh.Screen.Send("check_error:" & count0)
        xsh.Screen.Send(VbCr)
        xsh.Dialog.MsgBox("reboot:" & count0)
        xsh.Dialog.MsgBox("check route")
    End Function
    

    然后,在你的主函数中,你应该使用 error 函数来获取结果:

    Sub Main
        Dim j: j = 2
        error(j)
        xsh.Screen.Send(" route -ne ")
    End Sub
    

    现在,当你运行这个脚本时,你应该能看到正确的输出。

    评论

报告相同问题?