VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Returning Arrays From Functions

by Dale Cebula (3 Submissions)
Category: Coding Standards
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

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

Rate Returning Arrays From Functions

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

Download this snippet    Add to My Saved Code

Returning Arrays From Functions Comments

No comments have been posted about Returning Arrays From Functions. Why not be the first to post a comment about Returning Arrays From Functions.

Post your comment

Subject:
Message:
0/1000 characters