Results 1 to 5 of 5

Thread: [SOLVED] TextBox.Lines property

  1. #1

    Thread Starter
    Lively Member mindloop's Avatar
    Join Date
    Mar 2004
    Posts
    64

    Resolved [SOLVED] TextBox.Lines property

    Hey i am trying to simulate a console for my app so i'm using a textbox to show some output information.
    I am using following code for displaying info in the textbox:
    VB Code:
    1. private lineCount as integer = 0
    2. private sub addLine(byval newline as string)
    3. dim i as integer
    4. if lineCount >= 20
    5.    for i = 0 to 20
    6.       pInfo.Lines(i)=pInfo.Lines(i+1) ' pInfo is my textbox
    7.    next i
    8.    pInfo.Lines(20)= newline 'newline is the string i pass to the sub containing new info i need to show.
    9. else
    10.    pInfo.Lines(lineCount)=newline
    11.    lineCount=lineCount+1
    12. end if
    13. end sub
    yet nothing happens as if textbox.lines property were read only , yet i receive no error still my textbox remains unchanged.

    I initialised the textbox with property
    pInfo.Text = "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
    how should i approach this? i was so happy to have discovered .Lines property so i dont have to use string functions, but i feel like i'm missing something.
    Last edited by mindloop; Apr 21st, 2005 at 03:45 PM. Reason: SOLVED
    ehmm...

  2. #2
    Addicted Member
    Join Date
    Jan 2005
    Location
    Montréal
    Posts
    160

    Re: TextBox.Lines property

    just add the lines by appending a new line of text to the current text of the TextBox.
    VB Code:
    1. Public Property Lines() As String()
    The Lines member of TexBox is an array, so to add lines, you have to resize the array, which is a little odd only to add a line of text to your textbox.
    VB Code:
    1. TextBox1.Text += "newlineoftext" + Environment.NewLine
    There are no stupid questions, but a whole bunch of dumb sayings !

    Save time on database code, try DataLG !

  3. #3

    Thread Starter
    Lively Member mindloop's Avatar
    Join Date
    Mar 2004
    Posts
    64

    Re: TextBox.Lines property

    Hehe, dont think u got my problem right. i want to avoid scrollbar from appearing. therefor i want to make line no 2 become line no 3 and so on.
    adding lines would just fill my textbox and a scrollbar would appear.
    i need to handle lines by managing the string array Lines[]. but apparently i cant handle it as a regular string array since i cant replace say Lines[2] value with a new value let's say Lines[3]
    i initialised the array with blank lines. my textbox is fixed size therefor i only need to initialise 21 lines that's how much lines it can fit without scrolling.
    i dont need to resize the string array. i only need to reuse the defined elements.
    ehmm...

  4. #4
    Addicted Member
    Join Date
    Jan 2005
    Location
    Montréal
    Posts
    160

    Re: TextBox.Lines property

    try this :
    VB Code:
    1. Private lineCount As Integer = 0
    2.  
    3.     Private Sub addLine(ByVal newline As String)
    4.  
    5.         Dim asLines As String()
    6.  
    7.         If lineCount >= 20 Then
    8.             asLines = TextBox1.Lines
    9.             asLines(lineCount Mod 20) = newline
    10.             TextBox1.Lines = asLines
    11.         Else
    12.             TextBox1.Text += newline + Environment.NewLine
    13.         End If
    14.  
    15.         lineCount += 1
    16.  
    17.     End Sub

    Don't know why the intermediate array 'asLines' is necessary, but without it, the line doesn't get replaced. Anybody knows why?
    There are no stupid questions, but a whole bunch of dumb sayings !

    Save time on database code, try DataLG !

  5. #5

    Thread Starter
    Lively Member mindloop's Avatar
    Join Date
    Mar 2004
    Posts
    64

    Re: TextBox.Lines property

    thx worked.
    ehmm...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width