Option Explicit Dim Arret As Boolean Sub Depart() Application.OnTime Now + TimeValue("00:16:39"), "LectureFichier" End Sub Sub ArretLecture() Arret = True End Sub Sub LectureFichier() Dim Nom As String Dim Canal As Integer Dim InputData As String Dim Ligne As Long Dim J As Long Dim Indice As Integer If Arret = True Then Exit Sub Application.ScreenUpdating = False Nom = ThisWorkbook.Path & "\TrameRx_IP.DAT" ' Création de la feuille 'Indice = 1 On Error Resume Next Do 'Err.Clear Indice = Indice + 1 Sheets("Enreg " & Indice).Visible = True Loop Until Err.Number > 0 On Error GoTo 0 Sheets.Add after:=Sheets(Sheets.Count) ActiveSheet.Name = "Enreg " & Indice Range("A1") = Now Ligne = 1 ' Récupération du fichier Canal = FreeFile() Open Nom For Input As #Canal Do While Not EOF(Canal) ' Vérifie si la fin du fichier est atteinte. Line Input #Canal, InputData ' Lit les lignes de données (normalement 1 ligne) For J = 1 To Len(InputData) Step 800 Ligne = Ligne + 1 Range("A" & Ligne) = Trim(Mid(InputData, J, 800)) Next J Loop Close #Canal ' Ferme le fichier. Columns("A").AutoFit ThisWorkbook.Save Application.OnTime Now + TimeValue("00:16:39"), "LectureFichier" End Sub
C'est un fichier à accès random et il contient 500 messages. Après 500 messages il supprime les messages précédents et faire une nouvelle sauvegarde .
Function FileTrameInput(mode As Integer, Trame As String) As String*
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionEst-ce :
1) ce que tu veux qu'il fasse ?
ou
2) ce qu'il fait ?
Après un enregistrement de 500 évènements il supprime
ucfoutu, Ce que je veux que ce code fasse est:
Lire dans le fichier TrameRx-IP.DAT récupérer le contenu et le sauvegarder dans un autre fichier.
option explicit Private Sub lire() Dim intfic As Integer Dim strligne As String intfic = FreeFile Const NbMesrx = 500 Dim gintPtReti As integer Dim gintPtWrti As integer Dim FileTrameInput as string Dim bufFile As String * 800 Path = App.path & "\TrameRx_IP.DAT" Open path For Random As intfic len =len(bufFile) Do while Not EOF (1) = True Get #intfic, 1, bufFile gintPtReti = Val(Mid(bufFile, 1, 5)) gintPtWrti = Val(Mid(bufFile, 6, 10)) ' Lecture trame ' Test des limites pointeur lecture If gintPtReti > NbMesrx Or gintPtReti < 2 Then gintPtReti = 2 Else gintPtReti = gintPtReti + 1 End If bufFile = Format(gintPtReti, "00000") & Format(gintPtWrti, "00000") Get #intfic, gintPtReti, bufFile FileTrameInput = Trim(bufFile) loop Close #intfic End Sub
- or rien ne garantira jamais que ton appli/timer interviendra pile-poil et à tous coups entre le 500ème et le 501ème enregistrement.