Bonjour à tous,
La commande INPUT réserve bien des surprises... La dernière en date, elle n'interprète pas LF comme le caractère de fin de ligne. Il existe de nombreux posts sur le sujet et l'explication donnée est que ce type de fichier est celui du monde NON WINDOWS.
Voir
RESOLVED-Cannot-read-a-file-line-by-line
Ici extrait ci-dessous
- a LF without a CR is UNIX, Linux, AmigaOS and now Mac -
- since Mac OS X.
- Until Mac OS version 9 the Mac was usung a single CR without
- a LF. Same for the Apple II.
- CR+LF is Windows, DOS, OS/2, CP/M, Atari TOS.
For the old teletypes you needed both CR + LF.
In the mid-seventies I saw a program using a teletype as "printer".
They used multiple CR without a LF to write columns.
With a teletype you had to send first the CR (carriage return) then
the LF (line feed) due to the latency time of the mechanical equipment.
If you did it the other way, the first character of the new line was
printed somewhere to the right, not in the leftmost position.
Helmut.
Je joins un fichier pour test et une routine pour vérification et la solution => l'utilisation de l'objet Objets TextStream
test.txt
Et la routine pour vérif.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 Public Function fReadflatFile() Dim fso As New FileSystemObject '-> Objet TextStream => librairie Microsoft Scripting Runtime Dim ts As TextStream Dim iIdxFic As Integer, iIdx As Integer Dim sLigne As String, sPath As String, sFile As String, sPathFile As String Dim vSplit As Variant sPath = "d:\" sFile = "test.txt" sPathFile = sPath & sFile iIdxFic = FreeFile Open sPathFile For Input As iIdxFic While Not EOF(iIdxFic) Line Input #iIdxFic, sLigne vSplit = Split(sLigne, ";") For iIdx = 0 To UBound(vSplit) - 1 '-> UBound retourne 12 car n'identifie qu'une seule ligne Debug.Print vSplit(iIdx) Next Wend Close iIdxFic '-------------------------------------------------------------- ' LA SOLUTION '-------------------------------------------------------------- Set ts = fso.OpenTextFile(sPathFile) Do While Not ts.AtEndOfStream sLigne = ts.ReadLine vSplit = Split(sLigne, ";") For iIdx = 0 To UBound(vSplit) - 1 Debug.Print vSplit(iIdx) Next Loop ts.Close Exit_: Set fso = Nothing Exit Function Err_: MsgBox Err.Number & Chr(13) & Err.Description, vbCritical, "critical error messaage" GoTo Exit_ End Function
Partager