Bug with the 128 flag of inputselect

Things you’d like to miss in the future...
Forum rules
When reporting a bug, please include the following information: your XYplorer version (e.g., v27.90.0047), your Windows version (e.g., Win 11), and your screen scaling percentage (e.g., 125%). We recommend adding your Windows version and screen scaling percentage to your profile or signature. This will make debugging much easier for us.
Post Reply
klownboy
Posts: 4397
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Bug with the 128 flag of inputselect

Post by klownboy »

Help file for: inputselect (header, listdata, [separator="|"], [style=1], [cancel], [width=600], [height=400], [windowcaption])
states,
128 = Return selected index. If nothing is selected, 0 (zero) is returned.
This statement is incorrect. When using return index "128", if the 1st item is selected, the return is "0", 2nd is "1", and 3rd item selected returns "2". If nothing is selected the return is "-1". Which makes sense since it can't be "0" (zero) as stated since if the first item is selected the return is "0".

Edit: To make it easier to eval...

Code: Select all

     $options = "One|Two|Three";
     $index = inputselect("Select an option:<crlf>", "$options", "|" ,128, "None", 420, 265, "Your options");
       if ($index == "0") {echo Index: $index}
       if ($index == "1") {echo Index: $index}
       if ($index == "2") {echo Index: $index}
       if ($index == "-1") {msg "You haven't selected an option...aborting!"; end 1;}
Thanks,
Ken

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Website and Help Typos

Post by bdeshi »

hmmm... that 128 flag also returns an extra space; it returns " 0", ..., " n" instead of "0", ..., "n".
(huh, a source code typo?)
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 64841
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Website and Help Typos

Post by admin »

SammaySarkar wrote:hmmm... that 128 flag also returns an extra space; it returns " 0", ..., " n" instead of "0", ..., "n".
(huh, a source code typo?)
Bingo! :oops: Thanks.

admin
Site Admin
Posts: 64841
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Website and Help Typos

Post by admin »

klownboy wrote:Help file for: inputselect (header, listdata, [separator="|"], [style=1], [cancel], [width=600], [height=400], [windowcaption])
states,
128 = Return selected index. If nothing is selected, 0 (zero) is returned.
This statement is incorrect. When using return index "128", if the 1st item is selected, the return is "0", 2nd is "1", and 3rd item selected returns "2". If nothing is selected the return is "-1". Which makes sense since it can't be "0" (zero) as stated since if the first item is selected the return is "0".

Edit: To make it easier to eval...

Code: Select all

     $options = "One|Two|Three";
     $index = inputselect("Select an option:<crlf>", "$options", "|" ,128, "None", 420, 265, "Your options");
       if ($index == "0") {echo Index: $index}
       if ($index == "1") {echo Index: $index}
       if ($index == "2") {echo Index: $index}
       if ($index == "-1") {msg "You haven't selected an option...aborting!"; end 1;}
Thanks,
Ken
I think it was never intended to return the index 0-based. So the Help file is right but the code is wrong. Good find, thanks!

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Website and Help Typos

Post by TheQwerty »

admin wrote:I think it was never intended to return the index 0-based. So the Help file is right but the code is wrong. Good find, thanks!
Sorry, I missed the cutoff for v14.50.0300, but for InputSelect...

Either style 128 needs to respect style 2 and return a list of the the checked items' indexes, or it needs to be documented that it will completely ignore the checkboxes and return the "selected" item's index.

It's rather obvious but it might also be worth mentioning that combining styles 16 and 128 will give you headaches.

admin
Site Admin
Posts: 64841
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Website and Help Typos

Post by admin »

TheQwerty wrote:
admin wrote:I think it was never intended to return the index 0-based. So the Help file is right but the code is wrong. Good find, thanks!
Sorry, I missed the cutoff for v14.50.0300, but for InputSelect...

Either style 128 needs to respect style 2 and return a list of the the checked items' indexes, or it needs to be documented that it will completely ignore the checkboxes and return the "selected" item's index.

It's rather obvious but it might also be worth mentioning that combining styles 16 and 128 will give you headaches.
Hm,

style 2: I find the current behavior totally natural and expected. No need for docs.
style 16: The same. No headaches here.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Website and Help Typos

Post by TheQwerty »

admin wrote:
TheQwerty wrote:Either style 128 needs to respect style 2 and return a list of the the checked items' indexes, or it needs to be documented that it will completely ignore the checkboxes and return the "selected" item's index.

It's rather obvious but it might also be worth mentioning that combining styles 16 and 128 will give you headaches.
style 2: I find the current behavior totally natural and expected. No need for docs.
style 16: The same. No headaches here.
Really? Even when those styles are combined with 128?

If you don't want to document it fine, and I'll grant you that it is obviously stupid to combine styles 16+128, but don't tell me that it's natural and expected that combining 2+128 completely ignores the checkboxes and only returns the focused item's index.

Please play with it a bit because frankly the behavior of 2+128 is completely baffling at first...

Code: Select all

"Styles 2+128" Echo InputSelect('Style is 2+128 so the checkboxes are ignored.', '+A|B|+C|D',, 2+128);
"Styles 16+128" Echo InputSelect('Style is 16+128 and since the user can reorder items, changing their indexes, the returned value is worthless.', 'A|B|C|D',, 16+128);

admin
Site Admin
Posts: 64841
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Bug with the 128 flag of inputselect

Post by admin »

Hm, I still find your example totally natural, normal, and expected. Maybe I'm spoilt. :whistle:

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Bug with the 128 flag of inputselect

Post by TheQwerty »

Must be!
When I use style 130 I'm all :shock: :veryconfused: :roll:

admin
Site Admin
Posts: 64841
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Bug with the 128 flag of inputselect

Post by admin »

128 = Return selected index.

This has nothing to do with checked items.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Bug with the 128 flag of inputselect

Post by TheQwerty »

return The selected list item. If checkbox style then the checked items are returned, separated by separator.
2 means return the checked items.
128 means return the selected index.
130 means the checkboxes are displayed but completely meaningless as style 2 is ignored.
I doubt I'm the only one that expected and hoped that 130 would return a list of indexes of checked items.

16 means allow re-ordering items.
128 means return the selected index (after optional re-ordering).
144 means here's a random number between 0 and the count of items inclusive since you have no way of knowing if the items were re-ordered.


My point is the documentation is confusing because normally styles can be combined but here we have some styles that negate others and no idea how they are prioritized.

I've beaten this horse enough though so change it or not - I don't care.

admin
Site Admin
Posts: 64841
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Bug with the 128 flag of inputselect

Post by admin »

I added a note to the help.

Post Reply