SetVar and active setvar proc functions

So I made a slider and it contains an event-driven if statement in the corresponding proc function, which executes code when you move the slider.

I tried to do the same thing with a SetVar, but I cant even get it to run a print statement. Ive used SetVar to initiate variables before in a user-interface, but I used a second function to read all those variable and then feed them into the main function. This time, I would just like the proc function to run some code if the user pushes the up/down arrows or enters a new value into the field. Is it possible or have I misunderstood the functionality here?

function setvar_proc(setvar_z, z, varStr, varName) :setVariableControl

   string setvar_z // name of my control
   variable z  // the variable being manipulated
   string varStr  // not sure what this is for
   string varName // again, not entirely sure what you would use this for
 
   do a whole bunch of stuff like load some new images in my fancy panels based on the new z value
   print "Oh Igor, why don't you love me anymore?"

end


My button shows up with the correct variable value inside (and moving the slider keyed to the same variable changes this value, as well the opposite, changing the value here moves my slider), but nothing else happens. Igor refuses to print even.


Try the following, using the structure event handle:

Function SetvarTest()
    Variable/G root:MyValue
    NVAR vMyValue=root:MyValue
    vMyValue=1

    NewPanel /W=(150,77,450,277)
    SetVariable setvar0,pos={2,2},size={120,16},proc=SetVarProc,title="This is my value:"
    SetVariable setvar0,limits={0,10,1},value= root:MyValue

End

Function SetVarProc(sva) : SetVariableControl
    STRUCT WMSetVariableAction &sva

    switch( sva.eventCode )
        case 1: // mouse up
            print "Mouse Up event"
            break
        case 2: // Enter key
            print "Enter Key Event"
            break
        case -1: // control being killed
            break
    endswitch

    return 0
End


Hope this helps,
Kurt
Im not sure what the reference you pass (sva) is? I tried it as is, but didnt work, so I looked in the help files for the various structure members allowed in setvar, and Int32 seemed to be the event driven one so I tried replacing sva with that, but still didnt work.

Im totally new to this structure stuff and unfortunately the help file "example" is too bare-bones for me to understand anything at all of what is actually happening.

EDIT: Your stand alone code does exactly what I am trying to do tho, so I will just play around with that for a while until I understand things. Thanks, man.
The procedure functions relating to controls in a panel can take one of two forms: a structure based format, or a non-structure based format. The structure based format gives you far more options and capability.

For example, for the SetVariable control, you can have a non-structure based procedure looking like this:
Function SetVarProc(ctrlName,varNum,varStr,varName) : SetVariableControl
    String ctrlName
    Variable varNum
    String varStr
    String varName

End

which is much the same as you had in your original posting, or the same functionality (and the additional event handler) in a structure based function as this:
Function SetVarProc(sva) : SetVariableControl
    STRUCT WMSetVariableAction &sva

    String ctrlName = sva.ctrlName
    Variable varNum = sva.dval
    String varStr = sva.sval
    String varName = sva.vName

    switch( sva.eventCode )
        case 1: // mouse up
        case 2: // Enter key
        case 3: // Live update
            Variable dval = sva.dval
            String sval = sva.sval
            break
        case -1: // control being killed
            break
    endswitch

    return 0
End

I tend to look for the details by going to Help...Command Help, which opens up a Help Browser, and then scrolling down the list to select WMSetVariableAction in the left hand listbox, or choosing SetVariable in the left hand listbox, and then scrolling down to look at the Details section.
Hope this helps!
Kurt
The structure "sva" is passed by Igor to SetVarProc in response to the user interacting with the control. Then SetVarProc does what it is designed to do, based on the information provided by sva. In Kurt's example , the function's effect depends on the event: mouseup, enter key pressed or control being killed. Generally, your code don't call the control's action procedure, Igor does.

In your example, it would seem that, unless the "do a whole bunch of stuff..." causes the function to exit before the print statement is encountered, setvar_proc isn't being called as a result of user interaction with the setvar control. In the control definition is there a part that reads "proc=setvar_proc"?

Have you tried using the debugger? Although the print statement in setvar_proc is helpful, setting a break point in that function and stepping through it line by line after it has been called might be even more enlightening.
Thank you very much for the additional explanations. Yes, I always just type the command into the command line or my function window and right click it, but unfortunately I find some of the help files to be a bit too vague, especially in regards to the more complicated programming aspects of IGOR such as structured commands. (Ive got extremely basic experience in C++ and python and that is it).

Vagueness regarding input parameters is often a source of frustration. For example, I will often find a short sentence describing what a parameter is, but nothing at all as to what it does. Perhaps to a more experienced person, the functionality is obvious from the definition, but to somebody like me its a frustrating cyclical argument. Most of the time the definitions are very helpful, but not always. String varName = "the name of the variable" for example.. Obviously its a string containing the variable name, I can see that without the definition which tells me nothing new. But since when do I need a string to name a variable, isn't that what the variable command is for? And is the exception so important that there is a specific parameter for this? What happens if I leave it out? etc.. etc..

Obviously you guys cant be expected to write an in-depth introductory course for the newbies. And actually the IGOR documentation already comes wonderfully close, one of the reasons I love this program. One way to improve things would be to allow access to the code in the examples. The help files pointed me straight to a great slider example, but for the love of Igor I just couldn't find the code running the panel, which is what I really needed to see. It already exists, so having it pop up when you run the examples would be an easy and very practical addition to the documentation.

Thanks again, will plug away at this structure stuff now for a few days =)

EDIT: "In the control definition is there a part that reads "proc=setvar_proc"? Yes, and I use liberal print lines to test code for bugs. I havent played with the debugger yet actually, I will have to look into that. I'm sure I was doing something wrong with the whole structure mumbojumbo in this case..
daggaz wrote:
String varName = "the name of the variable" for example.. Obviously its a string containing the variable name, I can see that without the definition which tells me nothing new. But since when do I need a string to name a variable, isn't that what the variable command is for? And is the exception so important that there is a specific parameter for this? What happens if I leave it out? etc.. etc..

We try to make our documentation helpful... I admit that one sounds just a bit on the, um, cryptic side :) Perhaps the explanations here will help:
DisplayHelpTopic "Built-in Structure Reference"
I expect that you meant "vname" instead of "varname" but that's probably a result of frustration...
Such a member would be aimed at using a single action procedure for more than one control. In such a case, you might well need a programmatic way to find out the particular variable that is connected to the particular control that triggered your action procedure.
Quote:
Obviously you guys cant be expected to write an in-depth introductory course for the newbies.

But it is our intention to make the documentation helpful. If you have suggestions to improve it, please feel free to e-mail support@wavemetrics.com. We do actually listen!
Quote:
The help files pointed me straight to a great slider example, but for the love of Igor I just couldn't find the code running the panel, which is what I really needed to see. It already exists, so having it pop up when you run the examples would be an easy and very practical addition to the documentation.

A couple of things that can help:

If you put the panel into Draw mode (Show Tools) click a control to select it, then right click you will get a contextual menu that includes Go To xxx which will take you to the action procedure for the control.

In the code, if you right-click on the action structure name, it will take you to the documentation for the structure members. Which may be of limited help :)

In Igor code in general, if you right-click on an Igor command you will get a menu that includes Help For xxx and Insert xxx Template.

Quote:
will plug away at this structure stuff now for a few days =)

That's really the only way to learn it. It can be painful, though.
Quote:
I havent played with the debugger yet actually, I will have to look into that.

You really want to do that. I can't imagine doing anything more than the most basic coding without it.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com