Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class Module Array 1

Status
Not open for further replies.

chutney66

Programmer
Jan 20, 2006
11
Hi there,

I want to use an array as a property for a class module. I am used to using classes and know a little about arrays but don't know how to use an array in a class. Does anyone have some simple examples?

What I am doing is trying to store several names of tables in a single class property so I can loop through the property. I need to be able to add a table name to the property array and loop through them.

Any help much appreciated - I have searched on this in many places and have not been able to find much help.
 
It's fairly easy with variants
Code:
Option Explicit
Private mvarMyArray                 As Variant

Public Property Let myArray(VData As Variant)
    mvarMyArray = VData
End Property

Public Property Get myArray() As Variant
    myArray = mvarMyArray
End Property

and use it with something like

Code:
Private Sub Command12_Click()
    Dim CL                          As New Class1
    Dim ar()                        As String
    Dim n                           As Integer
    Dim a(0 To 2)                   As String

    a(0) = "a"
    a(1) = "b"
    a(2) = "c"
    CL.myArray = a
    
    ar = CL.myArray
    For n = LBound(ar) To UBound(ar)
        Debug.Print ar(n)
    Next
End Sub
 
Thank you very much. It looks so simple now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top