Updating SetVariable Control

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?

Andy
Would it be easier to store the settings in globals and retrieve them that way?

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
It might. I have been playing parsing the string but commas are used both as main delimiters and delimiters within the desired string.

Andy
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.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
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=1

		StrSwitch(SV.ctrlName)
			case "vSetStage":
				... do your stage movement stuff ...
				break
			case "vChangeIncrement":
				Variable lower = str2num(StringfromList(0,SV.Userdata))		// get limit settings from control userdata
				Variable upper = str2num(StringfromList(1,SV.Userdata))
				... change increment ...
				break
		EndSwitch	
	endif
End
Here is what I ended up with for future reference.

Function SetIncrement(ctrlName,varNum,varStr,varName) : SetVariableControl
	String ctrlName
	Variable varNum
	String varStr
	String varName
	
	String ControlName
	ControlName = "Axis_"+StringFromList(1, CtrlName, "_")
	controlinfo $controlName

	String LimitStr
	Variable StartP,EndP
	StartP	= strsearch(S_recreation, "limits={", 0)
	EndP 	= strsearch(S_recreation, "}", StartP)
	LimitStr= S_recreation[startp,(endP-1)]

	Variable LowLimit,HighLimit
	LowLimit		= str2num(StringFromList(0, LimitStr, ","))
	highlimit 	= str2num(StringFromList(1, LimitStr, ","))
	setvariable $ControlName limits={lowlimit,highlimit,varNum}


End
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).

Function SetIncrement(ctrlName,varNum,varStr,varName) : SetVariableControl
	String ctrlName
	Variable varNum
	String varStr
	String varName
 
	Controlinfo $("Axis_"+StringFromList(1, CtrlName, "_"))
 	SplitString/E="limits={.*}" S_recreation
	String LimitStr = ReplaceString("}",ReplaceString("limits={", S_value,""),"")
 
	Variable LowLimit	= str2num(StringFromList(0, LimitStr, ","))
	Variable highlimit 	= str2num(StringFromList(1, LimitStr, ","))
	setvariable $ControlName limits={lowlimit,highlimit,varNum}
End
Something like the following regexp


	SplitString/E="(?i).*limits={([^,]+),([^,]+),([^,]+)}.*" S_recreation, minimumStr, maximumStr, incrementStr


maybe?
Hi,

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
hegedus wrote:
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.