Results 1 to 5 of 5

Thread: How to use & w/ a function parameter

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    In C++, you can pass a parameter to a function using &
    so that the parameter you pass it is actually modified
    and you do not have to return that parameter.
    Like this:
    Code:
    void Function(int &x){
    x = 100;
    }
    Then if you say:
    Code:
    int a;
    Function(a);
    Then a is actually 100 now.

    Well, how do you do this in VB?

  2. #2
    Guest

    Lightbulb Will this work for you?

    Try this.

    Function Test(x)

    x = 100

    End Function

    dim y

    test y

    'Now y=100

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    OK. I didn't realize it was that simple in VB.
    Thanks

  4. #4
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    What you are talking about is passing variables by reference instead of by value - that's what the x& is, a reference to x.

    In VB you use ByVal and ByRef to achieve the same thing. You've probably seen this in the declaration of API function calls.

    For example:

    Code:
    Public Sub SetTo100(ByRef x As Integer)
    Harry.

    "From one thing, know ten thousand things."

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    That's exactly what I'm talking about.
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width