none
MultiLineTextBox add lines RRS feed

  • Question

  • Hi to all.

    The following code should print each number on a different line of control MultiLineTextBox, but it does not work. Why ?

    Tab = Controls.AddMultiLineTextBox(0,0)
    For r=0 to 1000
    Controls.SetTextBoxText(Tab,r + Text.GetCharacter(10) + Text.GetCharacter(13))
    EndFor

    All numbers are printed on a line.

    Best Regards


    • Edited by BluStars Sunday, July 16, 2017 1:59 PM
    Sunday, July 16, 2017 12:46 PM

Answers

  • The data that you set in nthe textbox needs to be all the lines.

    Therefore when we add a line to the data we need to append (add it to the end of the last data).

    tbData is the data that we are building up line by line from the values of r.

    Consider this line:

    tbData = Text.Append(tbData,r)+Text.GetCharacter(10)

    It appends r (and LF) to the current value of tbData

    But

    tbData = Text.Append("",r)+Text.GetCharacter(10)

    appends r (and LF) to "", which is the same as just setting it to r+LF

    Run the following to see:

    tbData = ""
    For r = 0 to 3
      tbData = Text.Append(tbData,r)+Text.GetCharacter(10)
      TextWindow.WriteLine(tbData)
    EndFor

    And

    tbData = ""
    For r = 0 to 3
      tbData = Text.Append("",r)+Text.GetCharacter(10)
      TextWindow.WriteLine(tbData)
    EndFor

    Or

    tbData = ""
    For r = 0 to 3
      tbData = r+Text.GetCharacter(10)
      TextWindow.WriteLine(tbData)
    EndFor

    Sunday, July 16, 2017 2:21 PM
    Moderator

All replies

  • Your code doesn't run, I presume the first line should be:

    Tab = Controls.AddMultiLineTextBox(0,0)

    Inside the loop you just whrite one line then replace it with a new line.  To add it to the existing lines, try appending the new lines.

    Tab = Controls.AddMultiLineTextBox(0,0)
    tbData = ""
    
    For r=0 to 1000
      tbData = Text.Append(tbData,r)+Text.GetCharacter(10)
      Controls.SetTextBoxText(Tab,tbData)
    EndFor

    Or perhaps better

    Tab = Controls.AddMultiLineTextBox(0,0)
    
    tbData = ""
    For r=0 to 1000
      tbData = Text.Append(tbData,r)+Text.GetCharacter(10)
    EndFor
    Controls.SetTextBoxText(Tab,tbData)


    Sunday, July 16, 2017 12:53 PM
    Moderator
  • It works, thank you.

    But I do not understand how it works.

    Because it does not work so rewritten:

    tbData = Text.Append("",r)+Text.GetCharacter(10)

    Thanks

    Sunday, July 16, 2017 2:04 PM
  • The data that you set in nthe textbox needs to be all the lines.

    Therefore when we add a line to the data we need to append (add it to the end of the last data).

    tbData is the data that we are building up line by line from the values of r.

    Consider this line:

    tbData = Text.Append(tbData,r)+Text.GetCharacter(10)

    It appends r (and LF) to the current value of tbData

    But

    tbData = Text.Append("",r)+Text.GetCharacter(10)

    appends r (and LF) to "", which is the same as just setting it to r+LF

    Run the following to see:

    tbData = ""
    For r = 0 to 3
      tbData = Text.Append(tbData,r)+Text.GetCharacter(10)
      TextWindow.WriteLine(tbData)
    EndFor

    And

    tbData = ""
    For r = 0 to 3
      tbData = Text.Append("",r)+Text.GetCharacter(10)
      TextWindow.WriteLine(tbData)
    EndFor

    Or

    tbData = ""
    For r = 0 to 3
      tbData = r+Text.GetCharacter(10)
      TextWindow.WriteLine(tbData)
    EndFor

    Sunday, July 16, 2017 2:21 PM
    Moderator
  • It's clear ! Thanks.
    • Proposed as answer by jricestkEditor Thursday, July 20, 2017 1:25 AM
    • Unproposed as answer by jricestkEditor Thursday, July 20, 2017 1:25 AM
    Sunday, July 16, 2017 8:10 PM
  • Here is an extension method to 'Append a string to the contents of a text control.' , using

    LitDev_LDInline and TextBoxBase.AppendText Method (String)

    ID: FXF356

    Friday, September 1, 2017 1:56 PM
    Answerer