I am building a simple control panel where the user can set a position for a stage. I would like to have a second setvariable where they can enter the increment of stepping tied to the arrows in the first setvariable. I need to modify the limit={lower,upper,increment} and I am trying build a generic bit of code. To that end I need to retrieve the existing limits setting and just modify the increment entry.
I am using controlinfo to get the S_recreation and trying to extract the limits field. The WhichListItem requires me to know the exact string which of course is what I am trying to find. It does not allow wildcards. What is the solution I am missing? Do I just loop through the recreation string doing a stringmatch?
You'll have to develop custom parsing code. Find "limits={", then from that position find "}". Extract the string between, and possibly use sscanf to extract the numbers.
I often use the user data associated with the control itself. In you case I would store the values into the increment control, as it is needed there directly. Here's some bit of code:
SetVariable vChangeIncrement ,proc=ControlExecuteFunction ,userdata=num2str(initiallower)+";"+num2str(initialupper)// write values
...
Function ControlExecuteFunction(SV) : SetVariableControl
STRUCT WMSetVariableAction &SV
if(SV.eventCode == 1|| SV.eventCode == 2)// value has changed
SV.blockReentry=1StrSwitch(SV.ctrlName)case"vSetStage":
... do your stage movement stuff ...
breakcase"vChangeIncrement":
Variable lower = str2num(StringfromList(0,SV.Userdata))// get limit settings from control userdataVariable upper = str2num(StringfromList(1,SV.Userdata))
... change increment ...
breakEndSwitchendifEnd
Just as a suggestion to shrink code: To avoid extra variables you could use for example SplitString (I guess there is an even nicer way to do it, but my RegEx-fu is not that strong).
Thank you for the other options. They highlighted commands I didn't even think of.
All good options.
One last thing I also keep in mind when I code especially since this is for a client is that it needs to clear to the person maintaining the code. Or in this case the machine since it is part of the interface for positioning stage. Some while I am regexp aware but not proficient, I tend to avoid using it if a clear albeit longer method is available.
it needs to clear to the person maintaining the code
If other people will maintain the code, this should definitly be taken into account. If I look at your solution (as not the original coder) I would have liked to see the limit extraction functionality extracted into its own function with documentation. And most important error checking. I also woiuld have liked to see the use of new style GUI procedures as these don't rely on the top window being the panel with the control.
Or, write the settings to a userdata string attached to the panel itself, then read them back as needed?
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
March 11, 2016 at 03:23 pm - Permalink
Andy
March 11, 2016 at 05:14 pm - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
March 14, 2016 at 05:18 pm - Permalink
March 14, 2016 at 11:49 pm - Permalink
March 15, 2016 at 02:54 pm - Permalink
March 15, 2016 at 06:41 pm - Permalink
maybe?
March 16, 2016 at 03:29 pm - Permalink
Thank you for the other options. They highlighted commands I didn't even think of.
All good options.
One last thing I also keep in mind when I code especially since this is for a client is that it needs to clear to the person maintaining the code. Or in this case the machine since it is part of the interface for positioning stage. Some while I am regexp aware but not proficient, I tend to avoid using it if a clear albeit longer method is available.
Andy
March 16, 2016 at 05:34 pm - Permalink
If other people will maintain the code, this should definitly be taken into account. If I look at your solution (as not the original coder) I would have liked to see the limit extraction functionality extracted into its own function with documentation. And most important error checking. I also woiuld have liked to see the use of new style GUI procedures as these don't rely on the top window being the panel with the control.
March 17, 2016 at 05:12 am - Permalink
Good input.
Andy
March 17, 2016 at 06:53 am - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
March 17, 2016 at 11:42 am - Permalink