how do u make it so instead of returning one value from a function u can return 2?
Printable View
how do u make it so instead of returning one value from a function u can return 2?
You have to use an output parameter, you cannot return two values the traditional way.
Public Function MyFunction(ByRef returnValue2 As Double) As Double
The second value can be returned through returnValue2. Make sense?
Quote:
Originally Posted by DNA7433
not really...
A function returns one object; no more, no less. That's the definition of a function: a method that returns a value. Now having said that a function returns one object, that object can be whatever you like. It can be an instance of a structure or class that have multiple properties that each return individual objects, or it can be an array or collection that contains multiple objects.
Alternatively you can do what DNA suggests and pass one or more parameters by reference, so that their value can be set withing the function and then passed back out again. An example of this is the Date.TryParse method. It needs to pass out two values: a boolean to indicate whether the operation was successful and the Data object that was created if it was successful. To do this its return type is Boolean and it has a Date argument passed by reference. That means that if the operation is successful, that parameter contains the Date after the method returns, e.g.VB Code:
Dim returnValue As Boolean Dim byRefParameter As Date returnValue = Date.TryParse(someString, byRefParameter) If returnValue = True Then 'The operation was successful so the date value is contained in the second parameter. MessageBox.Show("The data is " & byRefParameter.ToString()) End If
Or you can create a structure containing variables to hold the values that you need then have your function return the structure.
I agree.Quote:
Originally Posted by stanav
Quote:
Originally Posted by jmcilhinney