Sub tableau() Dim tableau() As String Dim rep As String Dim cpt, i As Integer rep = "toto" cpt = 0 ReDim tableau(cpt) While Not rep = "" rep = InputBox("Veuillez entrer un nom") tableau(cpt) = rep cpt = cpt + 1 ReDim Preserve tableau(cpt) Wend cpt = cpt - 2 ReDim Preserve tableau(cpt) 'For i = 0 To cpt 'MsgBox ("Voici le nom " & i & " : " & tableau(i)) 'Next i Call trier(tableau) 'For i = 0 To cpt 'MsgBox ("Voici le nom " & i & " : " & tableau(i)) 'Next i Call ecrireFichier(tableau) End Sub Sub trier(tableau() As String) 'Cette fonction je l'ai trouvé sur le site (elle vient de Bubble44) Dim first As Long Dim last As Long Dim i As Long Dim noswap As Boolean Dim v As Variant first = LBound(tableau) last = UBound(tableau) last = last - 1 Do While first <= last noswap = True For i = first To last If tableau(i) > tableau(i + 1) Then v = tableau(i) tableau(i) = tableau(i + 1) tableau(i + 1) = v noswap = False End If Next i last = last - 1 If noswap Then Exit Do Loop End Sub Sub ecrireFichier(tableau() As String) Dim fso, fichier Dim i, cpt As Integer Dim nomFichier As String Set fso = CreateObject("Scripting.FileSystemObject") nomFichier = "toto" i = 0 'on vérifie que l'on écrit pas dans un fichier existant While fso.FileExists("D:\USER" & nomFichier & i & ".txt") i = i + 1 Wend nomFichier = "D:\USER" & nomFichier & i & ".txt" Set fichier = fso.CreateTextFile(nomFichier, True) For cpt = 0 To UBound(tableau) fichier.WriteLine (tableau(cpt)) Next cpt fichier.Close Set fso = Nothing Set fichier = Nothing MsgBox "Le fichier créé se nomme : " & nomFichier End Sub
Sub tableau() Dim tableau() As String Dim rep As String Dim cpt, i As Integer rep = "toto" cpt = 0 ReDim tableau(cpt) While Not rep = "" rep = InputBox("Veuillez entrer un nom") tableau(cpt) = rep cpt = cpt + 1 ReDim Preserve tableau(cpt) Wend cpt = cpt - 2 ReDim Preserve tableau(cpt) 'For i = 0 To cpt 'MsgBox ("Voici le nom " & i & " : " & tableau(i)) 'Next i Call trier(tableau) 'For i = 0 To cpt 'MsgBox ("Voici le nom " & i & " : " & tableau(i)) 'Next i Call ecrireFichier(tableau) End Sub Sub trier(tableau() As String) 'Cette fonction je l'ai trouvé sur le site (elle vient de Bubble44) Dim first As Long Dim last As Long Dim i As Long Dim noswap As Boolean Dim v As Variant first = LBound(tableau) last = UBound(tableau) last = last - 1 Do While first <= last noswap = True For i = first To last If tableau(i) > tableau(i + 1) Then v = tableau(i) tableau(i) = tableau(i + 1) tableau(i + 1) = v noswap = False End If Next i last = last - 1 If noswap Then Exit Do Loop End Sub Sub ecrireFichier(tableau() As String) Dim fso, fichier Dim i, cpt As Integer Dim nomFichier As String Set fso = CreateObject("Scripting.FileSystemObject") nomFichier = "toto" i = 0 'on vérifie que l'on écrit pas dans un fichier existant While fso.FileExists("D:\USER" & nomFichier & i & ".txt") i = i + 1 Wend nomFichier = "D:\USER" & nomFichier & i & ".txt" Set fichier = fso.CreateTextFile(nomFichier, True) For cpt = 0 To UBound(tableau) fichier.WriteLine (tableau(cpt)) Next cpt fichier.Close Set fso = Nothing Set fichier = Nothing MsgBox "Le fichier créé se nomme : " & nomFichier End Sub