ColFiles, classes, collection
Bonjour à tous,
j'essai de comprendre les classes, user control, etc....
j'ai pompé un exemple de Collections dans Msdn (doc=Colfiles )
Mais je n'ai pas tout compris, et cela ne fonctionne pas.
si qq'un à du temps de libre, merci à lui
si joint ce bout de code
Form:
Code:
1 2 3 4 5
| Dim objfile As New JaCls1
Private Sub Form_Load()
objfile.Path = "D:\data\exercices"
ColFiles.add objfile, objfile
End Sub |
JaCls1: (module de classe)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| Private JamFiles As New Collection ' old = pcolfiles
Public Function add(Path As String) As JaCls1 ' old = file
Dim objfile As JaCls1
Set objfile = New JaCls1
objfile.Path = Path
JamFiles.add objfile
Set add = objfile
End Function
Public Function Item(Key As Variant) As JaCls1
' Return an item in the collection.
Set Item = JamFiles.Item(Key)
End Function
Public Sub Remove(Key As Variant)
' Remove an item from the collection.
JamFiles.Remove Key
End Sub
Property Get Count() As Long
' Return the number of items.
Count = JamFiles.Count
End Property
' Private variable to store path.
Private pstrPath As String
Property Get Path() As String
' Return stored path value.
Path = pstrPath
End Property
Property Let Path(strPath As String)
Dim strFile As String
' Clear the collection.
Set JamFiles = New Collection
' Make sure there's a backslash.
If Right(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
' Get the first file.
strFile = Dir(strPath & "*.*", _
vbReadOnly Or vbHidden Or vbArchive Or vbSystem)
Do Until Len(strFile) = 0
' Add it to the collection.
Call add(strPath & strFile)
' Get the next file.
strFile = Dir()
Loop
' Save the path.
pstrPath = strPath
End Property |