Tools Links Login

Returning Arrays From Functions

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

Original Author: Dale Cebula

Code

For example: You could have a function that returns error information which is called like this:




Private Sub MySub()


On Error GoTo err_handler


'....code here that rasies an error


err_handler:


If Err.Number <> 0 Then


Dim Tmp() As String


Tmp = ErrorHandler


MsgBox "Error Description: " & Tmp(0) & " Error Number #:" & Tmp(1) & " Source: " & Tmp(2)


Erase Tmp


End If
End Sub








Public Function ErrorHandler() As String()


Dim Errors(0 To 2) As String


Errors(0) = Err.Description


Errors(1) = Err.Number


Errors(2) = Err.Source


Err.Clear


ErrorHandler = Errors


End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 76 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.