Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-02-18
4
Medium Priority
?
1,493 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
0
Comment
Question by:tcalbaz
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Krys_K
ID: 23675941
Hi
 
There is a
On Error GoTo xxx
 
otherwise, no.
See this link
Link for GoTo comments
 
Regards
Krystian
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 23675975
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

0
 
LVL 1

Author Closing Comment

by:tcalbaz
ID: 31548524
Thanks for the answer and the alternative solution!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 23677970
No problem. Thanks for the grade.

Regards,

Rob.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 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