: : look at this code,it removes any odd numbers in combobox1 when command 1 is clicked
: :
: : Private Sub Command1_Click()
: : i = 0
: : While i <= Combo1.ListCount - 1
: : Combo1.ListIndex = i
: : If Combo1.List(Combo1.ListIndex) Mod 2 = 1 Then
: : Combo1.RemoveItem Combo1.ListIndex
: : i = -1
: : Print i
: : End If
: : i = i + 1
: : Wend
: : End Sub
: :
: : I'm Wondering in the while condition why we have to say Combo.listcount -1 and combo1.listcount would be wrong without -1
: : why is that?:-?
: : another thing is that why we should change the value of i to -1 when
: : when the conditioin is true?
: : No One Knows What Is Like To Be The Sad Boy
: :
: =============================================
: Firstly why the name "sadBoy" and the comment>>
: "No One Knows What Is Like To Be The Sad Boy"?
:
: Anyway the -1 is probably to do with the fact that VB starts counting at zero except for when it gets a string length or in this case a combobox listcount.
:
: The first item then is item number 0 ( not number 1 ).
:
: I will pass on the 2nd question as i can not see the reason for it,but won't your print statement always print -1?
:
:
: Regards,
:
: Dr M.
:
:
:
For the second question:
Say you have 3 items in the combo box
You set listIndex to 1, do your validation and then remove this item.
now former second item becomes first one - so you have to do validation for list index 1 again.
Actually the line
i = -1
Should be
i =i - 1 (to compensate for later i = i + 1)
Mike