[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.
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)
Re: Display number only and not text
Are the numbers always at the end after a space?
vb Code:
Private Sub Command1_Click()
Label1.Caption = Mid$(List1.List(List1.ListIndex), InStrRev(List1.List(List1.ListIndex), " ") + 1)
End Sub
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.
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. :p
Re: Display number only and not text
Quote:
Originally Posted by DigiRev
Beat me by a minute...and with the same exact code. :p
Great minds.... :wave:
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.