468,257 Members | 1,423 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,257 developers. It's quick & easy.

Function returns two values

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
5 3205
Brian Cahill <bc*****@wfs-ops.org> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 30 '06 #2
"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)


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.

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..
Mar 30 '06 #3
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 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 31 '06 #4
Brian,

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

I hope this helps,

Cor
Mar 31 '06 #5
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.

Mar 31 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Penn Markham | last post: by
12 posts views Thread by Gaurav Veda | last post: by
7 posts views Thread by Jim Geissman | last post: by
2 posts views Thread by laredotornado | last post: by
8 posts views Thread by Tweaxor | last post: by
2 posts views Thread by mosesdinakaran | last post: by
7 posts views Thread by Darko | last post: by
21 posts views Thread by coolguyaroundyou | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.