|
Post by jarychk on Jul 15, 2022 6:18:26 GMT
I cannot follow exactly the logic about the indices for the array and the combobox. The presence of the 0 element confuses the hell out of me. We must now learn to count from 0 to 9 instead of count from 1 to 10? I have taken a careful look at COMBOBOX.bas as a way to try to relearn combobox control. I would PREFER to count array elements starting at 1. We have any way of making this more comfortable?
Let me copy, paste that sample program here.
Not my code; is all Carl Gundel's code.
'COMBOBOX.BAS - a short combobox demo
WindowWidth = 360 WindowHeight = 270
array$(0) = "This" array$(1) = "is" array$(2) = "a" array$(3) = "test" array$(4) = "of" array$(5) = "the" array$(6) = "emergency" array$(7) = "broadcast" array$(8) = "system"
combobox #main.testcb, array$(), [selected], 26, 16, 136, 200 textbox #main.index, 182, 16, 136, 25 button #main, "Accept Selection", [accept], UL, 182, 51, 136, 25 statictext #main.instruct, "Hey", 182, 86, 136, 200
open "untitled" for dialog as #main
instruct$ = "Select an item in the combobox and watch the " + _ "number change, then change the number and hit Accept " + _ "Selection go the other way."
print #main.instruct, instruct$
'wait here for input event wait
[selected] 'Perform action for the combobox named 'testcb'
print #main.testcb, "selectionindex? xVar" print #main.index, str$(xVar) wait
[accept] 'Perform action for the button named 'accept'
print #main.index, "!contents? yVar" print #main.testcb, "selectindex "; yVar wait
|
|
|
Post by Rod on Jul 15, 2022 8:33:12 GMT
No, not really. Lots of things in computing start from and include zero. Numbers for a start, your screen pixels and of course arrays. Dim(9) has always provided ten elements you have just been ignoring zero.
If you use a variable to get the index you don’t even know what the number is so why worry?
Worse still if you alter the array and include blank elements the combo box won’t even list those blanks and the index will not match “what you think is the index”.
The trick is to stop worrying what the index is and just use it, it is a pointer to an array item. The pointer if stored will always point to that array item, you don’t need to know if index z is zero or one, just use z .
|
|
|
Post by jarychk on Jul 15, 2022 9:11:52 GMT
Renumbering the array elements as 1 through 9 makes the sample program much easier to understand and predict. You're right. This is not something to worry about.
|
|
|
Post by tsh73 on Jul 15, 2022 9:28:22 GMT
FYI, you can even renumber these items to be from 3 or 12 Anyway - then loading first will be set to 1, second to 2 etc
And "selectindex 0" always makes empty selection (nothing selected)
|
|
|
Post by honkytonk on Jul 15, 2022 14:14:17 GMT
My contribution to table filling
a$="This is a test of the emergency broadcast system and more and... more" for x=1 to len(a$) if word$(a$,x)="" then k=x: exit for next x dim array$(k+1) 'because index "0" for x=1 to k array$(x)=word$(a$,x) print array$(x) next x
|
|
|
Post by tsh73 on Jul 15, 2022 14:43:19 GMT
You don't need add 1 here. DIM a(5) actually gives 6 slots, a(0) a(1)... a(5)
|
|
|
Post by Rod on Jul 15, 2022 15:03:54 GMT
It might help if folks think about the combo box first and not the index. The combo box is in two parts, the visible text box and the hidden list. No matter how you structure your array() the combo box will reserve index 0 as the text box and index 1-n as the pointers to array items.
This allows the text box to receive data either as a new item or as a requested selection.
There are really two arrays associated with a combo box. The background array that it uses is established on creation and reloaded when a reload command is issued. When either of these events happen the background array looks at the associated array. It fills nothing into position 0 which it reserves for its own use. It then works through the associated array filling the background array with items indexed 1 onwards. It ignores empty string data in the associated array.
As tsh73 says Index 0 is the special index to get at the text box, other index values simply point at items in the list and you should not care what they are
Easy to overthink this, it is the contents of the array that is important, less so the index returned. Remember this is a control for user interaction, the user clicks and points to the item he is interested in. You can find that item again via that index or by the content. Select item “one” will select the item with that content. No need to even be aware of the index value.
The LBPE has a tutorial and practice brings clarity.
|
|
|
Post by jarychk on Jul 15, 2022 22:01:05 GMT
It might help if folks think about the combo box first and not the index. The combo box is in two parts, the visible text box and the hidden list. No matter how you structure your array() the combo box will reserve index 0 as the text box and index 1-n as the pointers to array items. This allows the text box to receive data either as a new item or as a requested selection. There are really two arrays associated with a combo box. The background array that it uses is established on creation and reloaded when a reload command is issued. When either of these events happen the background array looks at the associated array. It fills nothing into position 0 which it reserves for its own use. It then works through the associated array filling the background array with items indexed 1 onwards. It ignores empty string data in the associated array. As tsh73 says Index 0 is the special index to get at the text box, other index values simply point at items in the list and you should not care what they are Easy to overthink this, it is the contents of the array that is important, less so the index returned. Remember this is a control for user interaction, the user clicks and points to the item he is interested in. You can find that item again via that index or by the content. Select item “one” will select the item with that content. No need to even be aware of the index value. The LBPE has a tutorial and practice brings clarity.What you say which I put into bold type: Is LBPE still available?
|
|
|
Post by jarychk on Jul 15, 2022 23:29:41 GMT
It might help if folks think about the combo box first and not the index. The combo box is in two parts, the visible text box and the hidden list. No matter how you structure your array() the combo box will reserve index 0 as the text box and index 1-n as the pointers to array items. This allows the text box to receive data either as a new item or as a requested selection. There are really two arrays associated with a combo box. The background array that it uses is established on creation and reloaded when a reload command is issued. When either of these events happen the background array looks at the associated array. It fills nothing into position 0 which it reserves for its own use. It then works through the associated array filling the background array with items indexed 1 onwards. It ignores empty string data in the associated array. As tsh73 says Index 0 is the special index to get at the text box, other index values simply point at items in the list and you should not care what they are Easy to overthink this, it is the contents of the array that is important, less so the index returned. Remember this is a control for user interaction, the user clicks and points to the item he is interested in. You can find that item again via that index or by the content. Select item “one” will select the item with that content. No need to even be aware of the index value. The LBPE has a tutorial and practice brings clarity.What you say which I put into bold type: Is LBPE still available? I found answer to my own LBPE question. Searched online. Result: alycesrestaurant.com/lbpe/space.menu.html
|
|