Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / March 2006

Tip: Looking for answers? Try searching our database.

Function returns two values

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Cahill - 30 Mar 2006 20:17 GMT
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
Jon Skeet [C# MVP] - 30 Mar 2006 20:39 GMT
> 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.

Signature

Jon Skeet - <skeet@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

Ken Halter - 31 Mar 2006 00:27 GMT
> Hello,
>
[quoted text clipped - 3 lines]
>        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.

Signature

Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..

Charles Law - 31 Mar 2006 09:38 GMT
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

> Hello,
>
[quoted text clipped - 24 lines]
>
>        End Function
Cor Ligthert [MVP] - 31 Mar 2006 09:58 GMT
Brian,

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

I hope this helps,

Cor
Brian Cahill - 31 Mar 2006 16:07 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.