Function returns two values

  • Thread starter Thread starter Brian Cahill
  • Start date Start date
B

Brian Cahill

Hello,

I am trying to write a function that returns two values but I can't
figure out the syntax or if it's even possible.

Private Function CTXScanner(ByVal mfSvr As String, ByVal xmlstr
As String, ByVal xslstr As String)
Try
For Each HotfixItem In MFRecHotfix.Items
xmlstr = xmlstr & "<MFHOTFIX ID=""" &
HotfixItem & """>" & Environment.NewLine
xmlstr = xmlstr & "<SERVER>" & mfSvr &
"</SERVER>" & Environment.NewLine
xmlstr = xmlstr & "</MFHOTFIX>"
Next

Return xmlstr
Return xslstr
End If
srv2 = Nothing
winSrv2 = Nothing

Catch ex As Exception
MsgBox(ex.Message.ToString())
Exit Function
End Try

End Function
 
Brian Cahill said:
I am trying to write a function that returns two values but I can't
figure out the syntax or if it's even possible.

It's not - at least, you can't have two actual return values. However,
you *can* use out parameters to simulate multiple return values.

Personally, I'd suggest splitting the function into two - one for the
XML and one for the XSL.
 
Brian Cahill said:
Hello,

I am trying to write a function that returns two values but I can't
figure out the syntax or if it's even possible.

Private Function CTXScanner(ByVal mfSvr As String, ByVal xmlstr
As String, ByVal xslstr As String)

No real help here... just noting the lack of a return type.

As far as multiple returns goes, in VB6, I can return arrays, collections,
classes, etc. So, if you create a class to hold your returns, you're set...
arrays and collections are Ok too but, since I'm a "VB6'er", collections
aren't really type safe (they can be but.....) I like using a class so I can
have my type/range checking, etc. with intellisense.
 
Hi Brian

In addition to the other answers, as you are returning state and not
function, you might want to use a structure rather than a class to return
your two values.

HTH

Charles
 
Brian,

You can return an array from the type "object".

I hope this helps,

Cor
 
I was mistaken in how I was handling Functions and Subs. I passed
ByRef instead of ByVal and now I'm alright. Thanks for the info though.
 
Back
Top