PDA

View Full Version : ComboBox retrieval.



grandflavour
10-21-2008, 06:05 PM
Hello everyone.

I've been searching help files and also browsing the net trying to find out how I can specify a certain index within a combobox. To add to the combo box I used combobox1.additem

What I'm trying to do is get the index so I can have a loop like the following so that no repeats are allowed in the combobox.

private sub addWord()

dim i as integer
i = 1
dim count as integer
count = 0
do while i < combobox1.itemcount
if strcomp(combobox1(i), textbox1.text, vbtextcompare) = 1 then
msgbox("Sorry word already exists")
else
count = count + 1
end if
i = i + 1
loop

if count = combobox1.itemcount then
combobox1.Additem = textbox1.text
end if
end sub

Also is there a more efficient way?

Any help greatly appreciated.

GTO
10-21-2008, 08:31 PM
I believe you want to check against "0" to check if its equal.

Mark

Private Sub cmdAddEntry_Click()
Dim intCnt As Integer, _
bolDup As Boolean
If cboUnique.ListCount > 0 Then
For intCnt = 0 To cboUnique.ListCount - 1
'// I believe you want ...=0 to check.//
If StrComp(cboUnique.List(intCnt), _
txtHolder.Value, vbTextCompare) = 0 Then
'duplicate so disregard
txtHolder.Value = Empty
bolDup = True
MsgBox "Already entered", 0, ""
Exit For
End If
Next
End If

If Not bolDup Then
cboUnique.AddItem txtHolder.Value
txtHolder.Value = Empty
End If
End Sub