it's posible that Function return byref

  • Thread starter Thread starter mtczx232
  • Start date Start date
it's posible that Function return byref? what the syntax?

I don't know what you mean by "return byref"? If you mean set the
value of a byref variable it's like this:

Function Foo(byref MyVar As Type)
MyVar = newValue
End Function

If thats not what you were looking for please elaborate a bit.

Thanks,

Seth Rowe
 
put the byref as a parameter in your function, the return isnt by ref...
just by value

all you can really do is

Public MyFunction(ByRef myReturnValue) as Boolean
which would return a boolean if the ref value was set successfully, or if
you dont want a return status, then just make it a sub with the same
parameters
 
it's posible that Function return byref? what the syntax?

No, it's not. It doesn't even make sense. Could you tell us what you
were hoping the expected result might be? That would help us better
understand what you are really looking for.
 
I ask about


Function GetFoo(byref MyVar As Type) byref As Type
return MyVar
End Function



So the function return reference instead value. Like we do in C++
My target is to send this return ref as argument to another procedure
like that: sub(byref x)
 
I ask about

Function GetFoo(byref MyVar As Type) byref As Type
return MyVar
End Function

So the function return reference instead value. Like we do in C++
My target is to send this return ref as argument to another procedure
like that: sub(byref x)

Why not just store it in a variable first?

Dim myVar as Type = Foo() As Type
Foo2(myVar)

Function Foo() As Type
Return someValue
End Function

Sub Foo2(ByRef myVar As Type)
myVar = newValue
End Sub

Thanks,

Seth Rowe
 
If the return type of a function is a reference type, then it will return a
reference to the object returned. If the return type is a value type, then
it will return a copy of the value returned.
--
David Anton
www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Python
Instant C#
Instant VB
Instant C++
Instant Python
C++ to C# Converter
C++ to VB Converter
 
I ask about

Function GetFoo(byref MyVar As Type) byref As Type
return MyVar
End Function

So the function return reference instead value. Like we do in C++
My target is to send this return ref as argument to another procedure
like that: sub(byref x)

Remember, ByRef and ByVal are parameter passing mechanisms. It
doesn't make sense to specify either as part of the return type.
ByRef allows a method to change the reference of the parameter so that
the change is visible to the caller. If you want to pass an object
ByRef then you'll have to land the value you want to pass into a
variable first. The method can then change the reference of that
variable.
 
It does make sense - it's really just reference vs value type semantics.
For reference types, you get the behavior that the OP wants. For value
types you don't (try returning a value type object from a function - a change
to the value returned from the function doesn't affect the original value).
--
David Anton
www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Python
Instant C#
Instant VB
Instant C++
Instant Python
C++ to C# Converter
C++ to VB Converter
 
It does make sense - it's really just reference vs value type semantics.
For reference types, you get the behavior that the OP wants. For value
types you don't (try returning a value type object from a function - a change
to the value returned from the function doesn't affect the original value).
--
David Antonwww.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Python
Instant C#
Instant VB
Instant C++
Instant Python
C++ to C# Converter
C++ to VB Converter

What would ByRef (or ByVal for that matter) even mean in regards to a
function return value?

Also, Type already is a reference type (and an immutable one at that)
so I'm not sure what the OP is wanting.
 
Back
Top