-
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?
-
Will this work for you?
Try this.
Function Test(x)
x = 100
End Function
dim y
test y
'Now y=100
-
OK. I didn't realize it was that simple in VB.
Thanks
-
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)
-
That's exactly what I'm talking about.
Thanks.