'ouverture fichier open "c:\text.txt" for ouput as #1 'ecriture print #1, TB1 'fermeture fichier close #1
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question'On Error GoTo erreur Dim tablature As String Dim textline As String Dim i As Integer Dim Notes, Infos As Boolean 'initialisation txtauteur.Text = "" txttitre.Text = "" Txtinfo.Text = "" txtedition.Text = "" Notes = False Infos = False If MsgBox("Etes-vous sur de vouloir ouvrir un fichier ?" & vbCrLf & "Vous perdrez votre travail en cours.", vbOKCancel, "Effacer ?") = vbCancel Then Exit Sub ouverture.InitDir = App.Path ' le repertoire de l'application sera le repertoire initial du commonDialog ouverture.ShowOpen tablature = ouverture.FileName If tablature <> "" Then Open tablature For Input As #1 Do While Not EOF(1) Line Input #1, textline If Left(textline, 13) = "Composé par :" Then LongLig = Len(textline) txtauteur.Text = Right(textline, LongLig - 13) End If If Left(textline, 7) = "titre :" Then LongLig = Len(textline) txttitre.Text = Right(textline, LongLig - 7) End If If Left(textline, 29) = "Informations sur le morceau :" Then Infos = True End If If Left(textline, 11) = "Tablature :" Then Infos = False Notes = True End If If Infos = True And Left(textline, 29) <> "Informations sur le morceau :" And Left(textline, 28) <> "----------------------------" Then If Txtinfo.Text = "" Then Txtinfo.Text = textline Else Txtinfo.Text = Txtinfo.Text + vbCrLf + textline End If End If If Notes = True And Left(textline, 11) <> "Tablature :" Then If txtedition.Text = "" Then txtedition.Text = textline Else txtedition.Text = txtedition.Text + vbCrLf + textline End If End If Loop Close #1 End If
'// On recherche d'abort le nombre de lignes du TextBox '// et on stocke les lignes dans un tableau. Note : '// la deuxième valeur du tableau définit en combien on '// de chaine différente on doit diviser la chaine complète '// (c'est à dire combien de fois le nombre de caractère max '// est atteint) ReDim Chaines(1, 2) f = 2 TB1.Text = TB1.Text & Chr(10) LastF = 1 LastPos = 1 nbrChr = 0 maxl = 0 d = InStr(LastF, TB1.Text, Chr(10)) While Not d = 0 nbrChr = nbrChr + 1 ReDim Keep(nbrChr - 1, 2) For i = 1 To nbrChr - 1 Keep(i, 1) = Chaines(i, 1) Keep(i, 2) = Chaines(i, 2) Next i ReDim Chaines(nbrChr, 2) For i = 1 To nbrChr - 1 Chaines(i, 1) = Keep(i, 1) Chaines(i, 2) = Keep(i, 2) Next i Chaines(nbrChr, 1) = Mid(TB1.Text, LastPos, d - LastPos) Chaines(nbrChr, 2) = Int(Len(Mid(TB1.Text, LastPos, d - LastPos)) / 30) + 1 If Int(Len(Mid(TB1.Text, LastPos, d - LastPos)) / 30) + 1 > maxl Then maxl = Int(Len(Mid(TB1.Text, LastPos, d - LastPos)) / 30) + 1 LastF = d + 1 LastPos = LastF + 1 d = InStr(LastF, TB1.Text, Chr(10)) Wend '// Il faut remplacer les espaces par des "-" ici. Je te laisse '// rajouter ce code qui est simple. '// Maintenant que le tableau est rempli, on écrit le contenu '// du fichier : On Error Resume Next Open "C:/Text1.txt" For Output As #1 Print #1, "Tablatures :" For r = 1 To maxl For i = 1 To nbrChr If Chaines(i, 2) >= r Then ds = Mid(Chaines(i, 1), (r - 1) * 30 + 1, 30) If Len(ds) < 30 Then fg = 30 - Len(ds) For j 1 To fg: ds ds & "-": Next j End If Print #1, "|" & ds & "|" Else Print #1, "|------------------------------|" End If Next i Print #1, "" Next r Close #1