Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake a VB6 function return an array
Keywordsfunction, array, return, VB6
CategoriesSoftware Engineering
 
New in VB6, functions can return arrays.

The program could invoke this function as in:

    Dim strings() As String

strings = NumberList()

This assignment may not work if the array is declared statically (using explicit bounds) and the bounds do not match those of the array returned by the function.

 
' Return an array of strings.
Private Function NumberList() As String()
Dim arr() As String
Dim i As Integer

    ReDim arr(1 To 10)
    For i = 1 To 10
        arr(i) = Format$(i) & " * " & Format$(i) & " = " & _
            Format$(i * i)
    Next i

    NumberList = arr
End Function

Private Sub Form_Load()
Dim strings() As String
Dim i As Integer

    ' Get the array of strings.
    strings = NumberList()

    ' Display the strings.
    For i = LBound(strings) To UBound(strings)
        If i >= 0 Then
            Load Label1(i)
            Label1(i).Top = Label1(i - 1).Top + Label1(i - _
                1).Height + 30
            Label1(i).Visible = True
        End If
        Label1(i).Caption = strings(i)
    Next i
End Sub
 
Formatted by Neil Crosby
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated