Function Return Value
-
good day again... how does a function return two value? thanks
nothing is impossible.....
-
good day again... how does a function return two value? thanks
nothing is impossible.....
dim intTest as Integer = GetNumber() ... ..... ....... function GetNumber() as Integer dim i as Integer = 1+2 GetNumber = i ' or return i end function
When you get mad...THINK twice that the only advice Tamimi - Code
-
good day again... how does a function return two value? thanks
nothing is impossible.....
Hi, To return multiple values from a function, you will have to pass the arguments ByRef, not ByValue. The values you want to return will only be set to the arguments and these will be refelected outside the function. Search MSDN for ByRef keyword for more details !
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
-
dim intTest as Integer = GetNumber() ... ..... ....... function GetNumber() as Integer dim i as Integer = 1+2 GetNumber = i ' or return i end function
When you get mad...THINK twice that the only advice Tamimi - Code
thanks, your function does involves to values, but return one result.. ... i mean to ask, how does a function return to result.. ex: textbox1.text = getNumber(1) textbox2.text = getNumber(2) the code you provided was a great help, but it only returns 1 result... does anyone here knows how a function return two results?... thank you.. ;)
nothing is impossible.....
-
thanks, your function does involves to values, but return one result.. ... i mean to ask, how does a function return to result.. ex: textbox1.text = getNumber(1) textbox2.text = getNumber(2) the code you provided was a great help, but it only returns 1 result... does anyone here knows how a function return two results?... thank you.. ;)
nothing is impossible.....
Correction i mean "two results":laugh:
nothing is impossible.....
-
Hi, To return multiple values from a function, you will have to pass the arguments ByRef, not ByValue. The values you want to return will only be set to the arguments and these will be refelected outside the function. Search MSDN for ByRef keyword for more details !
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
thank you sir... your help is highly appreciated...
nothing is impossible.....
-
dim intTest as Integer = GetNumber() ... ..... ....... function GetNumber() as Integer dim i as Integer = 1+2 GetNumber = i ' or return i end function
When you get mad...THINK twice that the only advice Tamimi - Code
-
thank you sir... your help is highly appreciated...
nothing is impossible.....
An alternative is to define a structure that has two values and return that. In .NET 2 you could use one of those libraries that has a Pair generic class, e.g., see the free PowerCollections library. In C++ the Standard Library also defines a Pair class precisely for situations where you want to return two values - which is quite a common scenario in fact. I try to avoid ByRef when possible because it makes code less clear. But often you can't avoid it. Unfortunately, I'm not using .NET 2.0 yet, so can't use libraries such as PowerCollections.
Kevin
-
{{ A7WAL }} :omg:FLOAT LIKE A BUTTERFLY STING LIKE A BEE
Mohamad A. Flefel mflefel@hotmail.com +962 79 5963865 C#.net & VB.net Developer
your comment does not help any one !!!! whats wrong with you ?? :mad::mad::mad:
When you get mad...THINK twice that the only advice Tamimi - Code
-
good day again... how does a function return two value? thanks
nothing is impossible.....
Hi, Alternatively you can simply work with arrays. I managed to do it like this:
Private Function Amounts(ByVal SomeByValIfNecessary As String) As Integer() Dim AMarray(2) As Integer Try AMarray(0) = 1 AMarray(1) = 2 AMarray(2) = 3 Return AMarray Catch Ex As Exception msgbox(Ex.message) End Try
Elsewhere you can then call upon the different returned values like this:SomeIntegerVariable1 = Amounts(SomeValueForTheByref).GetValue(0) SomeIntegerVariable2 = Amounts(SomeValueForTheByVal).GetValue(1) SomeIntegerVariable3 = Amounts(SomeValueForTheByVal).GetValue(2)
Hope this helps, Johan -- modified at 7:30 Friday 24th November, 2006