| 1 |
VERSION 1.0 CLASS |
| 2 |
BEGIN |
| 3 |
MultiUse = -1 'True |
| 4 |
Persistable = 0 'NotPersistable |
| 5 |
DataBindingBehavior = 0 'vbNone |
| 6 |
DataSourceBehavior = 0 'vbNone |
| 7 |
MTSTransactionMode = 0 'NotAnMTSObject |
| 8 |
END |
| 9 |
|
| 10 |
'http://www.vbforums.com/showthread.php?374132-A-basic-example-of-Class-Modules |
| 11 |
'file = Class Sample (game).zip |
| 12 |
|
| 13 |
Attribute VB_Name = "cItems" |
| 14 |
Attribute VB_GlobalNameSpace = False |
| 15 |
Attribute VB_Creatable = True |
| 16 |
Attribute VB_PredeclaredId = False |
| 17 |
Attribute VB_Exposed = False |
| 18 |
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes" |
| 19 |
Attribute VB_Ext_KEY = "Collection" ,"cItem" |
| 20 |
Attribute VB_Ext_KEY = "Member0" ,"cItem" |
| 21 |
Attribute VB_Ext_KEY = "Top_Level" ,"Yes" |
| 22 |
Option Explicit |
| 23 |
|
| 24 |
'local variable to hold collection |
| 25 |
Private mCol As Collection |
| 26 |
|
| 27 |
Public Function Add( _ |
| 28 |
ItemType As eItemTypes, _ |
| 29 |
Value As Long, _ |
| 30 |
Rarity As Long, _ |
| 31 |
Optional ItemName As String, _ |
| 32 |
Optional sKey As String) As cItem |
| 33 |
'create a new object |
| 34 |
Dim objNewMember As cItem |
| 35 |
Set objNewMember = New cItem |
| 36 |
|
| 37 |
|
| 38 |
'set the properties passed into the method |
| 39 |
objNewMember.Value = Value |
| 40 |
objNewMember.Rarity = Rarity |
| 41 |
If Len(sKey) = 0 Then |
| 42 |
mCol.Add objNewMember |
| 43 |
Else |
| 44 |
mCol.Add objNewMember, sKey |
| 45 |
End If |
| 46 |
|
| 47 |
|
| 48 |
'return the object created |
| 49 |
Set Add = objNewMember |
| 50 |
Set objNewMember = Nothing |
| 51 |
|
| 52 |
|
| 53 |
End Function |
| 54 |
|
| 55 |
Public Property Get Item(vntIndexKey As Variant) As cItem |
| 56 |
Attribute Item.VB_UserMemId = 0 |
| 57 |
'used when referencing an element in the collection |
| 58 |
'vntIndexKey contains either the Index or Key to the collection, |
| 59 |
'this is why it is declared as a Variant |
| 60 |
'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5) |
| 61 |
Set Item = mCol(vntIndexKey) |
| 62 |
End Property |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
Public Property Get Count() As Long |
| 67 |
'used when retrieving the number of elements in the |
| 68 |
'collection. Syntax: Debug.Print x.Count |
| 69 |
Count = mCol.Count |
| 70 |
End Property |
| 71 |
|
| 72 |
|
| 73 |
Public Sub Remove(vntIndexKey As Variant) |
| 74 |
'used when removing an element from the collection |
| 75 |
'vntIndexKey contains either the Index or Key, which is why |
| 76 |
'it is declared as a Variant |
| 77 |
'Syntax: x.Remove(xyz) |
| 78 |
|
| 79 |
|
| 80 |
mCol.Remove vntIndexKey |
| 81 |
End Sub |
| 82 |
|
| 83 |
|
| 84 |
Public Property Get NewEnum() As IUnknown |
| 85 |
Attribute NewEnum.VB_UserMemId = -4 |
| 86 |
Attribute NewEnum.VB_MemberFlags = "40" |
| 87 |
'this property allows you to enumerate |
| 88 |
'this collection with the For...Each syntax |
| 89 |
Set NewEnum = mCol.[_NewEnum] |
| 90 |
End Property |
| 91 |
|
| 92 |
|
| 93 |
Private Sub Class_Initialize() |
| 94 |
'creates the collection when this class is created |
| 95 |
Set mCol = New Collection |
| 96 |
End Sub |
| 97 |
|
| 98 |
|
| 99 |
Private Sub Class_Terminate() |
| 100 |
'destroys collection when this class is terminated |
| 101 |
Set mCol = Nothing |
| 102 |
End Sub |
| 103 |
|