Maximum Row number in multiline textbox

AftPeakTank

Member
Joined
Apr 21, 2010
Messages
8
Programming Experience
Beginner
Hello all,

i am trying to put a maximum row number of lines in a multiline textbox.

What i want is to achieve something like a console, with a maximum number of rows, with the top rows to dissappear and to keep always the last i.e. 500 rows.

Thank you in advance!


a note: for the textbox text i use the following algorithm

dim text

textbox.text = textbox.text & vbcrlf & text


the problem is that after a certain number of rows the program starts to get a little slow. So i guess if i put a limit to the rows i will fix this.
 

oliverg

Active member
Joined
Apr 14, 2010
Messages
37
Programming Experience
1-3
VB.NET:
        If textbox.Lines.Count > 500 Then
            textbox.Text = textbox.Lines((textbox.Lines.Count - 500) - textbox.Lines.Count) & vbCrLf & text
        End If
But I would probably assign that count number once at the start to save on processing.
 

AftPeakTank

Member
Joined
Apr 21, 2010
Messages
8
Programming Experience
Beginner
VB.NET:
        If textbox.Lines.Count > 500 Then
            textbox.Text = textbox.Lines((textbox.Lines.Count - 500) - textbox.Lines.Count) & vbCrLf & text
        End If
But I would probably assign that count number once at the start to save on processing.

Iam really trying to understand what you mean here but i cant. In advance, the code doesnt seem to work (which i was afraid so). Maybe there is a typo or something...
 

AftPeakTank

Member
Joined
Apr 21, 2010
Messages
8
Programming Experience
Beginner
Ok i got it, a console like restriction of numbers of lines, in multiline textbox

Ok, there is the solution i came up for anyone who is interested:


VB.NET:
Dim strLines() As String = TextBox1.Lines

        If strLines.GetUpperBound(0) > maxlines - 1 Then
            Dim a As Integer
            Dim strtemp As String

            For a = 1 To strLines.GetUpperBound(0)
                If strtemp = Nothing Then
                    strtemp = strLines(a)
                Else
                    strtemp = strtemp & vbCrLf & strLines(a)
                End If
            Next
            TextBox1.Text = strtemp & vbCrLf & str
        Else
            TextBox1.Text = TextBox1.Text & vbCrLf & str
        End If
 
Top Bottom