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 - New to VBS..

Reply
 
Old 02-25-2009   #1 (permalink)
nickjax01


 
 

New to VBS..

HI everyone...

I am just starting out learning VBS...so I'd appreciate any help with
this...

Is there a way in VBS to see each line as it executes? Similar to ECHO
ON in bat files, I'd like to see each line as it executes and the
values that are being set in the variables.

Thank you

My System SpecsSystem Spec
Old 02-25-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: New to VBS..


<nickjax01@xxxxxx> wrote in message
news:39861fd6-0c41-441b-89a1-bf551c24c5cc@xxxxxx
Quote:

> HI everyone...
>
> I am just starting out learning VBS...so I'd appreciate any help with
> this...
>
> Is there a way in VBS to see each line as it executes? Similar to ECHO
> ON in bat files, I'd like to see each line as it executes and the
> values that are being set in the variables.
>
> Thank you
There certainly is nothing builtin that does this, and I don't know of any
environment that helps. It could be possible to create a script that reads
lines from another a very simple script, echos each line, then executes it.
However, complications quickly arise when statements cannot be run in
isolation one line at a time. For example lines continued on several lines.
And For Each, If Then, Do Until and other loops would be impossible. Also, I
see no way to show the values of variables.

A quick try follows. First an example script that can be executed one line
at a time:
=======
Option Explicit

Dim lngValue1, lngValue2, lngValue3

lngValue1 = 3
lngValue2 = 5
lngValue3 = lngValue1 + lngValue3
Wscript.Echo lngValue3
=======
Then, if the above is saved in the file c:\Scripts\Example.vbs, the
following VBScript program will read each line, echo it to the console, and
execute each line:
=======
Option Explicit

Dim strScriptFile, objFSO, objFile, strLine

Const ForReading = 1

' Specify the VBScript program to run.
strScriptFile = "c:\Scripts\Example.vbs"

' Open the file.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strScriptFile, ForReading)

' Read each line of the file.
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
' Echo the line to the console.
Wscript.Echo strLine
' Run the line.
Execute strLine
Loop

' Clean up.
objFile.Close
=======
If run at a command prompt with cscript, the output would be:
==========
Option Explicit

Dim lngValue1, lngValue2, lngValue3

lngValue1 = 3
lngValue2 = 5
lngValue3 = lngValue1 + lngValue3
Wscript.Echo lngValue3
3
=========
However, I believe there are just too many complications to make this
workable. Maybe someone knows how to run VBScript programs in VB IDE, for
example.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 02-25-2009   #3 (permalink)
Al Dunbar


 
 

Re: New to VBS..


"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:ugSok95lJHA.1388@xxxxxx
Quote:

>
> <nickjax01@xxxxxx> wrote in message
> news:39861fd6-0c41-441b-89a1-bf551c24c5cc@xxxxxx
Quote:

>> HI everyone...
>>
>> I am just starting out learning VBS...so I'd appreciate any help with
>> this...
>>
>> Is there a way in VBS to see each line as it executes? Similar to ECHO
>> ON in bat files, I'd like to see each line as it executes and the
>> values that are being set in the variables.
>>
>> Thank you
>
> There certainly is nothing builtin that does this, and I don't know of any
> environment that helps. It could be possible to create a script that reads
> lines from another a very simple script, echos each line, then executes
> it. However, complications quickly arise when statements cannot be run in
> isolation one line at a time. For example lines continued on several
> lines. And For Each, If Then, Do Until and other loops would be
> impossible. Also, I see no way to show the values of variables.
>
> A quick try follows. First an example script that can be executed one line
> at a time:
> =======
> Option Explicit
>
> Dim lngValue1, lngValue2, lngValue3
>
> lngValue1 = 3
> lngValue2 = 5
> lngValue3 = lngValue1 + lngValue3
> Wscript.Echo lngValue3
> =======
> Then, if the above is saved in the file c:\Scripts\Example.vbs, the
> following VBScript program will read each line, echo it to the console,
> and execute each line:
> =======
> Option Explicit
>
> Dim strScriptFile, objFSO, objFile, strLine
>
> Const ForReading = 1
>
> ' Specify the VBScript program to run.
> strScriptFile = "c:\Scripts\Example.vbs"
>
> ' Open the file.
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile(strScriptFile, ForReading)
>
> ' Read each line of the file.
> Do Until objFile.AtEndOfStream
> strLine = objFile.ReadLine
> ' Echo the line to the console.
> Wscript.Echo strLine
> ' Run the line.
> Execute strLine
> Loop
>
> ' Clean up.
> objFile.Close
> =======
> If run at a command prompt with cscript, the output would be:
> ==========
> Option Explicit
>
> Dim lngValue1, lngValue2, lngValue3
>
> lngValue1 = 3
> lngValue2 = 5
> lngValue3 = lngValue1 + lngValue3
> Wscript.Echo lngValue3
> 3
> =========
> However, I believe there are just too many complications to make this
> workable. Maybe someone knows how to run VBScript programs in VB IDE, for
> example.
Third party IDE's exist, for example, PrimalScript from Sapien Technologies.
Not sure if any of these can be set to display the staement as it is being
executed, however, ECHO ON in batch files is an extremely limited debugging
tool, and it cannot display variable values unless you code it to do so.

/Al


My System SpecsSystem Spec
Old 02-26-2009   #4 (permalink)
Joe Fawcett


 
 

Re: New to VBS..

Or use a script debugger such as Visual Studio. Even the free versions can
do this I believe. You can then step through the code line by line.

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

"Al Dunbar" <alandrub@xxxxxx> wrote in message
news:%23wZYVP6lJHA.1288@xxxxxx
Quote:

>
> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
> message news:ugSok95lJHA.1388@xxxxxx
Quote:

>>
>> <nickjax01@xxxxxx> wrote in message
>> news:39861fd6-0c41-441b-89a1-bf551c24c5cc@xxxxxx
Quote:

>>> HI everyone...
>>>
>>> I am just starting out learning VBS...so I'd appreciate any help with
>>> this...
>>>
>>> Is there a way in VBS to see each line as it executes? Similar to ECHO
>>> ON in bat files, I'd like to see each line as it executes and the
>>> values that are being set in the variables.
>>>
>>> Thank you
>>
>> There certainly is nothing builtin that does this, and I don't know of
>> any environment that helps. It could be possible to create a script that
>> reads lines from another a very simple script, echos each line, then
>> executes it. However, complications quickly arise when statements cannot
>> be run in isolation one line at a time. For example lines continued on
>> several lines. And For Each, If Then, Do Until and other loops would be
>> impossible. Also, I see no way to show the values of variables.
>>
>> A quick try follows. First an example script that can be executed one
>> line at a time:
>> =======
>> Option Explicit
>>
>> Dim lngValue1, lngValue2, lngValue3
>>
>> lngValue1 = 3
>> lngValue2 = 5
>> lngValue3 = lngValue1 + lngValue3
>> Wscript.Echo lngValue3
>> =======
>> Then, if the above is saved in the file c:\Scripts\Example.vbs, the
>> following VBScript program will read each line, echo it to the console,
>> and execute each line:
>> =======
>> Option Explicit
>>
>> Dim strScriptFile, objFSO, objFile, strLine
>>
>> Const ForReading = 1
>>
>> ' Specify the VBScript program to run.
>> strScriptFile = "c:\Scripts\Example.vbs"
>>
>> ' Open the file.
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> Set objFile = objFSO.OpenTextFile(strScriptFile, ForReading)
>>
>> ' Read each line of the file.
>> Do Until objFile.AtEndOfStream
>> strLine = objFile.ReadLine
>> ' Echo the line to the console.
>> Wscript.Echo strLine
>> ' Run the line.
>> Execute strLine
>> Loop
>>
>> ' Clean up.
>> objFile.Close
>> =======
>> If run at a command prompt with cscript, the output would be:
>> ==========
>> Option Explicit
>>
>> Dim lngValue1, lngValue2, lngValue3
>>
>> lngValue1 = 3
>> lngValue2 = 5
>> lngValue3 = lngValue1 + lngValue3
>> Wscript.Echo lngValue3
>> 3
>> =========
>> However, I believe there are just too many complications to make this
>> workable. Maybe someone knows how to run VBScript programs in VB IDE, for
>> example.
>
> Third party IDE's exist, for example, PrimalScript from Sapien
> Technologies. Not sure if any of these can be set to display the staement
> as it is being executed, however, ECHO ON in batch files is an extremely
> limited debugging tool, and it cannot display variable values unless you
> code it to do so.
>
> /Al
>
>

My System SpecsSystem Spec
Old 03-03-2009   #5 (permalink)
Nick


 
 

Re: New to VBS..

Thanks for all of your suggestions!


"Joe Fawcett" <joefawcett@xxxxxx> wrote in message
news:%234mMDO$lJHA.3644@xxxxxx
Quote:

> Or use a script debugger such as Visual Studio. Even the free versions can
> do this I believe. You can then step through the code line by line.
>
> --
>
> Joe Fawcett (MVP - XML)
>
> http://joe.fawcett.name
>
> "Al Dunbar" <alandrub@xxxxxx> wrote in message
> news:%23wZYVP6lJHA.1288@xxxxxx
Quote:

>>
>> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
>> message news:ugSok95lJHA.1388@xxxxxx
Quote:

>>>
>>> <nickjax01@xxxxxx> wrote in message
>>> news:39861fd6-0c41-441b-89a1-bf551c24c5cc@xxxxxx
>>>> HI everyone...
>>>>
>>>> I am just starting out learning VBS...so I'd appreciate any help with
>>>> this...
>>>>
>>>> Is there a way in VBS to see each line as it executes? Similar to ECHO
>>>> ON in bat files, I'd like to see each line as it executes and the
>>>> values that are being set in the variables.
>>>>
>>>> Thank you
>>>
>>> There certainly is nothing builtin that does this, and I don't know of
>>> any environment that helps. It could be possible to create a script that
>>> reads lines from another a very simple script, echos each line, then
>>> executes it. However, complications quickly arise when statements cannot
>>> be run in isolation one line at a time. For example lines continued on
>>> several lines. And For Each, If Then, Do Until and other loops would be
>>> impossible. Also, I see no way to show the values of variables.
>>>
>>> A quick try follows. First an example script that can be executed one
>>> line at a time:
>>> =======
>>> Option Explicit
>>>
>>> Dim lngValue1, lngValue2, lngValue3
>>>
>>> lngValue1 = 3
>>> lngValue2 = 5
>>> lngValue3 = lngValue1 + lngValue3
>>> Wscript.Echo lngValue3
>>> =======
>>> Then, if the above is saved in the file c:\Scripts\Example.vbs, the
>>> following VBScript program will read each line, echo it to the console,
>>> and execute each line:
>>> =======
>>> Option Explicit
>>>
>>> Dim strScriptFile, objFSO, objFile, strLine
>>>
>>> Const ForReading = 1
>>>
>>> ' Specify the VBScript program to run.
>>> strScriptFile = "c:\Scripts\Example.vbs"
>>>
>>> ' Open the file.
>>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>>> Set objFile = objFSO.OpenTextFile(strScriptFile, ForReading)
>>>
>>> ' Read each line of the file.
>>> Do Until objFile.AtEndOfStream
>>> strLine = objFile.ReadLine
>>> ' Echo the line to the console.
>>> Wscript.Echo strLine
>>> ' Run the line.
>>> Execute strLine
>>> Loop
>>>
>>> ' Clean up.
>>> objFile.Close
>>> =======
>>> If run at a command prompt with cscript, the output would be:
>>> ==========
>>> Option Explicit
>>>
>>> Dim lngValue1, lngValue2, lngValue3
>>>
>>> lngValue1 = 3
>>> lngValue2 = 5
>>> lngValue3 = lngValue1 + lngValue3
>>> Wscript.Echo lngValue3
>>> 3
>>> =========
>>> However, I believe there are just too many complications to make this
>>> workable. Maybe someone knows how to run VBScript programs in VB IDE,
>>> for example.
>>
>> Third party IDE's exist, for example, PrimalScript from Sapien
>> Technologies. Not sure if any of these can be set to display the staement
>> as it is being executed, however, ECHO ON in batch files is an extremely
>> limited debugging tool, and it cannot display variable values unless you
>> code it to do so.
>>
>> /Al
>>
>>
>
>

My System SpecsSystem Spec
Reply

Thread Tools



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