Hanoun Fouad Hanoun Fouad - 4 months ago 13
Vb.net Question

Continue writing in a second line of richtextbox

I have a function that converts an int to its actual string value, and it works constantly while I type the number in a textbox and the function converts it into a richtextbox.

The problem is that when it converts, i want to continue writing in a new line in the richtextbox so it can be printed as two lines on a paper.

Here is what i tried to do.

TextBox2.Text = " " & NumberToText(AmountBox.Text)
If TextBox2.Text.Length() > 60 Then
TextBox2.AppendText(Environment.NewLine)
End If


TextBox2 is the name of my richtextbox, and i chose 60 which is the average number of letters i want on my first line.

How can i let it continue converting the same number but on the second line ?

I want the output to be something like:


Four Hundreds Twenty Three Millions Four Hundreds Twenty -line1

Five Thousands Four Hundreds Twelve -line2


Any idea?

Answer

As Number to text as many return points you could use this intermediate function

Public Function NumberToTextSplitted(texto As String) As String
'Append this to what you are are already doing
Dim rtn as strin = NumberToText(texto)
Dim words As String() = rtn.Split(" ") 
Dim result As String = String.Empty

For Each word As String In words
    If line.Length + word.Length >= 59 Then
        result &= Environment.NewLine
    End If

    result &= " " & word
Next

Return result

End Function

Comments