Add Index to Combo Box List Items
Posted
#1
(In Topic #1407)
Regular

My list is something like:
5 Ingredient Recipe
6 Ingredient Recipe
7 Ingredient Recipe
So if I click 7 Ingredient Recipe in the combo box at run time, I want to give me 7 checkboxes with various labels in the hpanel. The problem is no matter what I click it just gives me the first option - 5 checkboxes.
I am using a case statement that is
Select case numingredients.index
Case 1
dispcheck = 5
Case 2
dispcheck = 6
Etc
End select
Posted
Regular

Update - solved it by setting the case statement starting with 0 for the first item in the list.
I will leave this here in case anyone else has the same quandary as well as my observation below.
Thx.
PS - just kind of found an answer.
The first item in the list seems to be throwing all the others off. So it was returning zero, and then each one was displaying the number of check boxes for the item above. Not sure why it's doing that, but when I added "Select from one option below" in the list in properties, all the other ones come up with the right number of checkboxes.
It works, but now I want to know if there is a neater solution.
Thx.
Posted
Guru

Code (gambas)
- ' Gambas class file
- BuildForm
- .Arrangement = Arrange.Vertical
- .Padding = 5
- .H = 350
- .W = 1000
- HBox1.h = 42
- .List = ["0 x CheckBox", "1 x CheckBox", "2 x CheckBoxs", "3 x CheckBoxs", "4 x CheckBoxs", "5 x CheckBoxs", "6 x CheckBoxs"]
- .Text = .List[0]
- .W = 250
- HBox2.h = 42
- CheckBoxes.Add(CheckBox1)
- bReturn = False
Posted
Guru

For ComboBox.Index (and most other things) the first item is always 0 not 1
For a neater solution maybe rather than a Select block you can just add the Index value?
So instead of…
Select numingredients.Index
Case 0
dispcheck = 5
Case 1
dispcheck = 6
and so on
Just do this…
dispcheck = numingredients.index + 5
Posted
Regular

That zero vs one thing used to snag me quite a bit with arrays in VB, especially with applications where my counters were more logical starting at 1.
Should have realized that this list was an array and would likely start at zero.
I will get this eventually!
Lucille
1 guest and 0 members have just viewed this.


