Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop a script from continuing

Status
Not open for further replies.

ter79

IS-IT--Management
Jul 11, 2001
106
US
I have the following script for SQL DTS

dim filesys, filesys1newfolder, mydate,s,mymonth,r,t,f, x
x = 0
f = "C:\February\02-12-2003\bsusa.txt"
set filesys1=CreateObject("Scripting.FileSystemObject")
If Not filesys1.FileExists(f) Then
MsgBox ("A file '" & f & "' does not exist")
x=1
goto exit
Else
MsgBox ("A file '" & f & "' already exists")
End If
t = DatePart("m", Now)
mymonth = MonthName( t , False )
myDate = FormatDateTime(Now, vbshortdate)
'Msgbox mymonth
r = "C:\" & mymonth
set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(r) Then
newfolder = filesys.CreateFolder(r)
End If
s= r & "\" & Replace(mydate, "/","-")
'msgbox s
set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(s) Then
newfolder = filesys.CreateFolder(s)
MsgBox ("A new folder '" & newfolder & "' has been created")
Else
MsgBox ("A folder '" & s & "' already exists")
End If
Exit:
IF x = 0 then
Main = DTSTaskExecResult_Success
Else
Main = DTSTaskExecResult_Failure
End if

How can I get the script to stop from excuting when the file that is trying to find does not exist. The goto statement I found out does not work in VBScript like it does in VB

Any help is appreciated!
 
Try changing "goto exit" to "EndMyScript" (without the quotes). Then change

"Exit:
IF x = 0 then
Main = DTSTaskExecResult_Success
Else
Main = DTSTaskExecResult_Failure
End if"

to

"Sub EndMyScript
IF x = 0 then
Main = DTSTaskExecResult_Success
Else
Main = DTSTaskExecResult_Failure
End if
EndSub"


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top