![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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; more than one parameter is involved. Quote: > good code that needs to pass parameters > by value should look like: > > Whatever ("passed by value") 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" ) 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 Specs![]() |
| | #3 (permalink) |
| | 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: 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. 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 Specs![]() |
| | #4 (permalink) |
| | 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. 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.. CALL, just suggesting that it can be useful to have some knowledge of all of the features available. <snip> /Al |
My System Specs![]() |
![]() |
| 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 | |||