Forum Discussion

jyothi_priya's avatar
jyothi_priya
Contributor
14 years ago

How to quit from a paticular script

Hi,



function x(a)

    If a = 2 then

        msgbox "Hi"

    else

        nsgbox "Fail"

        wscript.quit        'This is throwing error as wscript object is required

    end if 

end function



Sub a

    call x(1)

    msgbox "Pass"

end sub



sub b

    call x(2)

    msgbox "Pass"

end sub


Sub Main

    call a

    call b

End Sub


In the above sample example, sub routine a fails. so it should throw a message Fail and stop executing that particular sub routine. It should then execute sub routine b.

Using wscript.quit is throwing error that wscript object is required.

Can anyone tell me how to use wscript.quit?
  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi Jyothi,


    Using wscript.quit is throwing error that wscript object is required.

    Can anyone tell me how to use wscript.quit?


    TestComplete doesn't allow calling this method as it contradicts our product's internal organization.


    As a workaround, I recommend that you modify your script in the following way:



    function x(a)

        If a = 2 then

            msgbox "Hi"

        else

            msgbox "Fail"

            exit function ' <- this will resolve your problem

        end if

    end function



    Sub a

        call x(1)

        msgbox "Pass"

    end sub



    sub b

        call x(2)

        msgbox "Pass"

    end sub



    Sub Main

        call a

        call b

    End Sub

  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi Jyothi,


    In this case, I recommend that you use the On Error Resume Next statement:



    Function x(a)

        If a = 2 then

            msgbox "Hi"

        else

            msgbox "Fail"

            err.raise

        end if

    End Function



    Sub a

        call x(1)

         if x <> 0 then

           exit sub

         end if

        msgbox "Pass"

    End Sub



    Sub b

        call x(2)

        msgbox "Pass"

    End Sub



    Sub Main

        On Error Resume Next

        call a

        On Error Goto 0

        call b

    End Sub

  • Exit function only exits from that particular function and it returns back to the subroutine a and will execute next instruction in the sub routine. I do not want to return to the sub routine. It should display the message Fail and should stop execution of sub routine a without returning to it and then should move on to execute sub routine b. Thats what my requirement is. How can we do this?