Advertisement
2_2002-2004 Coding Standards #126235

Returning Arrays From Functions

The following code demonstrates how to call a function and return multiple results in an array.

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
For example: You could have a function that returns error information which is called like this:
<br>
<br>
Private Sub MySub()
<br>
On Error GoTo err_handler
<br>
'....code here that rasies an error
<br>
err_handler:
<br>
If Err.Number <> 0 Then
<br>
 Dim Tmp() As String
<br>
 Tmp = ErrorHandler
<br>
 MsgBox "Error Description: " & Tmp(0) & " Error Number #:" & Tmp(1) & " Source: " & Tmp(2)
<br> 
Erase Tmp
<br>
End If
End Sub
<br>
<br>
<br>
<br>
Public Function ErrorHandler() As String()
<br>
Dim Errors(0 To 2) As String
<br>
 Errors(0) = Err.Description
<br>
 Errors(1) = Err.Number
<br>
 Errors(2) = Err.Source
<br>
 Err.Clear
<br>
 ErrorHandler = Errors
<br>
End Function
Оригинальные комментарии (3)
Восстановлено из Wayback Machine