Login | |
|
 |
RE: Error Message - 3/28/2007 1:06:21 AM
|
|
 |
|
| |
ehvbs
Posts: 2106
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
|
Hi morpheus83uk, iErr = Err.Number This will store the current value of Err.Number in iErr. iErr will either be 0 (no error in the line(s) before) or not (there was an error) On Error GoTo 0 This will enable the standard error handling (abort program, report error info) and clear the Err object If iErr <> 0 Then This branch will be entered when iErr is not 0; meaning that there was an error before (the info about this error is lost because of the OEG0) ... objFile.WriteLine "Script Error: " & Now No problem writing this info to the log file ... objFile.WriteLine "Error: " & Err.Number Writing the info from the cleared Err object to the log file - pretty senseless ... Considering the links to the discussion of VBScript Error Handling http://www.microsoft.com/technet/scriptcenter/guide/sas_vbs_lfia.mspx?mfr=true "Requires extra work on the part of the script writer. The script writer must anticipate where errors are likely to occur and then include the code to respond appropriately." http://www.microsoft.com/technet/scriptcenter/resources/begin/ss0506.mspx "The way the Err object works is that, when an error occurs, the Err object contains all the information about that error. Think of the Err object as a basket. We’ve put something into the basket. But the next time we go through our For loop to check for the next date in the array, our basket is still full, which means the Err object still contains the error from last time. So you always want to “empty the basket,” or clear the Err object, before you run another method, otherwise you might end up with a full basket when you’re expecting an empty one. And just in case our wonderful basket metaphor wasn’t crystal clear, look what happens when we don’t call Err.Clear" http://www.microsoft.com/technet/scriptcenter/resources/scriptshop/shop1205.mspx "VBScript error-handling requires two elements that work together. You can turn it on with the On Error Resume Next statement and turn it off with On Error GoTo 0. When it's turned on you can use the built-in Err object to get some information on what kind of error occurred." and the sample code from: http://www.visualbasicscript.com/m_43706/tm.htm nErrNumber = Err.Number ' Copy the Err info (cleared by OEG0) to sErrDescription = Err.Description ' two simple variables On Error Goto 0 If 0 <> nErrNumber Then objFile.WriteLine nErrNumber nothing of the above should surprise you. So please answer: I take it that this just means that the scripts has completed without any errors? yourself. ehvbs
|
|
| |
|
|
|
 |
RE: Error Message - 3/31/2007 5:06:27 PM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
Technet is very explicit in it's explanation of Err-handling: quote: The VBScript Err object is a unique kind of object that you don't have to create or get: it is instantiated automatically by VBScript when the script runs. Err has three properties that are generally useful: Number (the default property) - integer Source - string Description - string It also has two other properties that you can ignore unless the application in question has created custom errors and tied them to help topics: HelpFile HelpContext Err also provides two methods: Clear Raise(lngNumber, strSource, strDescription)
_____________________________
For more information, please see the "Read me First" topic. http://www.visualbasicscript.com
|
|
| |
|
|
|
 |
RE: Error Message - 4/1/2007 12:10:23 AM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
Your code looks as correct as you like.... Here are some pointers: 1) make sure it works! 2) make sure you know where what is (in case of troubleshooting) 3) comment comment comment prior to any important piece of actioncode. Comment as much as that a second objective person can understand your script.
_____________________________
For more information, please see the "Read me First" topic. http://www.visualbasicscript.com
|
|
| |
|
|
|
 |
RE: Error Message - 4/9/2007 1:18:33 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
I think enough time has passed and you have probably made enough changes to your code that it would be good to have a quick reset. COuld you post the actual code that you are running along with a clear description of theproblem that you are having?
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Error Message - 4/9/2007 1:35:58 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
Part of the problem is that you are only checking the value of Err.Number at the very end of your script. Every action that could generate an error resets Err.Number to the value of the error. This means that if you have an action that fails and immediately after that you have an action that is succeeds, the Err.Number will be 0 because it only reports the last action's error. In your case you also open the text file for writing right before you try to write out the Err.Number. So as long as the script can open the file it will always report an Err.Number of 0. What you need to do is to check the value of Err.Number after every action that you think might fail and write out to the log file at that point in the script not at the end.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Error Message - 4/9/2007 3:16:23 AM
|
| | | |