Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Turning on options explicit

Reply
 
Old 11-21-2008   #1 (permalink)
BrianB


 
 

Turning on options explicit

I've inherited a several thousand line vbs script. Options Explicit is
commented out in it. I've found one mistyped variable and I'm sure there are
more. Is there a way to uncomment it and do a syntax check on the code? So
far I can just get it to point out undeclared variables when it hits them
during execution.

Brian



My System SpecsSystem Spec
Old 11-21-2008   #2 (permalink)
mr_unreliable


 
 

Re: Turning on options explicit

BrianB wrote:
Quote:

> I've inherited a several thousand line vbs script. Options Explicit is
> commented out in it. I've found one mistyped variable and I'm sure there are
> more. Is there a way to uncomment it and do a syntax check on the code? So
> far I can just get it to point out undeclared variables when it hits them
> during execution.
>
> Brian
>
hi Brian, unfortunately, that's the way it works.

Even visual basic (classic) will let you type in anything,
and not catch it until it executes. (Not experienced with
vb.net).

I have one suggestion, not easy, but with "thousands of
lines of code", the extra effort may be worth it.

Here goes: get yourself an programmer's editor with syntax
highlighting, which allows for you to input the language
syntax. (For example, scintilla, or EditPlus). It will
most likely come with a vbs syntax file (or at least a
visual basic syntax file). The syntax file will come with
lists of language verbs (do, stop, etc), and will include
instructions for "colorizing" various language elements
(strings, constants).

What I suggest is to set up another category, lets call it
"declared variables". In this category you place all
the variable names that are dimensioned (i.e., declared).
You also set up your colorization rules to highlight the
declared variables. This leaves the UN-colorized variables
as un-declared (note that the language elements are generally
colorized).

This sounds like a sure way to get eye-strain, looking for
un-colorized variables. But if you set the default color
to something noticeable then that might make the un-declared
variables stand out more.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)

p.s. you might wish to first check with some of the "high
priced" editors (like Sapien PrimalScript) to see if they
will auto-magically detect any undeclared variables
(without going into execution).


My System SpecsSystem Spec
Old 11-21-2008   #3 (permalink)
David Kerber


 
 

Re: Turning on options explicit

In article <e2ng$AATJHA.4456@xxxxxx>,
kindlyReplyToNewsgroup@xxxxxx says...
Quote:

> BrianB wrote:
Quote:

> > I've inherited a several thousand line vbs script. Options Explicit is
> > commented out in it. I've found one mistyped variable and I'm sure there are
> > more. Is there a way to uncomment it and do a syntax check on the code? So
> > far I can just get it to point out undeclared variables when it hits them
> > during execution.
> >
> > Brian
> >
>
> hi Brian, unfortunately, that's the way it works.
>
> Even visual basic (classic) will let you type in anything,
> and not catch it until it executes. (Not experienced with
> vb.net).
If you set "Option Explicit" (which is not the default, AFAIK), VB
classic will catch undeclared variables at compile time, rather than
waiting until runtime.

I wonder if importing his big vbscript into a VB IDE might compile well
enough to catch the undeclared var's?

.....

--
/~\ The ASCII
\ / Ribbon Campaign
X Against HTML
/ \ Email!

Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).

My System SpecsSystem Spec
Old 11-21-2008   #4 (permalink)
MikeB


 
 

Re: Turning on options explicit


"David Kerber" <ns_dkerber@xxxxxx_WarrenRogersAssociates.com> wrote in message
news:MPG.2390cd92b60c033b989cce@xxxxxx
Quote:

> In article <e2ng$AATJHA.4456@xxxxxx>,
> kindlyReplyToNewsgroup@xxxxxx says...
Quote:

>> BrianB wrote:
Quote:

>> > I've inherited a several thousand line vbs script. Options Explicit is
>> > commented out in it. I've found one mistyped variable and I'm sure there
>> > are
>> > more. Is there a way to uncomment it and do a syntax check on the code? So
>> > far I can just get it to point out undeclared variables when it hits them
>> > during execution.
>> >
>> > Brian
>> >
>>
>> hi Brian, unfortunately, that's the way it works.
>>
>> Even visual basic (classic) will let you type in anything,
>> and not catch it until it executes. (Not experienced with
>> vb.net).
>
> If you set "Option Explicit" (which is not the default, AFAIK), VB
> classic will catch undeclared variables at compile time, rather than
> waiting until runtime.
>
> I wonder if importing his big vbscript into a VB IDE might compile well
> enough to catch the undeclared var's?
It's OK for VB6 for sure and I use VBA editor to prototype Scripts as
well....
Quote:

> ....
>
> --
> /~\ The ASCII
> \ / Ribbon Campaign
> X Against HTML
> / \ Email!
>
> Remove the ns_ from if replying by e-mail (but keep posts in the
> newsgroups if possible).
>

My System SpecsSystem Spec
Old 11-21-2008   #5 (permalink)
BrianB


 
 

Re: Turning on options explicit

"MikeB" <m.byerleyATVerizonDottieNettie> wrote in message
news:%23Z1n2GCTJHA.1160@xxxxxx
Quote:

>
> "David Kerber" <ns_dkerber@xxxxxx_WarrenRogersAssociates.com> wrote in message
> news:MPG.2390cd92b60c033b989cce@xxxxxx
Quote:

>> In article <e2ng$AATJHA.4456@xxxxxx>,
>> kindlyReplyToNewsgroup@xxxxxx says...
Quote:

>>> BrianB wrote:
>>> > I've inherited a several thousand line vbs script. Options Explicit is
>>> > commented out in it. I've found one mistyped variable and I'm sure
>>> > there are
>>> > more. Is there a way to uncomment it and do a syntax check on the
>>> > code? So
>>> > far I can just get it to point out undeclared variables when it hits
>>> > them
>>> > during execution.
>>> >
>>> > Brian
>>> >
>>>
>>> hi Brian, unfortunately, that's the way it works.
>>>
>>> Even visual basic (classic) will let you type in anything,
>>> and not catch it until it executes. (Not experienced with
>>> vb.net).
>>
>> If you set "Option Explicit" (which is not the default, AFAIK), VB
>> classic will catch undeclared variables at compile time, rather than
>> waiting until runtime.
>>
>> I wonder if importing his big vbscript into a VB IDE might compile well
>> enough to catch the undeclared var's?
>
> It's OK for VB6 for sure and I use VBA editor to prototype Scripts as
> well....
>
Quote:

>> ....
>>
>> --
>> /~\ The ASCII
>> \ / Ribbon Campaign
>> X Against HTML
>> / \ Email!
>>
>> Remove the ns_ from if replying by e-mail (but keep posts in the
>> newsgroups if possible).
>>
>
Thank you all. I'll give it a try.

Brian


My System SpecsSystem Spec
Old 11-21-2008   #6 (permalink)
mayayana


 
 

Re: Turning on options explicit

>
Quote:

> What I suggest is to set up another category, lets call it
> "declared variables". In this category you place all
> the variable names that are dimensioned (i.e., declared).
> You also set up your colorization rules to highlight the
> declared variables. This leaves the UN-colorized variables
> as un-declared (note that the language elements are generally
> colorized).
>
WEB-ED Editor
www.jsware.net/jsware/webed.php5

Colorizes declared variables automatically.


My System SpecsSystem Spec
Old 11-24-2008   #7 (permalink)
Al Dunbar


 
 

Re: Turning on options explicit


"ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
news:4927477e$0$30236$9b4e6d93@xxxxxx-online.net...
Quote:

> BrianB schrieb:
Quote:

>> I've inherited a several thousand line vbs script. Options Explicit is
>> commented out in it. I've found one mistyped variable and I'm sure there
>> are more. Is there a way to uncomment it and do a syntax check on the
>> code? So far I can just get it to point out undeclared variables when it
>> hits them during execution.
>>
>> Brian
> (1) 'Compiling' the code in VBE won't catch typos in Sub/Function
> names
> (2) Static code analysis based on lists of allowed words (reserved
> words, names of known Subs/Functions, names of Dim'ed variables)
> is a lot of work and error-prone
> (3) To gain confidence in the script, you'll have to test it anyway
To gain confidence in the script, you will have to eventually *understand*
it, as well.

mayayana suggested that the WEB-ED editor could help you differentiate
between declared and undeclared variables. That might be of great help in
the task. But if the missing declarations hide some logical error, I do not
think you can expect a tool to automatically correct it.

/Al


My System SpecsSystem Spec
Old 11-29-2008   #8 (permalink)
Reventlov


 
 

Re: Turning on options explicit

Il giorno Mon, 24 Nov 2008 21:30:39 -0700, "Al Dunbar" <alandrub@xxxxxx> ha scritto:
Quote:

>mayayana suggested that the WEB-ED editor could help you differentiate
>between declared and undeclared variables. That might be of great help in
>the task. But if the missing declarations hide some logical error, I do not
>think you can expect a tool to automatically correct it.
I read (23 years ago) of a program for the Commodore 64 which parsed the code and built a
cross reference of the variables and the lines where they were used.
If a variable is used only once then there should be an error.
Anyone willing to enjoy writing this for vbscript?

--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--
My System SpecsSystem Spec
Old 11-29-2008   #9 (permalink)
mayayana


 
 

Re: Turning on options explicit

Quote:

> I read (23 years ago) of a program for the Commodore 64 which parsed the
code and built a
Quote:

> cross reference of the variables and the lines where they were used.
> If a variable is used only once then there should be an error.
> Anyone willing to enjoy writing this for vbscript?
I've never seen or written a VBScript that needed such
an elaborate tool. Just running it and checking error line
numbers seems to work fine for me. Maybe others have a
different way of doing things. For myself, I find that the *really*
hard part is familiarizing myself with the code. For that,
color syntax highlighting is very helpful, but I still have to
work out the logic. Until I have the whole layout and
functionality of a script clear in my mind -- whether it's my
code or someone else's -- I can't do much of anything useful
with it.


My System SpecsSystem Spec
Old 11-29-2008   #10 (permalink)
Al Dunbar


 
 

Re: Turning on options explicit


"mayayana" <mayaXXyana@xxxxxx> wrote in message
news:epS7vwjUJHA.1164@xxxxxx
Quote:

>
Quote:

>> I read (23 years ago) of a program for the Commodore 64 which parsed the
> code and built a
Quote:

>> cross reference of the variables and the lines where they were used.
>> If a variable is used only once then there should be an error.
That would, indeed, seem to indicate a logic error of some kind, however
simply knowing this will still require the scripter to determine the cause
of the problem: was a variable name spelt incorrectly, for example? But this
will only flag those errors where the incorrect spelling of one variable is
*not* the same as the correct spelling of another - an error that is often
more difficult to deal with.

Another way this can happen is when chunks of code are deleted...

There are so many other possible logic errors that cannot be found through
mechanical means, that such a limited tool would not seem to me to be worth
the cost to develop.

But, all this said, having a single instance of one variable name may not
always be an error. Consider that the variable might be defined in a script
snippet instantiated in code generated dynamically with EXECUTEGLOBAL.
Quote:
Quote:

>> Anyone willing to enjoy writing this for vbscript?
>
> I've never seen or written a VBScript that needed such
> an elaborate tool. Just running it and checking error line
> numbers seems to work fine for me. Maybe others have a
> different way of doing things. For myself, I find that the *really*
> hard part is familiarizing myself with the code. For that,
> color syntax highlighting is very helpful, but I still have to
> work out the logic. Until I have the whole layout and
> functionality of a script clear in my mind -- whether it's my
> code or someone else's -- I can't do much of anything useful
> with it.
Colorizing editors are useful, but if one also writes one's code using an
editor having intellisense capabilities, that is likely to prevent some
errors up front, as it will be aware of the number and names of parameters
in function calls, and possibly match code block elements. That, along with
adopting a consistent approach to coding standards wil, I think, get one
much farther along than any single-function code analysis tool will be able
to.

/Al


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Enabling ECN (Explicit Congestion Notification) in Vista Vista networking & sharing
How do you Enable ECN (Explicit Congestion Notification) Vista General
implicit/explicit data type conversion? PowerShell
RE: Option Explicit PowerShell
OPTION EXPLICIT PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46