Names of the variables as SUB arguments

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vladislav.moltchanov@ktl.fi

    Names of the variables as SUB arguments

    I countinue to discover problems for simple tasks. Now I would like to
    write code, Sub or Function, where some values (more than 1) are
    calculated and are to be assigned to the variables which names I would
    like to submit as arguments to this SUB /Function
    How to do this.

    --
    Vlad. Moltchanov
  • Mike Storr

    #2
    Re: Names of the variables as SUB arguments

    Use the ByRef option in the arguments list of the function. Perform your
    calculations, set the new values, and your calling function can then use the
    new values of the variables.

    Mike Storr



    <vladislav.molt chanov@ktl.fi> wrote in message
    news:4027A04E.5 C5CBC4D@ktl.fi. ..[color=blue]
    > I countinue to discover problems for simple tasks. Now I would like to
    > write code, Sub or Function, where some values (more than 1) are
    > calculated and are to be assigned to the variables which names I would
    > like to submit as arguments to this SUB /Function
    > How to do this.
    >
    > --
    > Vlad. Moltchanov[/color]


    Comment

    • Bas Cost Budde

      #3
      Re: Names of the variables as SUB arguments

      vladislav.moltc hanov@ktl.fi wrote:
      [color=blue]
      > I countinue to discover problems for simple tasks. Now I would like to
      > write code, Sub or Function, where some values (more than 1) are
      > calculated and are to be assigned to the variables which names I would
      > like to submit as arguments to this SUB /Function
      > How to do this.[/color]

      Something looking like?

      sub setValues(name1 , value1, name2, value2)
      (name1) = value1
      (name2) = value2
      end sub

      ?

      I think that is not possible. Moreover, the variables assigned to must
      be global, or at least with a scope larger than the sub itself--why use
      such global variables? Can't you use a table, say Settings(settin gName,
      settingValue)?


      --
      Bas Cost Budde

      but the domain is nl

      Comment

      • David W. Fenton

        #4
        Re: Names of the variables as SUB arguments

        Bas Cost Budde <bas@heuveltop. org> wrote in
        news:c08dj4$66v $12@news2.solco n.nl:
        [color=blue]
        > vladislav.moltc hanov@ktl.fi wrote:
        >[color=green]
        >> I countinue to discover problems for simple tasks. Now I would
        >> like to write code, Sub or Function, where some values (more than
        >> 1) are calculated and are to be assigned to the variables which
        >> names I would like to submit as arguments to this SUB /Function
        >> How to do this.[/color]
        >
        > Something looking like?
        >
        > sub setValues(name1 , value1, name2, value2)
        > (name1) = value1
        > (name2) = value2
        > end sub
        >
        > ?
        >
        > I think that is not possible. Moreover, the variables assigned to
        > must be global, or at least with a scope larger than the sub
        > itself--why use such global variables? Can't you use a table, say
        > Settings(settin gName, settingValue)?[/color]

        Eh?

        If you pass ByRef (the default), then the values will work.

        Call your sub thusly:

        Dim OutsideVariable 1
        Dim OutsideVariable 2

        setValues OutsideVariable 1, "foo", OutsideVariable 2, "bar"

        Debug.Print OutsideVariable 1 & " " & OutsideVariable 2

        will return:

        foo bar

        in the debug window.

        That's how you can get multiple values returned from a sub/function,
        by passing variables by reference that are written to within the
        sub/function.

        This is a basic technique of VB.

        --
        David W. Fenton http://www.bway.net/~dfenton
        dfenton at bway dot net http://www.bway.net/~dfassoc

        Comment

        • Bas Cost Budde

          #5
          Re: Names of the variables as SUB arguments

          David W. Fenton wrote:
          [color=blue]
          > Bas Cost Budde <bas@heuveltop. org> wrote in[/color]
          [color=blue][color=green]
          >>I think that is not possible.[/color][/color]
          [color=blue]
          > Eh?[/color]

          Exactly! Eh? I COMPLETELY misunderstood the question. Sorry about that,
          happily I'm not the only one in the team.

          --
          Bas Cost Budde

          but the domain is nl

          Comment

          • David W. Fenton

            #6
            Re: Names of the variables as SUB arguments

            Bas Cost Budde <bas@heuveltop. org> wrote in
            news:c08vit$91u $1@news2.solcon .nl:
            [color=blue]
            > David W. Fenton wrote:
            >[color=green]
            >> Bas Cost Budde <bas@heuveltop. org> wrote in[/color]
            >[color=green][color=darkred]
            >>>I think that is not possible.[/color][/color]
            >[color=green]
            >> Eh?[/color]
            >
            > Exactly! Eh? I COMPLETELY misunderstood the question. Sorry about
            > that, happily I'm not the only one in the team.[/color]

            Well, it's also possible *you* understood it and *I* didn't!

            --
            David W. Fenton http://www.bway.net/~dfenton
            dfenton at bway dot net http://www.bway.net/~dfassoc

            Comment

            • vladislav.moltchanov@ktl.fi

              #7
              Re: Names of the variables as SUB arguments

              Thanks to all having replied.

              The idea of ByRef became much more clear. However, my task was to make
              an Access analog of SAS macro taking as an argument string like "name1
              name2 ... name5" (number of names is not fixed) and generating
              variables

              name1 name2 ... name5 with, say, consequitive random numbers.

              vladislav.moltc hanov@ktl.fi wrote:[color=blue]
              >
              > I countinue to discover problems for simple tasks. Now I would like to
              > write code, Sub or Function, where some values (more than 1) are
              > calculated and are to be assigned to the variables which names I would
              > like to submit as arguments to this SUB /Function
              > How to do this.
              >
              > --
              > Vlad. Moltchanov[/color]

              --
              Vladislav Moltchanov Ph.D.

              National Public Health Institute
              Dept. of Epidemiology and Health Promotion
              Mannerheimintie 166, 00300 Helsinki, Finland

              Tel: +358 9 4744 8644
              Fax: +358 9 4744 8338

              Comment

              • Steve Jorgensen

                #8
                Re: Names of the variables as SUB arguments

                On Mon, 09 Feb 2004 16:59:26 +0200, vladislav.moltc hanov@ktl.fi wrote:
                [color=blue]
                >I countinue to discover problems for simple tasks. Now I would like to
                >write code, Sub or Function, where some values (more than 1) are
                >calculated and are to be assigned to the variables which names I would
                >like to submit as arguments to this SUB /Function
                >How to do this.[/color]

                Are you sure what you're talking about isn't best simply handled with arrays
                or collections? Parsing the names of things at run-time just to get numbered
                lists is very inefficient, to the extent it's possible at all.

                Comment

                Working...