Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB 6.0 >>> VB.NET / January 2004

Tip: Looking for answers? Try searching our database.

paramarray

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
peter - 24 Jan 2004 15:26 GMT
Hi everyone

In VB6,paramarray parameter is passed using byref,but in VB.NET,using byval.How can I get back the changed value of the   paramarray parameter

My work case in vb.net like this
----------------------------------------------------
Function mytestmethod(paramarray byval arg() as object
     arg(0)=1
     arg(1)="abc
End  Functio

Sub mycalling(
      dim a as integer=6
      dim b as string="xyz
      mytestmethod (a,b
      msgbox (a
      msgbox (b
End Su
----------------------------------------------------
the expected value of a,b is 12,"abc";but it remains 66 or "xyz"

Who can help me

Best regard

pete
Herfried K. Wagner [MVP] - 24 Jan 2004 16:15 GMT
* "=?Utf-8?B?cGV0ZXI=?=" <anonymous@discussions.microsoft.com> scripsit:
> In VB6,paramarray parameter is passed using byref,but in VB.NET,using
> byval.How can I get back the changed value of the   paramarray
[quoted text clipped - 6 lines]
>       arg(1)="abc"
> End  Function

Mhm...  Your function doesn't return anything.  You may want to return a
new array...  Have a look at the 'Return' keyword.

Signature

Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet

peter - 25 Jan 2004 13:06 GMT
I 'm sorry for my inattention.Now I correct it as follow

            Function mytestmethod(paramarray byval arg() as object) as objec
                arg(0)=1
                arg(1)="abc
                dim revalue as object="some value
                return revalue
            End  Functio

Sub mycalling(
      dim a as integer=6
      dim b as string="xyz
      dim r as objec
      r=mytestmethod (a,b
      msgbox (a
      msgbox (b
End Su

You might misunderstand my intention.My requirement is as follow
   1)in VB.NE
   2)passing uncertain number of parameters to the called function and retrieve the modified value of these parameters
   3)passing  parameters via parameter list,just as
                r=mytestmethod (arg1,arg2,arg3
       not via array as
                 dim argarray() as object={arg1,arg2,arg3}  
                 r=mytestmethod (arg1,arg2,arg3

Hope your suggestion
John Hart [MSFT] - 28 Jan 2004 20:37 GMT
Hi Peter,

As you have discovered the paramarray in VB.Net must be passed byVal which
as I'm sure you're aware means that you're actually passing a copy of the
values to the function.  There for the original values will not be changed
even if you make changes in the function.  See the following knowledge base
articles for more information about ParamArrays in VB.Net

       
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbup1003.asp          
       
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbls7/html/
vblrfvbspec7_1_6_4.asp

Since it appears that you're also returning an object from the function one
solution for you will be to use an additional ByRef parameter that contains
the updated values. For example:

Public Function mytestmethod(ByRef ModifiedArgs() As Object, ByVal
ParamArray args() As Object) As Object
       ModifiedArgs = args.Clone
       ModifiedArgs(0) = 12
       ModifiedArgs(1) = "abc"
       Dim reValue As Object = "some value"

       Return reValue

   End Function

   Sub mycalling()
       Dim a As Integer = 66
       Dim b As String = "zyz"
       Dim r As Object
       Dim NewValues() As Object

       r = mytestmethod(NewValues, a, b)
       a = NewValues(0)
       b = NewValues(1)
       MsgBox(a)
       MsgBox(b)

   End Sub
           
Hope that helps.
Signature

John Hart, Microsoft VB Team
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

> Thread-Topic: paramarray
> thread-index: AcPjQ/7JgZCJ5WZ/Q36zk8Pno1G1FQ==
> X-Tomcat-NG: microsoft.public.dotnet.languages.vb.upgrade
> From: "=?Utf-8?B?cGV0ZXI=?=" <anonymous@discussions.microsoft.com>
> References:  <8BA5FAA8-7797-4D47-A3D2-8BE326536652@microsoft.com>
<OuLXIVp4DHA.984@TK2MSFTNGP11.phx.gbl>
> Subject: Re: paramarray
> Date: Sun, 25 Jan 2004 05:06:07 -0800
[quoted text clipped - 12 lines]
> Path: cpmsftngxa07.phx.gbl
> Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.languages.vb.upgrade:6123
> NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
> X-Tomcat-NG: microsoft.public.dotnet.languages.vb.upgrade
>
> I 'm sorry for my inattention.Now I correct it as follow:

            Function mytestmethod(paramarray byval arg() as object) as
object
                arg(0)=12
                arg(1)="abc"
                dim revalue as object="some value"
                return revalue
            End  Function

Sub mycalling()
      dim a as integer=66
      dim b as string="xyz"
      dim r as object
      r=mytestmethod (a,b)
      msgbox (a)
      msgbox (b)
End Sub

You might misunderstand my intention.My requirement is as follow:
   1)in VB.NET
   2)passing uncertain number of parameters to the called function and
retrieve the modified value of these parameters.
   3)passing  parameters via parameter list,just as
                r=mytestmethod (arg1,arg2,arg3)
       not via array as
                 dim argarray() as object={arg1,arg2,arg3}    
                 r=mytestmethod (arg1,arg2,arg3)

Hope your suggestion.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.