Does WSH 5.7 have a "Go To" or equivalent Keyword?

Posted on 2009-02-18
Last Modified: 2012-05-06
Magnanimous Gurus,
I'm trying to write some batch files with WSH.  But WSH seems to choke on the "Go To" Keyword.   Is this by design?   What are my alternative solutions?

Many thanks,

Question by:tcalbaz
    LVL 12

    Expert Comment

    There is a
    On Error GoTo xxx
    otherwise, no.
    See this link
    Link for GoTo comments
    LVL 65

    Accepted Solution

    Hi, VBScript does not support GoTo statements, but you can use Sub procedures in place of your "blocks"

    For example, if you had

    if exist c:\myfile.txt goto DoesExist else DoesNotExist
    echo File does exist
    goto End
    echo File does not exist
    goto End
    echo Finished

    That could translate to the following code


    Set objFSO = CreateObject("Scripting.FileSystemObject")
    strFile = "C:\myfile.txt"
    If objFSO.FileExists(strFile) = True Then
    	Call DoesExist()
    	Call EndScript()
    	Call DoesNotExist()
    	Call EndScript()
    End If
    Sub DoesExist()
    	WScript.Echo "File does exist."
    End Sub
    Sub DoesNotExist()
    	WScript.Echo "File does not exist."
    End Sub
    Sub EndScript()
    	WScript.Echo "Script has finished."
    End Sub

    Open in new window

    LVL 1

    Author Closing Comment

    Thanks for the answer and the alternative solution!
    LVL 65

    Expert Comment

    No problem. Thanks for the grade.



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This script will sweep a range of IP addresses (class c only, and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now