VB icon

Retuning multiple parameters from functions

Email
Submitted on: 1/23/2015 12:57:00 AM
By: Phobos (from psc cd)  
Level: Beginner
User Rating: By 5 Users
Compatibility: VB 6.0
Views: 610
 
     VB provides a very easy way in which to pass multiple parameters to subroutines and functions. Whilst it is possible to return the results of processing in the passed parameters it is not very good practice, but many programmers do it anyway because they believe that VB functions will only return one parameter. This simple example shows a clean method of returning as many parameters as you like from a function without resorting to modifying the passed parameters.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Retuning multiple parameters from functions
' Description:VB provides a very easy way in which to pass multiple parameters to subroutines and functions.
Whilst it is possible to return the results of processing in the passed parameters it is not very good practice, but many programmers do it anyway because they believe that VB functions will only return one parameter.
This simple example shows a clean method of returning as many parameters as you like from a function without resorting to modifying the passed parameters.
' By: Phobos (from psc cd)
'**************************************

Option Explicit
Type ReturnedParameters
Parameter1 As String
Parameter2 As Integer
Parameter3 As Boolean
End Type
Private Sub main()
' Simple test program which shows how to return multiple parameters
' from a function.
With TestFunction
MsgBox .Parameter1
MsgBox .Parameter2
MsgBox .Parameter3
End With
End Sub
Private Function TestFunction() As ReturnedParameters
' Example function showing how multiple parameters can be returned
Dim sString As String, iInteger As Integer, bBoolean As Boolean
sString = "Test String"
iInteger = 12345
bBoolean = True
With TestFunction
.Parameter1 = sString
.Parameter2 = iInteger
.Parameter3 = bBoolean
End With
End Function


Other 5 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.