Ouvrir fichier 100 par 100 line

cs_simon0000 Messages postés 90 Date d'inscription lundi 25 juillet 2005 Statut Membre Dernière intervention 18 janvier 2006 - 17 août 2005 à 21:19
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 - 18 août 2005 à 00:30
bonsoir
comment je peux ouvrir un fichier txt 100 par 100 line ca ve dir de la line de a la line a
List1.Clear
Dim lgdata As String
Open "D:\1.txt" For Input As #1
For i = de To a
Input #1, lgdata
List1.AddItem lgdata
Next i
Close #1

merci a+

4 réponses

Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
17 août 2005 à 22:07
si tu veux 100 lignes à chaque fois faut pas fermer le fichier.


Open "D:\1.txt" For Input As #1



'les 100 premières Lignes

List1.Clear

call Lecture



'les 100 suivantes

List1.Clear


call Lecture



etc.....



et Close#1 à la fin



Private Sub Lecture()

Dim i As Integer

Dim lgdata As String

For i = de To a

Input #1, lgdata

List1.AddItem lgdata

Next i

End Sub


Daniel
0
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
17 août 2005 à 22:41
si tu veux lire en arrière c'est plus dur.

à part relire le fichier à chaque fois depuis le début, voici une autre solution:







Option Explicit



Dim Table() As Long

Dim nb As Long

Dim numero As Integer



Private Sub Form_Load()

Dim i As Integer

Dim lgdata As String

Dim pos As Long



i 100: pos 1

Open "D:\1.txt" For Input As #1

While Not EOF(1)

If i = 100 Then

nb = nb + 1

ReDim Preserve Table(nb)

Table(nb) = pos

i = 0

End If

Input #1, lgdata

pos = pos + Len(lgdata) + 2

i = i + 1

Wend

Close #1

ReDim Preserve Table(nb + 1)

Table(nb + 1) = pos



Open "D:\1.txt" For Binary As #1

numero = 1

Call Lecture(numero)



End Sub



Private Sub CmdSuivant_Click()

If numero < nb Then

numero = numero + 1

Call Lecture(numero)

End If

End Sub



Private Sub CmdPrecedent_Click()

If numero > 1 Then

numero = numero - 1

Call Lecture(numero)

End If

End Sub



Private Sub Lecture(n As Integer)

Dim i As Integer

Dim Buffer As String

Dim debut As Long

Dim fin As Long

Dim T() As String



List1.Clear

debut = Table(n)

fin = Table(n + 1)

Seek #1, debut

Buffer = Space$(fin - debut)

Get #1, , Buffer

T = Split(Buffer, vbCrLf)

For i = 0 To UBound(T) - 1

List1.AddItem i & " " & T(i)

Next

End Sub



Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

Close #1

End Sub


Daniel
0
cs_simon0000 Messages postés 90 Date d'inscription lundi 25 juillet 2005 Statut Membre Dernière intervention 18 janvier 2006
18 août 2005 à 00:21
ca marche merci
0
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
18 août 2005 à 00:30
si la réponse te satisfait tu peux cliquer sur 'Réponse acceptée"

merci.


Daniel
0
Rejoignez-nous