我在窗体模块写了一串代码。
其中有调用到类模块中的一个函数。
其函数中判定为错误。则终止所有执行。
就好比在窗体模块中exit sub的功能一样。
我不只是是要停止类模块中那一个函数。
而是这个程序停止。也不是退出

解决方案 »

  1.   


    '光看文字也许不知道我在说什么,简单笔画一下。
    Private Sub Command1_Click()
    Dim mScript As New CScript
    list.additem "你好"
    call mScript.comout ("all")
    ...
    ...
    msgbox "结束"
    end sub
    '类模块代码
    Public Function comout(ByVal com As String) As String
    if com="all" then
    msgbox "完成"
    else
    msgbox "失败"
    [exit sub]    '我就是想完成这句的功能,但是我这个是报错的!
                   '我想到这里的话这个程序停止,但不是退出
    end Function 
      

  2.   

    挂起什么的我看不行,也行不会用吧。
    或者说弄一个按钮,点击将可以终止正在运行的程序。
    就好比exit sub能让过程停止。只是现在我要这个exit sub不是在运行的那个过程中 
    而是在另一个过程中的、
    能实现吗,只要是我描述的功能就行了
      

  3.   

    把任务挂起。在类中没有EXIT SUB.
      

  4.   

    不明白楼主想表达什么……
    1.貌似也不是挂起进程
    2.在public function中用exit sub肯定是错的,只能exit function
    3.在msgbox的时候就已经挂起,程序也暂停了
    4.如果是要判断返回值,你就应该public function xxx as boolean,然后在主程序判断
      

  5.   

    Public Function comout(ByVal com As String) As String
        if com="all" then
            'msgbox "完成"
            comout="OK"
        else
            'msgbox "失败"
            comout="FAIL"
        end if
    end FunctionPrivate Sub Command1_Click()
        Dim mScript As New CScript
        list.additem "你好"
        if mScript.comout ("all")="OK" then
            '正确,继续执行接下来的代码
        else
            '不正确,执行提示错误之类的代码
            msgbox "XXXXXX"
            exit sub
        end if
        ...
        ...
        msgbox "结束"
    end sub直接使用返回值不就行了么.另外,代码加缩进是个好习惯,按TAB键.
      

  6.   

    这样不行,如果没有好的办法,我只能加end关闭程序了。
      

  7.   

    Private Sub Command1_Click()
      Dim mScript As New CScript
        If mScript.comout("all") = False Then
          MsgBox "错误"
          Unload Me
        End If
    End Sub
    '类模块代码
    Public Function comout(ByVal com As String) As Boolean
      ……
      ……
      If com <> "xxx" Then Exit Function
      '你的脚本代码
      ……
      ……
      comout = True
    End Function
      

  8.   

    ScriptControl控件的Timeout属性很有用:)
      

  9.   

    能具体一点吗,我昨天看了一天。
    但是发现script_control.后面没有成员出来。
    我就在想Set script_control = CreateObject("MSScriptControl.ScriptControl")
    与拖控件的区别了