Passing Paramarray to another paramarray

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tubs

    Passing Paramarray to another paramarray

    I know it might seem weird but i have a need to pass the contents of a
    paramarray from one sub to another that also takes a paramarray.
    Problem is i want to pass it exactly as it came in to the first one.
    In other words, in the second one i want to refer to them as
    arg1...argN. Currently if i pass it directly, it embeds itself into
    another deeper structure. Is there any way to pass it the same way it
    came in, as individual args to the second param array?
  • Herfried K. Wagner [MVP]

    #2
    Re: Passing Paramarray to another paramarray

    * tstauffer@comma ndalkon.com (Tubs) scripsit:[color=blue]
    > I know it might seem weird but i have a need to pass the contents of a
    > paramarray from one sub to another that also takes a paramarray.
    > Problem is i want to pass it exactly as it came in to the first one.
    > In other words, in the second one i want to refer to them as
    > arg1...argN. Currently if i pass it directly, it embeds itself into
    > another deeper structure. Is there any way to pass it the same way it
    > came in, as individual args to the second param array?[/color]

    Why not create an overloded method that accepts an array?

    --
    Herfried K. Wagner
    MVP · VB Classic, VB.NET
    <http://www.mvps.org/dotnet>

    Improve your quoting style:
    <http://learn.to/quote>
    <http://www.plig.net/nnq/nquote.html>

    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: Passing Paramarray to another paramarray

      Tubs,
      Is this a VB6 question?

      Within VB.NET if you pass a ParamArray to a second ParamArray it simply
      works. In other words VB.NET does not "embeds itself into another deeper
      structure"!

      I seem to remember VB6 would not handle this well.

      The following VB.NET 2003 program behaves as expected:

      Public Sub Main()
      Test("a", "b", "c")
      End Sub

      Public Sub Test(ByVal ParamArray args() As String)
      DoTest(args)
      End Sub

      Public Sub DoTest(ByVal ParamArray args() As String)
      For Each arg As String In args
      Debug.WriteLine (arg, "arg")
      Next
      End Sub

      In that DoTest will print the three parameters passed to Test.

      Note if you use the VS.NET 2002 syntax on the For Each, it works in VS.NET
      2002 also!

      Hope this helps
      Jay

      "Tubs" <tstauffer@comm andalkon.com> wrote in message
      news:449db0f1.0 310300511.45fd9 23d@posting.goo gle.com...[color=blue]
      > I know it might seem weird but i have a need to pass the contents of a
      > paramarray from one sub to another that also takes a paramarray.
      > Problem is i want to pass it exactly as it came in to the first one.
      > In other words, in the second one i want to refer to them as
      > arg1...argN. Currently if i pass it directly, it embeds itself into
      > another deeper structure. Is there any way to pass it the same way it
      > came in, as individual args to the second param array?[/color]


      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Passing Paramarray to another paramarray

        Herfried,
        Because ParamArray parameters already accept the array! :-) See my other
        post for details, try it.

        The first time I did it, it was like "Wow! they got that right!!!!", as in
        C++ & VB6 it was a pain as Tubs is suggesting. Which is where I wonder if
        Tubs is using VB6.

        It is also very handy that you can actually type the ParamArray, so you can
        do efficient overloaded functions such as Min and Max.

        Function Min(ParamArray As Integer) As Integer
        Function Min(ParamArray As Long) As Long
        Function Min(ParamArray As Double) As Double

        I'm anxious to try Generic Functions that accept ParamArrays ;-)

        Jay

        "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
        news:bnrgml$14m q7i$1@ID-208219.news.uni-berlin.de...[color=blue]
        > * tstauffer@comma ndalkon.com (Tubs) scripsit:[color=green]
        > > I know it might seem weird but i have a need to pass the contents of a
        > > paramarray from one sub to another that also takes a paramarray.
        > > Problem is i want to pass it exactly as it came in to the first one.
        > > In other words, in the second one i want to refer to them as
        > > arg1...argN. Currently if i pass it directly, it embeds itself into
        > > another deeper structure. Is there any way to pass it the same way it
        > > came in, as individual args to the second param array?[/color]
        >
        > Why not create an overloded method that accepts an array?
        >
        > --
        > Herfried K. Wagner
        > MVP · VB Classic, VB.NET
        > <http://www.mvps.org/dotnet>
        >
        > Improve your quoting style:
        > <http://learn.to/quote>
        > <http://www.plig.net/nnq/nquote.html>[/color]


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Passing Paramarray to another paramarray

          * "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@ema il.msn.com> scripsit:[color=blue]
          > Herfried,
          > Because ParamArray parameters already accept the array! :-) See my other
          > post for details, try it.[/color]

          You are right...

          \\\
          Private Function Foo(ByVal ParamArray Bar() As Integer)
          FooBar(Bar)
          End Function

          Private Function FooBar(ByVal ParamArray Bar() As Integer)
          ...
          End Function
          ///

          will work.

          I'll have a look at your other post now.

          ;-)

          --
          Herfried K. Wagner
          MVP · VB Classic, VB.NET
          <http://www.mvps.org/dotnet>

          Comment

          • Troy Stauffer

            #6
            Re: Passing Paramarray to another paramarray

            unfortunately it is about VB6. I am glad to know dotnet got it right
            because i need this there as well but this particular project is in
            legacy code. Any thoughts for it? I have even tried repacking the
            thing with no avail.

            Troy B. Stauffer
            Jack of all trades, master of none :)

            *** Sent via Developersdex http://www.developersdex.com ***
            Don't just participate in USENET...get rewarded for it!

            Comment

            • Jay B. Harlow [MVP - Outlook]

              #7
              Re: Passing Paramarray to another paramarray

              Troy,
              Have you considered 'faking' an overload? Which is effectively what Herfried
              suggested.

              Define a routine that accepts an array, that both ParamArray routines then
              call.

              Something like:

              Public Sub Foo(ParamArray args() As Variant)
              DoBar args
              End Sub

              Public Sub Bar(ParamArray args() As Variant)
              DoBar args
              End Sub

              Private Sub DoBar(ByVal args As Variant)
              ' do real work for bar in here
              Dim arg As Variant
              For Each arg In args
              Debug.Print arg
              Next
              End Sub

              As this is effectively what you need to do in C++.

              The problem then becomes do you call DoBar, or Bar. Which is where real
              overloading in VB.NET is handy!

              Hope this helps
              Jay


              "Troy Stauffer" <tstauffer@comm andalkon.com> wrote in message
              news:uqgD0HxnDH A.1632@TK2MSFTN GP10.phx.gbl...[color=blue]
              > unfortunately it is about VB6. I am glad to know dotnet got it right
              > because i need this there as well but this particular project is in
              > legacy code. Any thoughts for it? I have even tried repacking the
              > thing with no avail.
              >
              > Troy B. Stauffer
              > Jack of all trades, master of none :)
              >
              > *** Sent via Developersdex http://www.developersdex.com ***
              > Don't just participate in USENET...get rewarded for it![/color]


              Comment

              • Troy Stauffer

                #8
                Re: Passing Paramarray to another paramarray

                No but i will give it a shot. I actual do something like this now just
                have problems because there are multiple ways to call it. Thanks for
                the advice though. If nothing else i learned about dotnet, which is
                where i really enjoy being anyhow. :)

                Troy B. Stauffer
                Jack of all trades, master of none :)

                *** Sent via Developersdex http://www.developersdex.com ***
                Don't just participate in USENET...get rewarded for it!

                Comment

                • Jay B. Harlow [MVP - Outlook]

                  #9
                  Re: Passing Paramarray to another paramarray

                  Troy,
                  I should add that the other option is to ask in one of the other VB
                  newsgroups. This one is a VB.NET newsgroup, try one of the VB groups, that
                  do not have dotnet in the name. such as
                  microsoft.publi c.vb.general.di scussion.

                  Hope this helps
                  Jay

                  "Troy Stauffer" <tstauffer@comm andalkon.com> wrote in message
                  news:%23V8ZfYxn DHA.2064@TK2MSF TNGP11.phx.gbl. ..[color=blue]
                  > No but i will give it a shot. I actual do something like this now just
                  > have problems because there are multiple ways to call it. Thanks for
                  > the advice though. If nothing else i learned about dotnet, which is
                  > where i really enjoy being anyhow. :)
                  >
                  > Troy B. Stauffer
                  > Jack of all trades, master of none :)
                  >
                  > *** Sent via Developersdex http://www.developersdex.com ***
                  > Don't just participate in USENET...get rewarded for it![/color]


                  Comment

                  Working...