|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Function returns two valuesI 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 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. Show quoteHide quote "Brian Cahill" <bcah***@wfs-ops.org> wrote in message news:1143746266.677705.58390@i40g2000cwc.googlegroups.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 > 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. -- Show quoteHide quoteAl Reid "Brian Cahill" <bcah***@wfs-ops.org> wrote in message news:1143746266.677705.58390@i40g2000cwc.googlegroups.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 > "Brian Cahill" <bcah***@wfs-ops.org> wrote in message Probably the best way is to return Structure or Class that contains bothnews:1143746266.677705.58390@i40g2000cwc.googlegroups.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. 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. 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. |
|||||||||||||||||||||||