Use SetVariable in panel and in button

I am trying to make a panel that I can manually adjust a start and end frequency then fit a curve between the two frequencies. However, I am having an issue with this and am not completely sure how to handle passing variables.

Macro Fit (a,b)
    String a,b
    //Do stuff to $a,$b
    Execute"PanelTest()")
End

Function ButtonProc(ba) : Button Control
    STRUCT WMBButtonAction &ba
    //do stuff involving setvar0
    print setvar0
End

Window PanelTest : Panel

    PauseUpdate; Silent 1
    NewPanel /W=(200,100,1140,800) as "Data"
    ShowTools/A
    SetVariable setvar0, pos={100,200},size={150,20},title = "StartFreq"
    //Display some graphs, all generated by IGOR

EndMacro


When I compile the macro, the button procedure tells me there is an unknown name or symbol. So how can I pass the variables from the panel through to the function?
Try:

Macro Fit (a,b)
    String a,b
    //Do stuff to $a,$b
    PanelTest()
End


The Execute is not needed.

Here:
Function ButtonProc(ba) : Button Control
    STRUCT WMBButtonAction &ba
    //do stuff involving setvar0
    print setvar0
End


It is not clear what you intend: you can't just print a setvar by using its name.
Also, what do you want to print, the value of setvar0?
If so, use

Function ButtonProc(ba) : Button Control
    STRUCT WMBButtonAction &ba
    //do stuff involving setvar0
    ControlInfo/W=$ba.win setvar0
    print V_Value
End




--Jim Prouty
Software Engineer, WaveMetrics, Inc.
You also need to create a button on the panel to call the the button proc and you need to give the setvar a value.
There is an if/endif section in the button proc to limit the proc to respond to a button click only. There are several other events involving the button that could call the proc... such as the mouse moving over the button.

I made some changes to the code to do this. Hope this helps.

Macro Fit (a,b)
    String a,b
    //Do stuff to $a,$b
    PanelTest(a,b)
End
 
Function ButtonProc(ba)
    STRUCT WMButtonAction &ba
    //only respond to mouse click
    if( ba.eventCode != 2 )
        return 0
    endif
    //do stuff involving setvar0
    ControlInfo/W=$ba.win setvar0
    print V_Value
End
 
Window PanelTest(a,b) : Panel
    String a, b
    PauseUpdate; Silent 1
    NewPanel /W=(200,100,1140,800) as "Data"
    ShowTools/A
    SetVariable setvar0, pos={100,200},size={150,20},value=_NUM:42,title = "StartFreq"
    Button MyButton proc=ButtonProc, title="Do It!"
    //Display some graphs, all generated by IGOR
 
EndMacro