New Line in TextBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dr3amxstar
    New Member
    • May 2007
    • 55

    New Line in TextBox

    Hi.. Would really be glad to have some help on textBox .

    From what i know of textbox , the old value that u assign to it will always be replace by the new ones. Example :

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim array(4) As String
            array(0) = 6
            array(1) = 6
            array(2) = 6
            array(3) = 6
            array(4) = 6
            For n As Integer = 0 To 4
                
                TextBox1.Text = array(n)
    
            Next
    
        End Sub
    The output will only be one 6 on the textBox. However i want five 6 to be listed on the textbox. Is there a line break or something so that i can print all things in the array? I know i can use the listbox to achieve that but then i am not able to copy the words from the listbox
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by dr3amxstar
    Hi.. Would really be glad to have some help on textBox .

    From what i know of textbox , the old value that u assign to it will always be replace by the new ones. Example :

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim array(4) As String
            array(0) = 6
            array(1) = 6
            array(2) = 6
            array(3) = 6
            array(4) = 6
            For n As Integer = 0 To 4
                
                TextBox1.Text = array(n)
    
            Next
    
        End Sub
    The output will only be one 6 on the textBox. However i want five 6 to be listed on the textbox. Is there a line break or something so that i can print all things in the array? I know i can use the listbox to achieve that but then i am not able to copy the words from the listbox

    Make the TextBox Property Multi line =True

    and

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim array(4) As String
            array(0) = 6
            array(1) = 6
            array(2) = 6
            array(3) = 6
            array(4) = 6
            For n As Integer = 0 To 4
                
                TextBox1.Text = array(n) & vbcr
    
            Next
    
        End Sub

    Comment

    • dr3amxstar
      New Member
      • May 2007
      • 55

      #3
      Originally posted by hariharanmca
      Make the TextBox Property Multi line =True

      and

      Code:
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              Dim array(4) As String
              array(0) = 6
              array(1) = 6
              array(2) = 6
              array(3) = 6
              array(4) = 6
              For n As Integer = 0 To 4
                  
                  TextBox1.Text = array(n) & vbcr
      
              Next
      
          End Sub
      Hi i have set the multiline to true and edit this line
      TextBox1.Text = array(n) & vbcr

      However the output display is still the same. only one 6

      Comment

      • dr3amxstar
        New Member
        • May 2007
        • 55

        #4
        hihi forgot to mention that i am using VB 2005 express edition. Thanks!

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by dr3amxstar
          hihi forgot to mention that i am using VB 2005 express edition. Thanks!
          This is a fundamental rule - assigning a value to a property or variable replaces what was there previously. You cannot append a value to it.

          What you need to do is think carefully about what you want to put there. In a case like this, what you want to put there is the old value plus the new value, isn't it? So put that in there.

          Comment

          • hariharanmca
            Top Contributor
            • Dec 2006
            • 1977

            #6
            Originally posted by dr3amxstar
            hihi forgot to mention that i am using VB 2005 express edition. Thanks!

            what'er Vb version this is also a way. okay Explain your problem with some other example...

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              I'll give you another hint.

              If you have a string variable, and you want to add something onto the end of it, what do you do?

              Let's say MyString = "ABC"
              How would you add, say, a "D" onto the end, using code?
              You do the same with a textbox.

              Comment

              • hariharanmca
                Top Contributor
                • Dec 2006
                • 1977

                #8
                Originally posted by Killer42
                I'll give you another hint.

                If you have a string variable, and you want to add something onto the end of it, what do you do?

                Let's say MyString = "ABC"
                How would you add, say, a "D" onto the end, using code?
                You do the same with a textbox.

                okay I got the prob,

                Code:
                Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                        Dim array(4) As String
                        array(0) = 6
                        array(1) = 6
                        array(2) = 6
                        array(3) = 6
                        array(4) = 6
                        TextBox1.Text = ""
                        For n As Integer = 0 To 4
                            
                            TextBox1.Text = TextBox1.Text & array(n)  
                        Next
                 
                    End Sub
                
                
                Change the Code line to : 
                              TextBox1.Text = TextBox1.Text & array(n) & vbcr

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  Oh nuts! I was trying to encourage dr3amxstar to work it out.

                  Oh well...

                  Keep in mind dr3amxstar, you only want to add on the vbcrlf (actually, I'd recommend vbNewLine) if you want a line break between the values. You can stick them together without the breaks.

                  Comment

                  • hukam
                    New Member
                    • Jun 2007
                    • 8

                    #10
                    hello
                    you can use the following statement while at the time of inserting text

                    text1.text=text 1.text & array(n) & vbcrlf

                    thanks

                    Comment

                    • dr3amxstar
                      New Member
                      • May 2007
                      • 55

                      #11
                      Oops i thought nobody was replying to my thread and i managed to figured it out :D anyway thanks for all the help given!! I really did learn alot from this forum :D

                      Code:
                       TextBoxForm2c.AppendText(source3 & vbCrLf & accuracy & vbCrLf)

                      Comment

                      • Killer42
                        Recognized Expert Expert
                        • Oct 2006
                        • 8429

                        #12
                        Glad we could help.

                        It's good that you were able to work it out. I prefer to try and help people work out the answer rather than just giving it to them outright, anyway. Copy/paste generally doesn't teach you much.

                        Comment

                        • dr3amxstar
                          New Member
                          • May 2007
                          • 55

                          #13
                          Originally posted by Killer42
                          Glad we could help.

                          It's good that you were able to work it out. I prefer to try and help people work out the answer rather than just giving it to them outright, anyway. Copy/paste generally doesn't teach you much.

                          yup! by trying out myself i understand what i am doing :D

                          Comment

                          Working...