FONCTION GENERIQUE QUI RETOURNE UN TABLEAU

Résolu
cs_johnmary Messages postés 8 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 23 novembre 2004 - 7 nov. 2004 à 20:52
cs_johnmary Messages postés 8 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 23 novembre 2004 - 7 nov. 2004 à 22:09
Bonsoir à tous,

J'ai créé une fonction dans un module intitulé iofonctions.prg.

FUNCTION FolderListe()
PARAMETERS DrivePath
DIMENSION ThePaths(1024)
Inc=1
fsObject = CreateObject("Scripting.FileSystemObject")
RootFolder = fsObject.GetFolder(drivepath)
ChildFolders = RootFolder.SubFolders
For Each FolderFound In ChildFolders
thepaths(inc)=FolderFound.Name
inc=inc+1
NEXT
RETURN Thepaths
ENDFUNC

Cette fonction est appelée depuis un autre module comme
ceci :

.....
SET PROCEDURE TO iofonctions
DirRoutes=folderliste(Folder_Routes + "")

La variable DirRoutes me retourne uniquement une chaine,
mais pas le tableau Thepaths.

Ce que j'attends en fait dans DirRoutes, c'est une copie de Thepaths, pour traiter chaque élément du tableau.

Merci pour votre aide

2 réponses

cs_johnmary Messages postés 8 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 23 novembre 2004
7 nov. 2004 à 22:09
Impeccable, Thierry, merci beaucoup.

En plus tu m'apportes un plus sur la compréhension du
fonctionement des classes...

Place ce code dans les contributions ... ça va donner un
bon coup de main aux débutants ...

a+
3
ThierryPerretier Messages postés 103 Date d'inscription mardi 5 octobre 2004 Statut Membre Dernière intervention 6 juillet 2006 1
7 nov. 2004 à 21:48
Bonsoir,

De cette façon, ce n'est pas possible.

Je te propose d'écrire iofonctions.prg ce cette manière :

DEFINE CLASS ioFonctions as Custom

DIMENSION ThePaths(1024)
nbFolder = 0

FUNCTION FolderListe(DrivePath)
fsObject = CreateObject("Scripting.FileSystemObject")
RootFolder = fsObject.GetFolder(drivepath)
ChildFolders = RootFolder.SubFolders
this.nbFolder =0
FOR Each FolderFound In ChildFolders
this.nbFolder = this.nbFolder+1
this.thePaths(this.nbFolder)=FolderFound.Name
NEXT
RETURN this.nbFolder
ENDFUNC

ENDDEFINE

On l'utilise alors ainsi :

oIo=NewObject("ioFonctions","iofonctions.prg")
oIo.FolderListe("c:")
? oIo.ThePaths(1)
? oIo.ThePaths(2)
0
Rejoignez-nous