Est-il possible de retourner un tableau avec une fonction ??

cs_enzino Messages postés 8 Date d'inscription lundi 4 février 2002 Statut Membre Dernière intervention 4 juin 2003 - 6 mai 2003 à 14:04
stevebelgium Messages postés 180 Date d'inscription lundi 17 mars 2003 Statut Membre Dernière intervention 7 juin 2003 - 6 mai 2003 à 15:05
Bonjour,
Je reviens avec mon problème de Fonction !!!
Je me suis fait mal comprendre lors de ma première question.

La question est : Est-il possible avec une fonction de retourner un tableau ???

Je vais vous détaillé mon problème.

Je lis dans un fichier toutes les lignes que je stock dans une variable "TextLine"
ex:
SEQUENCE Integer
NO_PARCELLE Char(10)
etc ....

Après cette variable j'aimerai la diriger vers une fonction qui va me spliter cette ligne dans un
tableau.
ex: résultat souhaité
TabChamps(1,1) = SEQUENCE
TabChamps(1,2) = Integer

TabChamps(2,1) = NO_PARCELLE
TabChamps(2,2) = Char(10)
etc ....

Mon but et de retouner le tableau TabChamps !!!

Merci d'avance !!


***************************** code ************************************************************************

Public Sub LectureFichierMif(sNomFichierMif)

Do While Not EOF(1) ' Effectue la boucle jusqu'à la fin du fichier.
Line Input #1, TextLine ' Lit la ligne dans la variable.
j = j + 1
ReDim TabChamps(j)
TabChamps(j) = FctSplitAttribut(Trim(TextLine)) ************ PROBLEME ***********

' rempli la listebox
Form1.Lst_ChoixAttribut.AddItem TabChamps(j)

Loop
Close #1

End sub

*******************************************************************************
'Ets-il possible que la fonction "FctSplitAttribut" me retourne un tableau ????

Public Function FctSplitAttribut(TextLine)

Dim TabListChamps() As String
Dim a As Integer
Dim Separateur As String

vSeparateur = " "
TabListChamps = Split(TextLine, vSeparateur)

For a = LBound(TabListChamps) To UBound(TabListChamps)
FctSplitAttribut = TabListChamps(a) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Next
End Function

2 réponses

cs_Crazyht Messages postés 1522 Date d'inscription mardi 18 décembre 2001 Statut Membre Dernière intervention 21 août 2010 8
6 mai 2003 à 14:56
Impossible de retourner un tableau mais utilise un argument ByRef pour le retour ca marche nikel :)

A++

Crazyht :)
0
stevebelgium Messages postés 180 Date d'inscription lundi 17 mars 2003 Statut Membre Dernière intervention 7 juin 2003 1
6 mai 2003 à 15:05
ce n'est pas vraiment une reponse a ta question mais si j'etais toi je le fesait comme ca .

tu a besion 1 fichier c:\a.txt avec ca dedans

SEQUENCE Integer
NO_PARCELLE Char(10)
SEQUENCE Integer

code :

Private Sub Command1_Click()

Dim TabChamps() As String
Dim x, y As Integer
Dim Temp As String

x = 0

Temp = ""

Open "c:\a.txt" For Input As #1

Do Until EOF(1)

Line Input #1, Temp
y = y + 1

Loop

Close #1

Open "c:\a.txt" For Input As #1

ReDim Preserve TabChamps(y - 1, 1)

Do Until EOF(1)

Line Input #1, Temp
x = x + 1
TabChamps(x - 1, 0) = Left(Temp, InStr(1, Temp, " "))
TabChamps(x - 1, 1) = Mid(Temp, InStr(1, Temp, " "))

Loop

Close #1

For x = 0 To UBound(TabChamps())
MsgBox "TabChamps(" & x & ",1) = " & TabChamps(x, 0) & Chr$(13) & _
"TabChamps(" & x & ",2) = " & TabChamps(x, 1)
Next x


End Sub

***********************
0
Rejoignez-nous