VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Retuning multiple parameters from functions

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.

Rate Retuning multiple parameters from functions

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

Download this snippet    Add to My Saved Code

Retuning multiple parameters from functions Comments

No comments have been posted about Retuning multiple parameters from functions. Why not be the first to post a comment about Retuning multiple parameters from functions.

Post your comment

Subject:
Message:
0/1000 characters