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

VBScript Syntax Checker

Status
Not open for further replies.

dean12

MIS
Joined
Oct 23, 2001
Messages
273
Location
US
I'm looking for a tool that will take my VBScript and check it for syntax errors. Specifically, I need to know where I have referenced constants and then failed to either include the "Const" statement or have made a typo.

I don't want to execute the script and debug because that only seems to debug the parts that are actually run.

Appreciate any recommendations.
 
I'm not sure of a tool that will simply check your script for this, but PrimalScript 4.1 (scripting editor), has a built in syntax checker as you type and many other useful features.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Specifically, I need to know where I have referenced constants and then failed to either include the "Const" statement"

I don't understand this? Could you give an example of referencing a constant without first declaring it as a constant?

"or have made a typo."

If you mean a typo in a variable name, then put Option Explicit at the top of your script. It will catch undeclared variables even in portions of the code that never actually execute.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Here's a bit of VBScript:

-------------------------------------------------------

Option Explicit
Const strfPage = "Page_No"
Const strgCenter = "Center Page"

If UICenter.Fields(strfPage).Value = strgCenter then
UICenter.Fields(strtPage).Value = 3
end if

-------------------------------------------------------

Did I make a mistake?

Oops, I can't execute this script. It requires that it be run inside a rather complex environment. And if I understand things correctly, even if I could execute this script the error would not be detected until it tried to execute the assignment statement.

I just want something that will tell me that I have referenced an undefined variable called "strtPage".

 
Primalscript should catch the error and if you tried to run the script it would not run at all and it would tell you that you had used an undeclared variable.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 

Option Explicit

Sub routine1
Const xxx = "DEAN"
abc (rrr) = 1
End Sub
--------------------------------------------------------

That's the whole script. Primal Script 4.1 doesn't detect this error. I run the script and no error I guess because the "sub" is never invoked. sub "routine1" is going to be called from somewhere else.


 
Well then I'd say either you are SOL or you need to read up on writing recursive descent parsers.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
But actually isn't what I'm seeing the norm for VBScript? It's all late binding or execution time evaluation so who's to know until the statement is executed.

Option Explicit
call sub1
sub sub1
if 1 = 2 then abc = 3
end sub


I don't think you will get an error from anything. If I tell PrimalScript this is a VBScript file, it will run it all day long - no problems. Forget the logic error of 1 = 2, clearly "abc" is not declared anywhere.
 
In the end, the script is simply doing what it was told to do. It is still the scripters responsibility to ensure variables (if used) are defined, that the logic makes sense, and to try to debug it by testing as many possible scenarios against it as possible.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Oh I agree. It's just that I hate that uncomfortable feeling that somewhere in the last 1,200 lines of code there is a typo waiting to bite.
 
I think this is a good example of the fact that computers don't really allow us to work smarter they just improve the speed, complexity, and scale at which we can make mistakes!

To error is human, to really F***K something up requires a computer! [pc3]

[thumbsup]

Thanks

John Fuhrman
Titan Global Services
 
This kind of stuff reminds me of running naked through the forest. Lots of little pointy things you can get snagged on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top