Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Return 2 values from a function
Message
From
15/10/2008 15:40:23
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
 
 
To
15/10/2008 15:01:46
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01355203
Message ID:
01355226
Views:
20
In VB.NET, these are used like so (note the ByRef instead of ByVal):
Sub Main
   Dim value1 As Integer = 1
   Dim value2 As Integer = 2

   FlipValues(value1, value2)

   'value1 now equals 2
   'value2 now equals 1
End Sub

Sub FlipValues(ByRef firstValue As Integer, ByRef secondValue As Integer)
   Dim tempValue As Integer = firstValue
   firstValue= secondValue
   secondValue= tempValue
End Sub
However, I would tend to agree with Paul that you should use a Structure. Like John said, a Function should return a single value. A Structure qualifies as a single value.

>Hi Daniel,
>
>In addition to John and Paul's info, if you really need multiple return values, you can use "out" parameters.
>
>Bill
>
>>Hi All,
>>
>>I need to return 2 values from a VB.NET function. One is data type integer and the other string.
>>What is the best approach to acomplish that?
>>
>>Thanks,
>>Daniel
Very fitting: http://xkcd.com/386/
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform