![](/profiles/wavemetrics/themes/wavemetrics/logo.png)
Help for switch-case-break code
![](/sites/default/files/styles/thumbnail/public/default_images/Artboard%201_1.png?itok=jeHOCIXy)
Hi all,
I'm currently working on making a listbox, and I have never done it before. I'm also new to Igor, so I've been reading help files, and looking at demo's and examples for listbox. One thing that I get confused on every time is what exactly the switch, case 1:, break does.
Function ListProc(lba) : ListBoxControl STRUCT WMListboxAction &lba Variable row = lba.row Variable col = lba.col WAVE/T/Z listWave = lba.listWave WAVE/Z selWave = lba.selWave switch( lba.eventCode ) case -1: // control being killed break case 1: // mouse down break case 3: // double click break case 4: // cell selection case 5: // cell selection plus shift key break case 6: // begin edit break case 7: // finish edit break case 13: // checkbox clicked (Igor 6.2 or later) break endswitch return 0 End
This is something I got when I asked Igor for my code when creating my listbox. What do the cases mean? I've looked at the help topics and I think I get confused further. Do I need to put something here to tell Igor what to do? And should I leave it at "case 1" or turn it into "case 'stuff' ", stuff being what exactly I want to do.
Sorry if this is all a jumbled mess and doesn't make sense. Please if anyone has any input, I would greatly appreciate it! And let me know if I need to be more clear with anything!
![](/sites/default/files/forum.png)
Forum
![](/sites/default/files/support.png)
Support
![](/sites/default/files/gallery.png)
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
Hi,
When the user interactions with the list box, Igor will send a message, eventcode, to the function saying what is happening. Within your script you can have different things happen depending on the type of action and the switch flow control is the code snippet inserted as a template. For example eventcode=1 is mouse down, 3 is double click, and so on. So for example you want something to happen when editing is finished you would insert code in the case 7.
To cause a beep on double clicking and run function called fred with the row number as an input variable when done editing :
Andy
From the manual
WMListboxAction
This structure is passed to action procedures for listbox controls created using the ListBox operation.
The constants used to specify the size of structure char arrays are internal to Igor Pro and may change.
WMListboxAction eventCode Field
Action functions should respond only to documented eventCode values. Other event codes may be added in the future.
The event code passed to the listbox action procedure has the following meaning:
Event Code Event
-3 Control received keyboard focus (Igor8 or later)
-2 Control lost keyboard focus (Igor8 or later)
-1 Control being killed
1 Mouse down
2 Mouse up
3 Double click
4 Cell selection (mouse or arrow keys)
5 Cell selection plus Shift key
6 Begin edit
7 End edit
8 Vertical scroll
See Scroll Event Warnings under ListBox
9 Horizontal scroll by user or by the hScroll=h keyword
10 Top row set by row=r or first column set by col=c keywords
11 Column divider resized
12 Keystroke, character code is place in row field
See Note on Keystroke Event under ListBox
13 Checkbox was clicked. This event is sent after selWave is updated.
WMListboxAction row and col Fields
The row field is the row number of selection in interior or -1 if in title area.
The col field is the column number of the selection.
The meanings of row and col are different for eventCodes 8 through 11:
Code row col
8 Top visible row Horizontal shift in pixels.
9 Top visible row Horizontal shift (user scroll).
9 -1 Horizontal shift (hScroll keyword).
10 Top visible row -1 (row keyword).
10 -1 First visible col (col keyword).
11 Column shift Column resized by user.
If eventCode is 11, row is the horizontal shift in pixels of the column col that was resized, not the total horizontal shift of the list as reported in V_horizScroll by ControlInfo. If row is negative, the divider was moved to the left. col=0 corresponds to adjusting the divider on the right side of the first column. Use ControlInfo to get a list of all column widths.
July 20, 2020 at 01:23 pm - Permalink
A switch does flow control a bit like an if-block.
this
is the same as this
July 21, 2020 at 12:12 am - Permalink