by Phobos (6 Submissions)
Category: Data Structures
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (5 Votes)
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.
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