Results 1 to 6 of 6

Thread: Multiline Label help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    23

    Multiline Label help

    Hey guys, I have a problem that I cant seem to figure out. I have a multiline label that im trying to add a line everytime I click the button. Its basically adding a new CD track name, CD minutes, and CD seconds to each new line for everytime the user inputs the given information:

    1 Track_Name1 3 min. 13 sec.
    2 Track_Name2 2 min. 34 sec.
    3 Track_Name3 3 min. 01 sec.
    .
    .
    .

    But it keeps adding the "new" line in the position of the old one, so its only displaying on 1 line. I tried using a vbCrLf, but I might have it in the wrong spot?

    heres what I got...

    Code:
     Private Sub btnAddCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddCut.Click
            cutCounter += 1
            lblPlayList.Text = CStr(cutCounter) & " " & txtTitle.Text & " " & txtCutMin.Text & " min. " & txtCutSec.Text & " sec." & vbCrLf
            txtCutMin.Clear()
            txtCutSec.Clear()
            txtTitle.Clear()
    
        End Sub
    The cutCounter is obviously the track number, and it clears the current info for the new information. Thanks for any help...

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Multiline Label help

    This part:

    lblPlayList.Text =

    means that you will be replacing what is there with the new string. That's not what you want. Replace it with this:

    lblPlayList.Text &=

    That will take what is there and concatenate on the new part.
    My usual boring signature: Nothing

  3. #3
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Multiline Label help

    Or if you want to make your code a little easier to understand you could use: -

    lblPlayList.Text = lblPlayList.Text + "Whatever"

    Of course this will be considered 'Old hat' by some of the purists.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Multiline Label help

    The only problem I have with that is the use of + rather than &. They do the same thing, and there is technically nothing wrong with that, especially if you have Option Strict ON, but if you don't have Option Strict ON, there are times when + doesn't do what you expect it to do when working with strings that could be interpreted as numbers. Therefore, I much prefer the use of & for string concatenation since there can be no ambiguity about it.
    My usual boring signature: Nothing

  5. #5
    Hyperactive Member
    Join Date
    May 2009
    Posts
    274

    Re: Multiline Label help

    Is
    Code:
    lblPlayList.Text = lblPlayList.Text & (whatever) & vbnewline
    not sufficient??

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Multiline Label help

    Yes, it is entirely sufficient.
    My usual boring signature: Nothing

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