Advertisement
2002ASP Data Structures #2745

Retuning multiple parameters from functions

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.

AI

สรุปโดย AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

ซอร์สโค้ด
original-source
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
ความคิดเห็นดั้งเดิม (3)
กู้คืนจาก Wayback Machine