Results 1 to 3 of 3

Thread: VBS

  1. #1
    Join Date
    Dec 1969

    Default VBS

    Hello gain<BR>I have this case or question. I have VBS batch job handle billing function. It has a big main sub and some class includes. This function is very critical, I am working on error handling, the main sub (1200 line of code) inside the main sub we call a lot of stored procedure and we do a lot of calculation. The error handle I design like the following I Just want to take you opinion if that will dose what I need. <BR>What I need whenever and Error occur to Rollback everything (very much like the program never run) other wise to commit the job. <BR>Here What I did.<BR><BR>On Error resume next<BR>dbConnection.Open strConnectionString<BR>dbConnection.BeginTrans<BR> <BR>And at the end of the sub<BR><BR>If Err.Number = 0 Then<BR> cnnConnection.CommitTrans<BR> Else<BR> dbConnection.RollbackTrans<BR> dbConnection.Close<BR> Set dbConnection = Nothing<BR> <BR> End If <BR><BR>I try not to use any <BR>Err.clear or On Error GoTo 0 to make sure I catch any Error. <BR><BR>Please advise <BR>

  2. #2
    Join Date
    Dec 1969

    Default Becareful with that.

    Errors that occur in functions may not be handled by that.<BR><BR>It&#039;s something about the main file having On Error Resume Next, but the functions themselves don&#039;t. No error is triggered and/or the function doesn&#039;t return a value.<BR><BR>Just make sure you test things out yourself. Put in dummy code to FORCE errors and test your error handler.

  3. #3
    Join Date
    Dec 1969

    Default RE: VBS

    I devised a system to handle error handling when using VBS Scripts that I think is pretty clever. <BR><BR>I write the script and test it and after I do so, I split the script up into multiple .VBS files. Some files may only have one function, some have a few. <BR><BR>I include all of these scripts in the same job in a .WSH file. WSH Files execute the scripts asynchronously, as soon as one is done the next starts. <BR><BR>You can also include code directly inside the WSH, so I wrote a little function that I dubbed IntegrityCheck. Basically, it works like this: <BR><BR>In my WSH file I put this code BEFORE i include any scripts:<BR><BR> &#060;script language="VBScript"&#062;<BR> RunCheck = True<BR> &#060;/script&#062;<BR><BR>And at the TOP of every script I call the IntegrityCheck subroutine. At the BOTTOM of every script, I set RunCheck = True<BR><BR>The sub checks to see if RunCheck is True. If it is, then it sets RunCheck = False. <BR><BR>If RunCheck = True then it means that the previous script ran without error, that it made it to the very bottom without incident. If RunCheck = False that means that the previous script had an error somewhere, and that it never executed the last line to turn RunCheck = True. <BR><BR>After all the scripts are listed, I include a call to the IntegrityCheck sub as a code block directly within the WSH. <BR><BR>This system has worked for me without incident. It&#039;s basically fool proof, because any error will stop execution of the script that generated the error and it will move on to the next script. As a parameter in my IntegrityCheck sub I tell it which script had the error, then I use a Case statement to determine which operatiosn to take to "roll back" the error. <BR><BR>It&#039;s the best error handling solution I could come up with for VBS since it has basically ZERO built in ability to do so.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts