Instancier un dirlistbox etc... sans le mettre dans une form

misterzinzin Messages postés 112 Date d'inscription vendredi 27 octobre 2000 Statut Membre Dernière intervention 26 janvier 2011 - 2 mai 2005 à 21:08
misterzinzin Messages postés 112 Date d'inscription vendredi 27 octobre 2000 Statut Membre Dernière intervention 26 janvier 2011 - 3 mai 2005 à 20:56
voila, j'aimerais faire une fonction qui calcule la taille d'un repertoire...

le code est le suivant





Private Function taillepath(ByVal path As String) As Double

Dim dire As DirListBox

'Set dire = New DirListBox

dire.path = path

Dim file As FileListBox

'Set file = New FileListBox

file.path = path

Dim liste As ListBox

'Set liste = New ListBox

liste.Clear

taillepath = 0

Dim i As Integer

'dossier

i = 0

Do While i < dire.ListCount

liste.AddItem dire.List(i)

i = i + 1

Loop

Do While liste.ListCount

'fichier

i = 0

Do While i < File1.ListCount

taillepath = taillepath + FileLen(File1.path & "" & File1.List(i))

i = i + 1

Loop

dire.path = liste.List(0)

file.path = liste.List(0)

liste.RemoveItem (0)

i = 0

Do While i < dire.ListCount

liste.AddItem dire.List(i)

i = i + 1

Loop

Loop

End Function


cependant, il ne marche pas pour la simple et bonne raison qu'il
refuse tout acces au objet cree (Dim dire As DirListBox ok dire.path =
path marche plus!)

j'ai essaye avec un Set dire = New DirListBox (que l'on m'a conseillé)
mais cela ne marche tjs pas... je trouve qu'il serais dommage de devoir
coller un dirlistebox, un filelistbox et un listbox a chaque fois que
je veux utiliser cette fonction.... qui a l'avantage de ne pas reclamer
d'api (mais qui ne fonctionne pas diront certaint...)



des solution ?


moi, le seul, l'unique, ZinZin
A voir également:

2 réponses

Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
2 mai 2005 à 23:24
Private Function taillepath(ByVal path As String) As Long
Dim i As Integer
Dim j As Integer
Dim n As Integer
Dim t As Long

Dim dire As DirListBox
Set dire = Controls.Add("VB.DirListBox", "Dir1")
dire.path = path

Dim file As FileListBox
Set file = Controls.Add("VB.FileListBox", "File1")
file.path = path

Dim liste As ListBox
Set liste = Controls.Add("VB.ListBox", "List1")

For n = 0 To dire.ListCount - 1
liste.AddItem dire.List(n)
Next


Do While i < liste.ListCount
file.path = liste.List(i)
t = 0
For j = 0 To file.ListCount - 1
t = t + FileLen(file.path & "" & file.List(j))
Next
taillepath = taillepath + t
dire.path = liste.List(i)
For j = 1 To dire.ListCount
n = n + 1
liste.AddItem dire.List(n)
Next
i = i + 1
Loop

Controls.Remove dire
Controls.Remove file
Controls.Remove liste

End Function

Daniel
0
misterzinzin Messages postés 112 Date d'inscription vendredi 27 octobre 2000 Statut Membre Dernière intervention 26 janvier 2011 2
3 mai 2005 à 20:56
nickel :-) merci bcp... ca servira ptetre a d'autre personne (par
contre g des doute sur les resultat que me renvois ma fonction...

moi, le seul, l'unique, ZinZin
0
Rejoignez-nous