Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning 2 pieces of data to Sub from Function

Status
Not open for further replies.

EddyLLC

Technical User
Mar 15, 2005
304
US
Is it possible to return two different values from a function when it is called. My situation is this, I am building a record into a variable called strWriteLine. I make a call to FD50, modify that record then return the modified record. This works fine. What I would like to do is return with the record a count of how many modifications were made. I keep track of this number in Function FD50 but can it be returned to the calling Public Sub?

Following is the calling code and the Function called

strWriteLine = FD50(strLine, InvNum,)
Function FD50(strLine As String, InvNo As String)
---Modify the strWriteLine as strLine
End Function
 
Declare your own data type:

Code:
Public Type TestUDT
    Val1 As String
    Val2 As Integer
End Type

Then make your function return that type:

Code:
Public Function FD50() As TestUDT
   ....function code here
End Function

When calling the function you need to specify which value you want to return like this:

strValue1=FD50.Val1
intValue2=FD50.Val2

Ed Metcalfe.

Please do not feed the trolls.....
 
Ed's suggestion is the all round neatest, but you can also pass an array or a concatenated string (depending on your data types). Then there are ByRef variables and module level variables as alternative approaches.

Cheers,
Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top