Remonter dans un fichier texte en VBA

Résolu
cs_DeWaRs Messages postés 77 Date d'inscription vendredi 31 décembre 2004 Statut Membre Dernière intervention 6 septembre 2010 - 27 juil. 2009 à 11:54
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 - 27 juil. 2009 à 16:20
Bonjour,

Pour parcourir un fichier texte, je fait
  Open "\\frpar05\log\inventory_it.txt" For Input As #4
    

    
  Do While Not EOF(4)
  
  Line Input #4, cherche
  
 
  If InStr(1, cherche, TextBox_it_id.Text, 1) > 0 Then
   operator = Left(cherche, InStr(1, cherche, ";") - 1) ' On recherche le membre IT dans le fichier inventory.txt.
  End If
  
  Loop


Cela ouvre le fichier du début et fait une recherche dedans jusqu'a la fin.

Je veux faire l'inverse, ouvrir le fichier a la fin et faire une recherche jusqu'au début...

Merci d'avance.

DeWaRs

1 réponse

PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
27 juil. 2009 à 16:20
salut,

Private Sub Command1_Click()
    Dim FF As Integer, sBuffer As String, asFile() As String, i As Long
    Free = FreeFile()
    Open "\\frpar05\log\inventory_it.txt" For Binary As #FF
        sBuffer = String(LOF(FF), 0)
        Get #FF, , sBuffer
    Close #FF
    
    asFile = Split(sBuffer, vbCrLf)

    'dim cherche ???, operator??
    For i = UBound(asFile) To LBound(asFile) Step -1
        cherche = asFile(i)
        If InStr(1, cherche, TextBox_it_id.Text, 1) > 0 Then
            operator = Left(cherche, InStr(1, cherche, ";") - 1) ' On recherche le membre IT dans le fichier inventory.txt.
        End If
    Next i
 
    Erase asFile
End Sub


++
[hr]
3
Rejoignez-nous