Results 1 to 7 of 7

Thread: [RESOLVED] Display number only and not text

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    790

    Resolved [RESOLVED] Display number only and not text

    I have a list, and in my items are labeled like this:

    List1.Add Item "Home sound 14"
    List1.AddItem "Home sound 15"
    List1.AddItem "Home sound 16"

    I use the following code to play the text into a label:

    Label1.Caption = List1.List(List1.ListIndex)

    My question is:
    How can I just send the number to the label caption so only "14", "15", "16", etc. is sent and not the words like "home" or "sound"?

    Thanks.

  2. #2
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Display number only and not text

    If the text is always formatted in the same way you could try:

    Label1.Caption = Mid$(List1.List(List1.ListIndex), instrrev(List1.List(List1.ListIndex), " ") +1)
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Display number only and not text

    Are the numbers always at the end after a space?

    vb Code:
    1. Private Sub Command1_Click()
    2.     Label1.Caption = Mid$(List1.List(List1.ListIndex), InStrRev(List1.List(List1.ListIndex), " ") + 1)
    3. End Sub

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Display number only and not text

    Either through use of regular expressions or through Mid(List1.List(List1.ListIndex), 12) if leading non digit characters is fixed length.

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Display number only and not text

    Quote Originally Posted by pnish
    If the text is always formatted in the same way you could try:

    Label1.Caption = Mid$(List1.List(List1.ListIndex), instrrev(List1.List(List1.ListIndex), " ") +1)
    Beat me by a minute...and with the same exact code.

  6. #6
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Display number only and not text

    Quote Originally Posted by DigiRev
    Beat me by a minute...and with the same exact code.
    Great minds....
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    790

    Re: Display number only and not text

    Yep, great minds!

    Thanks! It works as it needs to.

    I set it up so the format is the same... it displays the number I need.

    Thanks again.

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