Private Sub Command1_Click() Dim s As String Dim l As Integer l = 10 'nb de caractères à enregistrer ' On supprime les retours ligne s'il y en a dans le texte s = Trim(Replace(Text1.Text, vbCrLf, " ")) Open "c:\blablabla.txt" For Output As 1 Do While Len(s) > 0 If Len(s) >= l Then Print #1, Left$(s, l) s = Right$(s, Len(s) - l) Else Print #1, Left$(s, Len(s)) s = "" End If Loop Close #1 End Sub
Private Sub Command1_Click() Dim s As String Dim s1 As String Dim l As Integer Dim i As Integer, j As Integer Dim t() As String l = 10 'nb de caractères à enregistrer ' On supprime les retours ligne s'il y en a dans le texte s = Trim(Replace(Text1.Text, vbCrLf, " ")) ' on découpe la chaine en mots t = Split(s, " ") Open "c:\blablabla.txt" For Output As 1 For i = LBound(t) To UBound(t) If Len(t(i)) >= l Then Print #1, t(i) ' pour les mots plus longs que l ou égaux à l Else s1 = t(i) ' on mémorise un 1er mot For j = i + 1 To UBound(t) ' on rajoute des mots sans dépasser l If Len(s1 & " " & t(j)) <= l Then s1 = s1 & " " & t(j) i = i + 1 Else Exit For End If Next Print #1, s1 End If Next Close #1 End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub Command7_Click() Dim s As String Dim l As Integer l = 50 'nb de caractères à enregistrer ' On supprime les retours ligne s = Trim(Replace(Text2.Text, vbCrLf, " ")) Open App.Path & "" & Text22 & ".txt" For Output As 1 Do While Len(s) > 0 If Len(s) >= l Then MsgBox Left$(s, l) buffer = Right$(s, Len(s) - l) Else MsgBox Left$(s, Len(s)) s = "" End If Loop End Sub Close #1