Il problema sta nello spazio separatore tra la
parola che riesce ad essere inclusa nel limite dei caratteri
per riga e quella che eccede.
VB NET non inserisce uno spazio 'reale', ovvero il carattere
chr(32) ma il chr(20).
Rimetti questa funzione al posto della precedente.
In questa funzione vengono rimpiazzati anche gli spazi dicodice:Public Function ParseTextBox(RowLen As Integer, RowText As String ) As String Dim sRet, sToken As String Dim nC As Integer Dim sCR as string = Microsoft.VisualBasic.Constants.vbCrLf Dim c20 As String = Microsoft.VisualBasic.chr(20) Dim mRowText As String ' Rimpiazza tutti i CRLF con degli spazi ' -------------------------------------- mRowText = Microsoft.VisualBasic.Replace(RowText, sCR," ") ' Rimpiazza tutti i chr(20) con degli spazi ' -------------------------------------- mRowText = Microsoft.VisualBasic.Replace(RowText, c20," ") sRet = "" nC = 0 Do While Len(mRowText) > 0 ' Se la lunghezza dela strimga rimanente Š minore ' della larghezza massima, aggiungo la romanenza ed esco If Microsoft.VisualBasic.Len(mRowText) < RowLen Then sRet = sRet + sCR + mRowText Exit Do End If if RowLen > nC then sToken =Microsoft.VisualBasic.Mid(mRowText,1,(RowLen - nC)) Else exit do End if If Microsoft.VisualBasic.Right(sToken,1) <> " " Then nC = nC + 1 Else sRet = sRet + sCR + sToken mRowText = Microsoft.VisualBasic.Mid(mRowText, (RowLen - nC)) nC = 0 End If Loop Return sRet End Function
tipo chr(20) con spazi 'veri' (di tipo chr(32)).
La chiamata resta come ti avevo suggerito :
codice:strDoc = strDoc + ParseTextBox(40, TextBox1.Text) + vbCrLf + vbCrLf
Ciao,
Brainjar.![]()

Rispondi quotando
