![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Are sub-routines parameters called by reference or called by value? When I call a sub-routine in a VBscript and I want to pass two System.Collections.ArrayList objects are these objects then passed by value or by reference? In other words: are possible modifications (done in the subroutine) visible OUTSIDE the subroutine or not? Example: Set arr1 = CreateObject("System.Collections.ArrayList") Set arr2 = CreateObject("System.Collections.ArrayList") .....<fill arr1 and arr2>... ..... call mycalc .... sub mycalc parm1 parm2 ... parm1.removeAt 1 ... end sub Thomas |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Are sub-routines parameters called by reference or called byvalue? On Mar 25, 1:40*pm, t.lebre...@xxxxxx (Thomas Lebrecht) wrote: Quote: > When I call a sub-routine in a VBscript and I want to pass > two System.Collections.ArrayList objects > are these objects then passed by value or by reference? > > In other words: are possible modifications (done in the subroutine) visible > OUTSIDE the subroutine or not? > > Example: > > Set arr1 = CreateObject("System.Collections.ArrayList") > Set arr2 = CreateObject("System.Collections.ArrayList") > ....<fill arr1 and arr2>... > .... > > call mycalc > > ... > > sub mycalc parm1 parm2 > * *... > * *parm1.removeAt 1 > * *... > end sub answer of the top of my head, but I do know that VBScript was based off of VB6 so it probably works the same way VB6 works. And in VB.NET, which succeeded VB6, ByVal is the default. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Are sub-routines parameters called by reference or called by value? "Thomas Lebrecht" <t.lebrecht@xxxxxx> schrieb Quote: > When I call a sub-routine in a VBscript and I want to pass > two System.Collections.ArrayList objects > are these objects then passed by value or by reference? Is there a reason why VBscript questions are also sent to the VB.Net group lately? In VB.Net, without specifying ByVal or ByRef, ByVal is the default. See "Passing Mechanism" under the "Rules" headline: http://msdn.microsoft.com/en-us/library/cbs7z96t.aspx Armin |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Are sub-routines parameters called by reference or called by value? "Thomas Lebrecht" <t.lebrecht@xxxxxx> wrote in message news:49ca6c9d$0$32676$9b4e6d93@xxxxxx-online.net... Quote: > When I call a sub-routine in a VBscript and I want to pass > two System.Collections.ArrayList objects > are these objects then passed by value or by reference? > > In other words: are possible modifications (done in the subroutine) > visible > OUTSIDE the subroutine or not? > > Example: > > Set arr1 = CreateObject("System.Collections.ArrayList") > Set arr2 = CreateObject("System.Collections.ArrayList") > ....<fill arr1 and arr2>... > .... > > call mycalc > > ... > > sub mycalc parm1 parm2 > ... > parm1.removeAt 1 > ... > end sub > > Thomas > passed "by reference", unless you specify ByVal. If the argument is an expression it is passed "by value". This is an instance where the behaviour of VBScript is different from VB (classic). I try to always specify ByVal or ByRef to avoid confusion. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Are sub-routines parameters called by reference or called byvalue? Thomas Lebrecht wrote: Quote: > When I call a sub-routine in a VBscript and I want to pass > two System.Collections.ArrayList objects > are these objects then passed by value or by reference? > Aside from the comments above, imho vbs parameters are passed "ByRef" by default. The only exception I know is when you explicitly call for "ByVal" in your Sub or Function definition. It more-or-less has to be byref, otherwise you could never pass out values through the parameters of a function or sub. There is also (that mysterious) "coercion" in vbs. To some limited extent, vbs will look at the calling sequence of objects being called, and "coerce" the parameters to fit (i.e., force the parameters into agreement as to type). I have never seen the "rules" of coercion (i.e., when it works and when it doesn't work(, but I have seen cases of it working. However, it does not appear to be useful in your case. As far as using net framework objects with vbs is concerned, I have seen a few limited examples, but in general the net framework is designed for use by dot-net languages. cheers, jw ____________________________________________________________ You got questions? WE GOT ANSWERS!!! ..(but, no guarantee the answers will be applicable to the questions) |
My System Specs![]() |
| | #6 (permalink) |
| | VBScript vs. VB.NET group posting (Was: Re: Are sub-routines parameters called by reference or called by value?) Because the poster is often confused about which group is appropriate for posting a particular question, usually (as in this case) due to some confusion about the distinction between the .NET runtime and the language used to access it. For anyone who bothers to read this, if you're using a .NET from VBScript/Jscript or any other Active Scripting language, posting to a .NET language group isn't likely to net you any useful help; you're not using a ..NET language. It might be helpful to post in a core .NET group if it appears that the issue might be confusion about how the component behaves, but for a language issue - like the ByRef vs. ByVal behavior of VBScript - it's best to post to the VBScript language group. "Armin Zingler" <az.nospam@xxxxxx> wrote in message news:uKsgCcXrJHA.3864@xxxxxx Quote: > "Thomas Lebrecht" <t.lebrecht@xxxxxx> schrieb Quote: >> When I call a sub-routine in a VBscript and I want to pass >> two System.Collections.ArrayList objects >> are these objects then passed by value or by reference? > > Is there a reason why VBscript questions are also sent to the VB.Net group > lately? > > In VB.Net, without specifying ByVal or ByRef, ByVal is the default. See > "Passing Mechanism" under the "Rules" headline: > http://msdn.microsoft.com/en-us/library/cbs7z96t.aspx > > > Armin |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Are sub-routines parameters called by reference or called by value? Richard Mueller [MVP] <rlmueller-nospam@xxxxxx> typed: Quote: Quote: >> When I call a sub-routine in a VBscript and I want to pass >> two System.Collections.ArrayList objects >> are these objects then passed by value or by reference? >> >> In other words: are possible modifications (done in the subroutine) >> visible >> OUTSIDE the subroutine or not? >> >> Example: >> >> Set arr1 = CreateObject("System.Collections.ArrayList") >> Set arr2 = CreateObject("System.Collections.ArrayList") >> ....<fill arr1 and arr2>... >> .... >> >> call mycalc >> >> ... >> >> sub mycalc parm1 parm2 >> ... >> parm1.removeAt 1 >> ... >> end sub Quote: > In VBScript if the argument is a variable, array, or array element, > it is passed "by reference", unless you specify ByVal. If the > argument is an expression it is passed "by value". This is an > instance where the behaviour of VBScript is different from VB > (classic). I try to always specify ByVal or ByRef to avoid confusion. their different opinions. If somebody has by chance a source for what happens by the parametre handling with functions? Besides, also I could observe already very much different behaviour of the Windows-Script-Host interpreter. I would be very glad with a solution from reliable source. The explanation advanced by you corresponds, at least, to my experiences in the earliest. TIA -- ЯR |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Are sub-routines parameters called by reference or called by value? "Ruediger Roesler" <administrator@xxxxxx> wrote in message news:49cabe3b$0$32665$9b4e6d93@xxxxxx-online.net... Quote: > Richard Mueller [MVP] <rlmueller-nospam@xxxxxx> typed: > Quote: Quote: >>> When I call a sub-routine in a VBscript and I want to pass >>> two System.Collections.ArrayList objects >>> are these objects then passed by value or by reference? >>> >>> In other words: are possible modifications (done in the subroutine) >>> visible >>> OUTSIDE the subroutine or not? >>> >>> Example: >>> >>> Set arr1 = CreateObject("System.Collections.ArrayList") >>> Set arr2 = CreateObject("System.Collections.ArrayList") >>> ....<fill arr1 and arr2>... >>> .... >>> >>> call mycalc >>> >>> ... >>> >>> sub mycalc parm1 parm2 >>> ... >>> parm1.removeAt 1 >>> ... >>> end sub Quote: >> In VBScript if the argument is a variable, array, or array element, >> it is passed "by reference", unless you specify ByVal. If the >> argument is an expression it is passed "by value". This is an >> instance where the behaviour of VBScript is different from VB >> (classic). I try to always specify ByVal or ByRef to avoid confusion. > Now we are so clever as like before, after all here have made known > their different opinions. If somebody has by chance a source for what > happens by the parametre handling with functions? Besides, also I could > observe already very much different behaviour of the Windows-Script-Host > interpreter. I would be very glad with a solution from reliable source. > > The explanation advanced by you corresponds, at least, to my experiences > in the earliest. TIA > > -- > ?R > bottom of the page): http://www.microsoft.com/technet/scr..._vbs_zuue.mspx I also referred to "Windows 2000 Windows Script Host" by Tim Hill before my original reply. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Are sub-routines parameters called by reference or called by value? I can't find the original post via Google Groups, unfortunately, but there IS a fairly complete listing of how byval/byref works in various ways when calling a procedure that was provided by Eric Lippert, one of the key VBScript developers. This link: http://classicasp.aspfaq.com/general...-vbscript.html appears to be the entire post as I recall it now. "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in message news:OhJAg$arJHA.3848@xxxxxx Quote: > > "Ruediger Roesler" <administrator@xxxxxx> wrote in message > news:49cabe3b$0$32665$9b4e6d93@xxxxxx-online.net... Quote: >> Richard Mueller [MVP] <rlmueller-nospam@xxxxxx> typed: >> Quote: >>>> When I call a sub-routine in a VBscript and I want to pass >>>> two System.Collections.ArrayList objects >>>> are these objects then passed by value or by reference? >>>> >>>> In other words: are possible modifications (done in the subroutine) >>>> visible >>>> OUTSIDE the subroutine or not? >>>> >>>> Example: >>>> >>>> Set arr1 = CreateObject("System.Collections.ArrayList") >>>> Set arr2 = CreateObject("System.Collections.ArrayList") >>>> ....<fill arr1 and arr2>... >>>> .... >>>> >>>> call mycalc >>>> >>>> ... >>>> >>>> sub mycalc parm1 parm2 >>>> ... >>>> parm1.removeAt 1 >>>> ... >>>> end sub Quote: >>> In VBScript if the argument is a variable, array, or array element, >>> it is passed "by reference", unless you specify ByVal. If the >>> argument is an expression it is passed "by value". This is an >>> instance where the behaviour of VBScript is different from VB >>> (classic). I try to always specify ByVal or ByRef to avoid confusion. >> Now we are so clever as like before, after all here have made known >> their different opinions. If somebody has by chance a source for what >> happens by the parametre handling with functions? Besides, also I could >> observe already very much different behaviour of the Windows-Script-Host >> interpreter. I would be very glad with a solution from reliable source. >> >> The explanation advanced by you corresponds, at least, to my experiences >> in the earliest. TIA >> >> -- >> ?R >> > This link from "Microsoft Windows 2000 Scripting Guide" explains (near the > bottom of the page): > > http://www.microsoft.com/technet/scr..._vbs_zuue.mspx > > I also referred to "Windows 2000 Windows Script Host" by Tim Hill before > my original reply. > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > > |
My System Specs![]() |
| | #10 (permalink) |
| | Re: Are sub-routines parameters called by reference or called by value? By reference as this is the default behavior of all VB pre .Net languages ( including VBA , VBS ) HTH Michel "Thomas Lebrecht" <t.lebrecht@xxxxxx> schreef in bericht news:49ca6c9d$0$32676$9b4e6d93@xxxxxx-online.net... Quote: > When I call a sub-routine in a VBscript and I want to pass > two System.Collections.ArrayList objects > are these objects then passed by value or by reference? > > In other words: are possible modifications (done in the subroutine) > visible > OUTSIDE the subroutine or not? > > Example: > > Set arr1 = CreateObject("System.Collections.ArrayList") > Set arr2 = CreateObject("System.Collections.ArrayList") > ....<fill arr1 and arr2>... > .... > > call mycalc > > ... > > sub mycalc parm1 parm2 > ... > parm1.removeAt 1 > ... > end sub > > Thomas > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| I don't know what this is called but how do I block it | Vista General | |||
| Re: ? for the so called Trolls | Vista General | |||
| files called .rim | Vista mail | |||
| I called Microsoft | Vista installation & setup | |||
| Why is 5744 being called RC2 ? | Vista General | |||