[VB]Ajouter un caractère sur toutes les lignes d'un fichier text

Fermé
Ordibug? Messages postés 105 Date d'inscription dimanche 18 novembre 2012 Statut Membre Dernière intervention 9 décembre 2015 - 27 mars 2015 à 23:47
ccm81 Messages postés 10854 Date d'inscription lundi 18 octobre 2010 Statut Membre Dernière intervention 26 avril 2024 - 28 mars 2015 à 15:08
Bonjour,
j'ai un fichier text avec des centaines de lignes de MD5. Donc il y'a des des lettres et nombres ! Et moi je veux créer un logiciel où donc je parcours le fichier text, et ensuite j'appuie sur un bouton, et sur chaque lignes de MD5 ça fasse ça : b08029b47a99f94e7a36224039cb2830|
l'histoire que ça m'évite de le faire manuellement :/
merci d'avance
A voir également:

2 réponses

cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 728
28 mars 2015 à 13:51
Bonjour,

En vba avec Excel:

Faire Alt F11 pour accéder à l'éditeur.
Insertion-UserForm
Mettre 2 boutons et une Listbox avec ce code:

Option Explicit
'allez dans Outils- Options et cocher reference Microsoft Scripting Runtime
Private Sub CommandButton1_Click()
lire
CommandButton2.Enabled = True
End Sub
Private Sub CommandButton2_Click()
ecrire
End Sub
Sub ecrire()
Dim oFSO As Scripting.FileSystemObject
Dim oFl As Scripting.File
Dim oTxt As Scripting.TextStream
Dim i As Integer
'Instanciation du FSO
Set oFSO = New Scripting.FileSystemObject
Set oFl = oFSO.GetFile("C:\chemin\fichier.txt") 'chemin fichier texte
Set oTxt = oFl.OpenAsTextStream(ForWriting)
With oTxt
    For i = 0 To ListBox1.ListCount - 1
        .WriteLine ListBox1.List(i) & "b08029b47a99f94e7a36224039cb2830|"
    Next i
End With
End Sub
Sub lire()
Dim oFSO As Scripting.FileSystemObject
Dim oFl As Scripting.File
Dim oTxt As Scripting.TextStream
'Instanciation du FSO
Set oFSO = New Scripting.FileSystemObject
Set oFl = oFSO.GetFile("C:\chemin\fichier.txt") 'chemin fichier texte
Set oTxt = oFl.OpenAsTextStream(ForReading)
With oTxt
    While Not .AtEndOfStream
       ListBox1.AddItem (.ReadLine)
    Wend
End With
End Sub
Private Sub UserForm_Initialize()
CommandButton1.Caption = "Lire"
CommandButton2.Caption = "Ecrire"
CommandButton2.Enabled = False
End Sub

0
ccm81 Messages postés 10854 Date d'inscription lundi 18 octobre 2010 Statut Membre Dernière intervention 26 avril 2024 2 404
Modifié par ccm81 le 28/03/2015 à 15:13
Bonjour

Un mini-exemple pour ajouter le caractère | en fin de chaque ligne, un peu plus sommaire que celui de cs_Le Pivert que je salue au passage.

Option Explicit

Const chemin = "D:\"
Const nomFI = "trucIn.txt"
Const nomFO = "trucOut.txt"

Private Sub btOK_Click()
Dim ficIn, ficOut, buffer As String
  'nom fichier
  ficIn = chemin & nomFI
  ficOut = chemin & nomFO
  Open ficIn For Input As #1
  Open ficOut For Output As #2
  Do While Not EOF(1)
    'lecture enregistremnt
    Line Input #1, buffer
    buffer = buffer & "|"
    Print #2, buffer
  Loop
  Close #1
  Close #2
End Sub

Cdlmnt
0