VB function with multiple output - assignment of results
For future readers, VB.NET 2017 and above now supports value tuples as a language feature. You declare your function as follows:
Function ColorToHSV(clr As System.Drawing.Color) As (hue As Double, saturation As Double, value As Double)
Dim max As Integer = Math.Max(clr.R, Math.Max(clr.G, clr.B))
Dim min As Integer = Math.Min(clr.R, Math.Min(clr.G, clr.B))
Dim h = clr.GetHue()
Dim s = If((max = 0), 0, 1.0 - (1.0 * min / max))
Dim v = max / 255.0
Return (h, s, v)
End Function
And you call it like this:
Dim MyHSVColor = ColorToHSV(clr)
MsgBox(MyHSVColor.hue)
Note how VB.NET creates public property named hue
inferred from the return type of the called function. Intellisense too works properly for these members.
Note however that you need to target .NET Framework 4.7 for this to work. Alternately you can install System.ValueTuple
(available as NuGet package) in your project to take advantage of this feature.
Your solution works and it is an elegant way to return multiple results, however you could also try with this
Public Sub foo2(ByVal nA As Integer, ByRef a1 As Integer, ByRef a2 As Integer)
a1 = Convert.ToInt32(nA)
a2 = Convert.ToInt32(nA) +1
End Sub
and call with
foo2(nA, CeilOfA, FloorOfA)
If you have many results to return it is logical to think to a class that could return all the values required (Expecially if these values are of different dataTypes)
Public Class CalcParams
Public p1 As Integer
Public p2 As String
Public p3 As DateTime
Public p4 As List(Of String)
End Class
Public Function foo2(ByVal nA As Integer) As CalcParams
Dim cp = new CalcParams()
cp.p1 = Convert.ToInt32(nA)
.......
Return cp
End Function