Guy’s Scripting Ezine 117 – Troubleshooting VBScripts
♣ This Week’s SecretThis Week’s Mission is to pass on my ‘soft’ troubleshooting secrets. Here follows a list of seven unusual, even zany tips, these are strategies that you are unlikely to find in a textbook, but they offer an insight into my approach to problem solving. You could regard these strategies as inspiration for that moment when, after researching the error code number you still cannot find the answer. Now I realize that this list is not exhaustive, and my greatest joy would be if you would write in with your pet troubleshooting method. Seven Troubleshooting Strategies1) Golden Rule – Break your script into sections 4) If you are still stuck try a parallel approach 1) Golden Rule – Break your script into sectionsWhen I get a request for assistance with a VBScript, I often reply with the sentence: ‘Breakdown your script into its simplest components, get each command working in isolation, only then bolt the sections back together’. In my own scripts you may see traces of troubleshooting sections in the form of extra WSCript.echo messages. Sometimes I forget to remove them after testing the script, on other occasions I deliberately leave the WSCript.echo statement, just to alert you that VBScript has performed an action. The reason this strategy works is because you simultaneously build on success while narrowing down the search area for the fault. 2) Play the numbers game.Start solving VBScript errors by playing the numbers game. Rule 1) Trace the line numbers of the error. While you play the numbers game, pretend you are Sherlock Holmes searching for clues. Look for patterns. Take these two error messages 800708CA and 800A01F4; with just a glance at 800708CA I can tell this is an operating system problem, the clue is that ‘7’ in position 4. Notice how in the second hex number, 800708CA, we have an ‘A’ in position 4, thus indicating a syntax error. Further research indicates 800708CA means network connection does not exist, whereas 0800A01F4 means variable undefined. Incidentally, the underlying problem was trying to remove a network drive that did not exist. Get a good script editor. When you are troubleshooting, you need every advantage that you can get, thus a script editor will help by displaying the line numbers. The advantage is that when get a WSH error message you won’t have to count down to line 81 or where ever the message directs you. The better script editors also color code the commands, as a result you can often see a sudden change to red letters where you make a typo. As a bonus good script editors give you a context sensitive library of commands, which extends your scripting vocabulary. These days,my choice of script editor is OnScript. 3) Try a Walk-ThroughIt is amazing how often a manual walk-though of the task sheds extra light on a scripting problem. In particular, watch out for steps that are missing in the script. For example, pressing the OK button in a dialog box requires the VBScript command: obj.SetInfo. Following this theme, as you step through the task manually, observe how the default radio buttons are set. Another advantage of a walk-through is that may reveal that what you want to achieve cannot be done with a VBScript. Trust me, I have a whole folder full of readers’ plans for mission impossible. Many plans sound plausible until you try a walk-through. For example, I had a request to add a photograph to each user’s property sheet. Could I kindly help with a script. It seemed a nice idea until a walk-through in Active Directory Users and Computers exposed that there is no way of adding a user’s photograph. It also struck me that even if the script could magically achieve the mission, then how would you see the photo? 4) If you are still stuck try a parallel approach4a) Suppose that your mission is to map a network drive, but the script just won’t work. Instead of going around in circles, try mapping a printer. If that also fails, look for a common cause, for instance, the fault maybe because you are created an environmental object instead of a network object. By trying a parallel approach you can isolate the error. 4b) Here is another example, you are trying write to a file; but it fails, why not try to read from a file instead? This will prompt you to re-examine the Const statement and also to check that folder\file referenced in the script, is where you think it is. 4c) Cannot run Excel? Try to run Notepad instead, if that works it could mean that Excel is not installed. 4d) Seek similar examples on the internet. Leave a request in your favourite forum. My hidden message with this approach is when the parallel command works, you are at the start of a winning roll of the VBScript dice. What I find is that when I get even a small success, then my confidence grows and what was a difficult problem, suddenly becomes a cinch. Don’t underestimate the power of positive thinking. 5) Change of SceneryPerhaps what you need to solve the problem is sharper focus, or greater attention to detail. In this case, break out of that terrible loop where you go around in circles. Print out your script, but take it to another room where you read each line carefully. Don’t ask me why, but it works for me. A psychologist may say that I associate the dinning room with concentrating on fine detail. I repeat that when it comes to troubleshooting getting into a positive frame of mind is as important as technical know-how. Thinking positively opens up the mind to alternative avenues, for example, leave a question in a forum, or email-a-friend. To fix a script that’s not working, you need to develop the ‘can do’, or ‘I can walk on water mentality’. Let me play devils advocate for a minute, if you are in a bad mood, then common sense dictates that this negative attitude will sap your problem solving abilities. Blame someone. I don’t like this idea at all. However, my friend ‘Mad’ Mick swears that sticking pins in cabbage patch doll labelled Bill Gates, fires up his brain and solves the problem. Physical out bursts do not work for me, but if punching the door, or kicking the wall makes you feel better and gets you into problem solving state, then who am I to judge. Incidentally, this indicates I am willing to publish tips even if they don’t work for me. Guy Recommends: Tools4ever’s UMRA |



