By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,639 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,639 IT Pros & Developers. It's quick & easy.

Function returns two values

P: n/a
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

Mar 30 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
It can't.

You either have to have a ByRef parameter that you set in your function, or
you need to create an object that has multiple properties. Then you function
creates an instance of that object, sets its properties, and returns it.

"Brian Cahill" <bc*****@wfs-ops.org> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
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

Mar 30 '06 #2

P: n/a
It looks like you are mis-using or not understanding a Function vs Sub. From what I see here you should change the Function to Sub
and change the ByVal to ByRef on the xmlstr and xslstr parameters. Also remove the two return statements.

--
Al Reid
"Brian Cahill" <bc*****@wfs-ops.org> wrote in message news:11*********************@i40g2000cwc.googlegro ups.com...
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

Mar 30 '06 #3

P: n/a

"Brian Cahill" <bc*****@wfs-ops.org> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
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.


Probably the best way is to return Structure or Class that contains both
values, as in

Private Class CtxScanner_R
Public Xml As String
Public Xsl As String
Friend Sub New( ByVal sXml As String, ByVal sXsl As String )
Me.Xml = sXml
Me.Xsl = sXsl
End Sub
End Class

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

. . . whatever code you need . . .

Return New CtxScanner_R( xmlstr, xslstr )
End Function

HTH,
Phill W.
Mar 31 '06 #4

P: n/a
I was handling Functions and Subs the wrong way like Al said. I should
have been passing byRef instead of byVal. Thanks for the code though.
Much appreciated.

Mar 31 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.