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 - VBScript procedure and function calls

Reply
 
Old 01-28-2009   #1 (permalink)
angusdundee


 
 

VBScript procedure and function calls

Hi,
I am confused about VBScript procedure and function calls. sometimes
the parenthese are included sometimes no like for example when calling
Date (two version Date() and Date) and Time

any thought please. thank you

My System SpecsSystem Spec
Old 01-28-2009   #2 (permalink)
Al Dunbar


 
 

Re: VBScript procedure and function calls


"ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
news:498055a5$0$31863$9b4e6d93@xxxxxx-online.net...
Quote:

> angusdundee@xxxxxx schrieb:
Quote:

>> Hi,
>> I am confused about VBScript procedure and function calls. sometimes
>> the parenthese are included sometimes no like for example when calling
>> Date (two version Date() and Date) and Time
> [...]
> If you follow the simple rule:
>
> Use parameter list parentheses when you want to get something back
> from the called code
>
> e.g.:
>
> MsgBox "Just output/side effect" (called as Sub)
>
> iRet = MsgBox( "need your answer" ) (called as function)
> WScript.Echo "got from MsgBox(...)", iRet
> ==>
> got from MsgBox(...) 1
>
> then you won't be confused by bad code like:
>
> MsgBox( "passed by value" )
>
> which slips past the 'compilers' guard by (unwittingly) using
> 'pass me by value' brackets;
Fortunately, this bad code is more likely to trigger a syntax error when
more than one parameter is involved.
Quote:

> good code that needs to pass parameters
> by value should look like:
>
> Whatever ("passed by value")
True, however, putting a blank character between the module name and the
leading parenthesis is an optional (but useful) convention that is
meaningless to the parser.
Quote:

> and you won't have to learn/think about Call which is just a
> syntactical means to let you write parameter list parentheses
> when doing a sub call:
>
> Call MsgBox( "Just output/side effect" )
I think it is useful to learn about the Call statement because one might
occasionally inherit code written that way. It also completes the comparison
of the various ways to invoke a sub or function, along with a apparent few
syntactical anomalies.

Although you can use CALL to invoke a function (thereby ignoring the
returned value), I think its best use is to explicitly differentiate between
routines that do return a value (functions) and those that do not (subs).

That said, I now tend to use functions exclusively, and, as a result, never
use a CALL statement, even though that could be done with no ill effect.

Strangely enough, though, when you use CALL without parentheses, the error
thrown is: "expected end of statement", whereas when you include parentheses
but have no CALL, the error message is "cannot use parenthesis when calling
a sub" (same message if the routine in question is defined as a function).
It is almost as if using CALL is not a call, whereas leaving it off is
somehow considered a call...

/Al


My System SpecsSystem Spec
Old 01-29-2009   #3 (permalink)
MikeB


 
 

Re: VBScript procedure and function calls

----- Original Message -----
From: "Al Dunbar" <alandrub@xxxxxx>
Newsgroups: microsoft.public.scripting.vbscript
Sent: Wednesday, January 28, 2009 5:48 PM
Subject: Re: VBScript procedure and function calls

Quote:

>
> "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
> news:498055a5$0$31863$9b4e6d93@xxxxxx-online.net...
Quote:

>> angusdundee@xxxxxx schrieb:
<snip>
Quote:

> I think it is useful to learn about the Call statement because one might
> occasionally inherit code written that way. It also completes the
> comparison of the various ways to invoke a sub or function, along with a
> apparent few syntactical anomalies.
I have never written a single line of vb / vbscript code with CALL. The
lengthy explanations alone are reason enough to avoid it.

Just because it allows you to make something do what it isn't intended is
reason enough to not use it..

Quote:

> Although you can use CALL to invoke a function (thereby ignoring the
> returned value), I think its best use is to explicitly differentiate
> between routines that do return a value (functions) and those that do not
> (subs).
>
> That said, I now tend to use functions exclusively, and, as a result,
> never use a CALL statement, even though that could be done with no ill
> effect.
>
> Strangely enough, though, when you use CALL without parentheses, the error
> thrown is: "expected end of statement", whereas when you include
> parentheses but have no CALL, the error message is "cannot use parenthesis
> when calling a sub" (same message if the routine in question is defined as
> a function). It is almost as if using CALL is not a call, whereas leaving
> it off is somehow considered a call...
>
> /Al
>
>

My System SpecsSystem Spec
Old 02-03-2009   #4 (permalink)
Al Dunbar


 
 

Re: VBScript procedure and function calls


"MikeB" <bauerlie@xxxxxx> wrote in message
news:uOykehkgJHA.5956@xxxxxx
Quote:

> ----- Original Message -----
> From: "Al Dunbar" <alandrub@xxxxxx>
> Newsgroups: microsoft.public.scripting.vbscript
> Sent: Wednesday, January 28, 2009 5:48 PM
> Subject: Re: VBScript procedure and function calls
>
>
Quote:

>>
>> "ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
>> news:498055a5$0$31863$9b4e6d93@xxxxxx-online.net...
Quote:

>>> angusdundee@xxxxxx schrieb:
>
> <snip>
Quote:

>> I think it is useful to learn about the Call statement because one might
>> occasionally inherit code written that way. It also completes the
>> comparison of the various ways to invoke a sub or function, along with a
>> apparent few syntactical anomalies.
>
> I have never written a single line of vb / vbscript code with CALL. The
> lengthy explanations alone are reason enough to avoid it.
I have no issues with anyone avoiding certain "features" of vbscript. I
rarely use CALL, but I NEVER use WEND.

As to your fear of lengthy explanations, do you really only observe short
explanations? ;-)
Quote:

> Just because it allows you to make something do what it isn't intended is
> reason enough to not use it..
I'm not sure what you mean by that. But I was not counselling anyone to use
CALL, just suggesting that it can be useful to have some knowledge of all of
the features available.

<snip>

/Al


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
VBscript Array Split Function VB Script
digital certified in a vbscript function VB Script
VBScript to search LDAP from Excel function? VB Script
VBScript function in a .htm page VB Script
Line drawing function calls in Windows??? Vista General


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