We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

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

Medium Priority
1,530 Views
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,

Ted
Comment
Watch Question

Commented:
Hi
 
There is a
On Error GoTo xxx
 
otherwise, no.
See this link
Link for GoTo comments
 
Regards
Krystian
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
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
:DoesExist
echo File does exist
goto End
:DoesNotExist
echo File does not exist
goto End
:end
echo Finished

That could translate to the following code

Regards,

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFile = "C:\myfile.txt"
If objFSO.FileExists(strFile) = True Then
	Call DoesExist()
	Call EndScript()
Else
	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."
	WScript.Quit
End Sub

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks for the answer and the alternative solution!
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
No problem. Thanks for the grade.

Regards,

Rob.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.