README.md

December 4, 2022 ยท View on GitHub

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.

More Info

Submitted On
ByPhobos
LevelBeginner
User Rating3.8 (19 globes from 5 users)
CompatibilityVB 6.0
CategoryData Structures
WorldVisual Basic
Archive File

Source Code

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