473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
4 1057
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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
12
by: Gaurav Veda | last post by:
Hi ! I am a poor mortal who has become terrified of Python. It seems to have thrown all the OO concepts out of the window. Penniless, I ask a basic question : What is the difference between a...
7
by: Jim Geissman | last post by:
Take a table, where not all the columns are populated: CREATE TABLE #T (A int, B int, C int, D int) INSERT #T (A,B) VALUES (1,2) INSERT #T (A,B) VALUES (3,4) INSERT #T (A,B) VALUES (5,6)...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
8
by: Tweaxor | last post by:
Hey, I was trying to figure out was it possible in C to pass the values in an array from one function to another function. Is the possible in C? ex. y is the array that holds seven values If...
11
by: Sathyaish | last post by:
In a thread on JoS, Quickie asked, "Write a function in C that returns a function that adds x to its argument." http://discuss.fogcreek.com/joelonsoftware/default.asp?cmd=show&ixPost=146457 ...
2
by: mosesdinakaran | last post by:
Hi everybody, Today I faced a problem where I am very confused and I could not solve it and I am posting here.... My question is Is is possible to return a value to a particular function ...
7
by: Darko | last post by:
Hello, I have this particular problem with eval() when using Microsoft Internet Explorer, when trying to define an event handler. This is the code: function BigObject() { this.items = new...
160
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
21
by: coolguyaroundyou | last post by:
See the below code: void func(int x) { printf("%d",x); } int main() { int j=0;
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.