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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handling in a sub to set Main = DTSTaskExecResult_Failure

Status
Not open for further replies.

JStandard

Programmer
Mar 15, 2005
22
US
Greetings,

I have a DTS with a VBScript component that has a Function Main() and a Sub Test() in it.

Is there any way I can call the sub within main and using error handling, set Main = DTSTaskExecResult_Failure?

Ex.

Code:
Sub TestArray(aTest)
  On Error Resume Next
  aTest(1,2) = "This is out of bounds"
  If err.number <> 0 Then
    Main = DTSTaskExecResult_Failure 
    ' Ideally DTS would end right here because of failure
  End If
  On Error Goto 0
End Sub

Function Main()
  Dim aTest(1,1), bTest(1,1)
  TestArray aTest
  
  ' Other Stuff
  TestArray bTest

  Main = DTSTaskExecResult_Success
End Function


So in the above example, I am basically attempting to halt the DTS when I encountered an error in a specific part of the Sub TestArray.

This would allow me to be able to use this function at multiple points within the code, without having to encapsulate it in an error handling block each time I want to call the function.

To put it in Java terms, if I am calling a method from within a method, no matter where I am, I can use the System.Out.Exit() to cause the application to end prematurely. I am looking for analagous functionality in DTS/VBScript.

Is there anyway I can accomplish having the Sub cause the Main function to fail in a VBScript DTS Task? Is there a better way to do this?

Any help is much appreciated.

Thanks kindly,
- Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top