Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb6 listbox

Status
Not open for further replies.

learningvb01

Technical User
Joined
Feb 13, 2005
Messages
2
Location
US
I want to enter values in a list box by assigning them in my code - which I can do. But I'd like to check the list - if the value is already there -- not add it again. i'm messing wiht tyring to loop through the list by a for loop with list.index.

Help! Please.

also -- is there a good reference for listboxes and list.index?

Thank you
 
To keep it simple you could create a function to check by looping thru the list box items.

A good source of info is the VB6 online help for ListBox - properties, methods and events.

Code:
Public Function f_IsItemInList(sValueToCheck As String) As Boolean

Dim x As Long

For x = 0 To List1.ListCount - 1
    If List1.List(x) = sValueToCheck Then
        f_IsItemInList = True
        Exit Function
    End If
Next

End Function

'then call as required
If Not f_IsItemInList(MyNewString) Then
   Debug.Print "OK to additem"
   
End If
 
This worked well. Now I have another question. When I select the list property sort to be true, an item begining with the number 2 shows up after 19. I know this is how it works, but I really need to see 2 follow 1. Any suggestions?

Thanks,
Dave
 

Use leading zero's for sorting

sValue = Format$(lValue, "000")

002
019
etc



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top