Page 333 - Microsoft Office Excel 2003 Programming Inside Out
P. 333

Developing Class Modules

                             Property routines may also have one or more parameters. Typically, you would use parame­
                             ters with a property routine if you wanted to simulate an array. For example the following
                             code fragment declares a private class-level variable named MyNames, which is an array of
                             100 Strings. The code fragment also includes two property routines that make the property
                             appear as an array.

                             Private MyNames (99) As String
                             Public Property Get NameArray(index As Long) As String
                                                                                                             Chapter 14
                             NameArray = MyNames(index)
                             End Property

                             Public Property Let NameArray (index As Long, value as String)
                             MyNames = value

                             End Property

                             Note  You can specify as many parameters as you wish for the property routines. How-
                             ever, they must be identical between the Get and Let/Set routines, except for the very last
                             parameter in the Let/Set routine, which contains the value for the property.

                             Someone using the class might access the property like this:

                             MyObject.NameArray (10) = “Item 10 in the array”
                             Or like this:

                             MyVar = MyObject.NameArray (10)


                             Tip  Property Routines and Parameters
                             Although you can specify a list of parameters for a property routine, you should limit the use
                             of the parameters in a property routine to those parameters that make the property routine
                             look like an array. If you need to use parameters other than subscripts, you should consider
                             creating one or more methods with the parameters you need.
















                                                                                                       307
                                                                                                Part 4:  Advanced VBA
   328   329   330   331   332   333   334   335   336   337   338