﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>question about byRef behavior</title><link>http://www.visualbasicscript.com/</link><description /><copyright>(c) VBScript Forum</copyright><ttl>30</ttl><item><title> RE: question about byRef behavior (ehvbs)</title><description>  I called about half of the () in my postings related to this topic "parameter &lt;br&gt;   list parentheses", because &lt;br&gt;    &lt;br&gt;   &amp;nbsp; (a) they are used in VBScript to this aim for functions &lt;br&gt;    &lt;br&gt;   &amp;nbsp; (a) they must be carefully differentiated from "please pass this argument &lt;br&gt;   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by value" () that may be used for parameters of Subs &lt;b&gt;or&lt;/b&gt; Functions &lt;br&gt;    &lt;br&gt;   Perhaps I should have bolded ebgreen's &lt;br&gt;    &lt;br&gt;   &amp;nbsp; 2) &lt;b&gt;If the procedure does not return a value, don't put () around parameters&lt;/b&gt; &lt;br&gt;   &amp;nbsp;  &lt;br&gt;   or paraphrased it like: &lt;br&gt;    &lt;br&gt;   &amp;nbsp; 3) The parameter list of a Sub call &lt;b&gt;isn't delimited by ()&lt;/b&gt;; if you see a () after &lt;br&gt;   &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; the name of a Sub it's either the second type or a syntax error &lt;br&gt;   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;br&gt;   In some languages you can't call anything without (); if you have no parameters to  &lt;br&gt;   pass or don't want to tell just now you have to put () around the empty list; sometimes  &lt;br&gt;   you must put a void or an ellipsis between the () to help the compiler along. Still &lt;br&gt;   other languages don't use parameter list () at all (Tcl, shells); as to the Perl you  &lt;br&gt;   mentioned: D. Conway's best practice for parantheses is to avoid them for builtins and  &lt;br&gt;   'honorary' builtins. &lt;br&gt;    &lt;br&gt;   That's why I wouldn't strive to "find a technique where I can allways enclose the passed  &lt;br&gt;   parms in (), whether it is a sub or a func". I would accept the hard (?) fact of life &lt;br&gt;   that Subs aren't Functions and that in VBScript the second need "parameter list parentheses"  &lt;br&gt;   and the first don't. Then you can forget about Call (as a further means of muddle the difference)  &lt;br&gt;   and keep your mind alert for those&amp;nbsp; cases where special (fancy?) parameter passing forces you  &lt;br&gt;   to think about "protect this param" (). &lt;br&gt;    &lt;br&gt;   After reading this again, I think I must add: All the above concerns the&lt;b&gt; calling &lt;/b&gt;of NamedCodeBlocks. &lt;br&gt;   If you want my simple rule for the defining of any NamedCodeBlocks whatsoever - Subs, Functions, &lt;br&gt;   with no arguments, with 42 parameters, .... &lt;br&gt;    &lt;br&gt;   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Put parameter list () after the name in any case &lt;br&gt;    &lt;br&gt;   I never had problems with this, but YMMV. &lt;br&gt;    &lt;br&gt;    &lt;br&gt;    &lt;br&gt;    &lt;br&gt;   &amp;nbsp; &lt;br&gt;    &lt;br&gt;   </description><link>http://www.visualbasicscript.com/fb.ashx?m=41090</link><pubDate>Sat, 16 Dec 2006 14:54:15 GMT</pubDate></item><item><title> RE: question about byRef behavior (TNO)</title><description>  A parameter list is simply a list of values passed to a Function or Sub Procedure inside the () symbols. In JavaScript and alot of other Object Oriented Programming languages a &lt;i&gt;Parameter List&lt;/i&gt;&amp;nbsp; is treated like an associative array and&amp;nbsp;can be treated as such. This term was probably just&amp;nbsp;inherited into vbscript by its makers by a force of habit (C++) and doesn't mean anything more in this language besides being a simply list. </description><link>http://www.visualbasicscript.com/fb.ashx?m=41087</link><pubDate>Sat, 16 Dec 2006 12:31:44 GMT</pubDate></item><item><title> RE: question about byRef behavior (thorwath)</title><description>  Thanks so much for providing this type of detailed information. As a newby to this &lt;br&gt;  lang, I find some of the basic contructs just difficult to get a handle on, due to &lt;br&gt;  making erroneous assumptions based on other past-life langs. And the feedback I &lt;br&gt;  get here is just great. &lt;br&gt;   &lt;br&gt;  I have carefully read your reply and that very detailed thread you referenced above, &lt;br&gt;  with TNO's (and others) detailed rules. Based on that review, I would also like to  &lt;br&gt;  confirm the following&amp;nbsp;new assumption: &lt;br&gt;   &lt;br&gt;  &lt;font color="#0000ff"&gt;If I am willing to allways use the &lt;b&gt;&lt;font color="#ff0000"&gt;call &lt;/font&gt;&lt;/b&gt;prefix, I think I can always using () to wrap my passed &lt;/font&gt; &lt;br&gt;  &lt;font color="#0000ff"&gt;parms, &lt;i&gt;even&lt;/i&gt; if the sub or func does not take parms,&amp;nbsp;when I not using a return value.&lt;/font&gt; &lt;br&gt;  &lt;font color="#0000ff"&gt;In the case where I am using the return value from a func, I&amp;nbsp;won't use the&amp;nbsp;&lt;/font&gt;&amp;nbsp;&lt;b&gt;&lt;font color="#ff0000"&gt;call &lt;/font&gt;&lt;/b&gt;&lt;font color="#0000ff"&gt;prefix,&lt;/font&gt; &lt;br&gt;  &lt;font color="#0000ff"&gt;but will always use the ().&lt;/font&gt; &lt;br&gt;   &lt;br&gt;  It that assumption correct? I guess I am trying to find a technique where I can allways &lt;br&gt;  enclose the passed parms in (), whether it is a sub or a func. &lt;br&gt;   &lt;br&gt;  Also, I have one final question based on the mention of a lang construct: &lt;br&gt;  &lt;blockquote class="quote"&gt;&lt;i&gt;&lt;/i&gt;&lt;br&gt; &lt;br&gt;  (from one of the replies in the referenced thread) &lt;br&gt;   &lt;br&gt;  "Yes, it works; but those &lt;font color="#0000ff"&gt;()&lt;/font&gt; aren't &lt;font color="#0000ff"&gt;&lt;i&gt;parameter list () &lt;/i&gt;&lt;/font&gt;, but "please pass per  &lt;br&gt;  value" parantheses, that - by nature and&amp;nbsp; definition - can be put around  &lt;br&gt;  just one element.  &lt;br&gt;   &lt;br&gt;  Add to this that the VBScript Docs WRONGLY put parameter list () all over the  &lt;br&gt;  place - probably the docs and/or the documenters were infected with a heavy  &lt;br&gt;  dose of Javascript - it's no wonder, Subs, Functions, and () aren't easy to  &lt;br&gt;  get right in VBScript".  &lt;br&gt;  &lt;/blockquote&gt; &lt;br&gt;   &lt;br&gt;  I have gone back to the Microsoft online help file [Microsoft vbScript Help.CHM], &lt;br&gt;  which I have assumed is the bible on this lang, and I can't find any entries &lt;br&gt;  for either "()", "parameter" or "parameter list". This search also failed in my &lt;br&gt;  vbScript in a Nutshell book as well. So what the heck is the "&lt;i&gt;parameter list&lt;/i&gt;" &lt;br&gt;  construct anyway? Or, is this just a slang way of refering to the any set &lt;br&gt;  of params passed to a sub or func? &lt;br&gt;   &lt;br&gt;  -Thanks, Terry  &lt;br&gt;   </description><link>http://www.visualbasicscript.com/fb.ashx?m=41086</link><pubDate>Sat, 16 Dec 2006 11:24:20 GMT</pubDate></item><item><title> RE: question about byRef behavior (ehvbs)</title><description>  Hi thorwath, &lt;br&gt;    &lt;br&gt;   a short answer: &lt;br&gt;    &lt;br&gt;   &amp;nbsp; (1) sRet = x( sVar )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;br&gt;   &amp;nbsp;  &lt;br&gt;   calls function x() AS a Function and passes sVarby reference (as it was intented by  &lt;br&gt;   the author); the () are for used to delimit the (short) parameter list - and to indicate  &lt;br&gt;   (redundantly) that this is a function call &lt;br&gt;   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;br&gt;   &amp;nbsp; (2) x sVar&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;br&gt;   &amp;nbsp;  &lt;br&gt;   calls function x() AS a Sub (of course, on wonders why); sVar will be modified by x();  &lt;br&gt;   no () hints at the fact, that this a Sub call &lt;br&gt;    &lt;br&gt;   &amp;nbsp; (3) x( sVar ) - better written as  &lt;br&gt;   &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x (sVar) &lt;br&gt;   &amp;nbsp;  &lt;br&gt;   calls the function AS a Sub, but passing sVar by Value - indicated by the &lt;br&gt;   () around the variable name; the () may be looking like parameter list &lt;br&gt;   parantheses, but they aren't &lt;br&gt;    &lt;br&gt;   &amp;nbsp; (4) Call x( sVar ) &lt;br&gt;   &amp;nbsp;  &lt;br&gt;   calls x() As a Sub; because Call *needs* the parantheses (to indicate &lt;br&gt;   that a function is called AS a Sub), the () aren't interpreted as  &lt;br&gt;   'please pass per Value' parantheses &lt;br&gt;    &lt;br&gt;   &amp;nbsp; (5) Call x( (sVar) ) &lt;br&gt;   &amp;nbsp;  &lt;br&gt;   will be behave as (3). &lt;br&gt;    &lt;br&gt;   a longer discussion: &lt;br&gt;    &lt;br&gt;   &amp;nbsp;&amp;nbsp; &lt;a href="http://www.visualbasicscript.com/m_40908/tm.htm" target="_blank" rel="nofollow"&gt;http://www.visualbasicscript.com/m_40908/tm.htm&lt;/a&gt; &lt;br&gt;   &amp;nbsp;&amp;nbsp;  &lt;br&gt;   I agree with ebgreen's conclusion: &lt;br&gt;    &lt;br&gt;   &amp;nbsp;&amp;nbsp; There is really just two things to remember if you avoid Call:&amp;nbsp;  &lt;br&gt;    &lt;br&gt;   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1) If the procedure returns a value, put () around the parameters. &lt;br&gt;   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2) If the procedure does not return a value, don't put () around parameters.  &lt;br&gt;   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;br&gt;   This will guide you right for 99% of your VBScript programming without &lt;br&gt;   following my meanderings or learning by heart the rules TNO cited, especially &lt;br&gt;   if you &lt;b&gt;don't&lt;/b&gt; call Functions As Subs, but use each of these different types &lt;br&gt;   of NamedCodeBlocks/procedures as theirs authors intended them to be used (or &lt;br&gt;   wrap bad designed ones in better Functions OR Subs of your own). &lt;br&gt;   &amp;nbsp; </description><link>http://www.visualbasicscript.com/fb.ashx?m=41082</link><pubDate>Sat, 16 Dec 2006 08:42:47 GMT</pubDate></item><item><title> question about byRef behavior (thorwath)</title><description>  I have a question about "byRef" behavior in the following code fragment: &lt;br&gt;  &amp;nbsp; &lt;br&gt;  &lt;pre class="prettyprint"&gt;
 function x(s)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'by default, s is passed "byRef" 
 &amp;nbsp;&amp;nbsp;&amp;nbsp; s="altered by x()" 
 end function
 &amp;nbsp;
 sVar="zero"
 &amp;nbsp;
 x(sVar)
 msgBox sVar
 &amp;nbsp;
 call x(sVar)
 msgBox sVar
 &lt;/pre&gt; &lt;br&gt;  &amp;nbsp; &lt;br&gt;  The first time function x() is invoked, using the "x(sVar)" form, &lt;br&gt;  sVar is not modified after x() returns. &lt;br&gt;  &amp;nbsp; &lt;br&gt;  But the second time function x() is invoked, using the "call x(sVar)" &lt;br&gt;  form, sVar is modified, as expected, after x() returns. &lt;br&gt;  &amp;nbsp; &lt;br&gt;  Can someone explain why the first invocation of x() failed to let &lt;br&gt;  x() modify sVar? This seems like very nuanced behavior. Is it &lt;br&gt;  always necessary to use the "call " keyword if you want explicit &lt;br&gt;  "byRef" behavior? &lt;br&gt;  &amp;nbsp; &lt;br&gt;  -Thanks, Terry Horwath &lt;br&gt;   &lt;br&gt;   </description><link>http://www.visualbasicscript.com/fb.ashx?m=41080</link><pubDate>Sat, 16 Dec 2006 06:51:50 GMT</pubDate></item></channel></rss>
