How can I introduce my button ?

Hi all
I want to use button for running my code, I mean I write some code to appear some buttons and I like after press my button, it do rest of my code.
If you please check my code in attachment, you will be see I have my button which called "Calculate number of atoms" but I can not introduce it correctly and when I press it I see error.
My aim is: after press this button, it do rest of the my code

Thanks so much
test 1.pxp
You code is incomplete. Though you have create a panel with a button that calls a buttonProc procedure, you have not written that ButtonProc function. You code has only:

Window Panel0() : control panel
    Pauseupdate ; silent 1
    Newpanel /W=(248,115,730,626)  // apear the panel
    modifypanel cbRGB=(0,39168,39168),fixedsize=1 //color of panel
    showtools /A
    setdrawlayer userback
    Setdrawenv fsize=20,fstyle=1,textrgb=(65535,65535,65535)
    drawtext 4,32,"Analysis of Trap"
    drawpict 2,2,2,1,1
    Button button1,pos={160,165},size={161,35},proc=buttonproc,title="Calculate number of atoms"
Endmacro
...
Function AjustaImagen()
...
End


You will have better success if you let Igor's dialogs create panel code for you to start, and then you can modify it to suit your purposes. I often add controls to a new panel, then save the window recreation macro (Window->Control->Window Control... and check "Save macro"), and then make a function out of it like the example below.

The Window Panel0() : control panel part should be just: Window Panel0() : Panel, though quickly you will learn that a good name for a panel is useful when modifying controls or just bring the window to the front, so I'd suggest code like this:

Menu "Analysis"
    "Open Calculate Panel",/Q, OpenCalculatePanel()
End

Function OpenCalculatePanel()
    DoWindow/K CalculatePanel
    Newpanel /W=(248,115,730,626)/N=CalculatePanel // apear the panel
    modifypanel cbRGB=(0,39168,39168),fixedsize=1 //color of panel
    showtools /A
    setdrawlayer/K userback
    Setdrawenv fsize=20,fstyle=1,textrgb=(65535,65535,65535)
    drawtext 4,32,"Analysis of Trap"
    //drawpict 2,2,2,1,1    //no: 4 numbers and a picture name are needed here
    Button button1,pos={160,165},size={161,35},proc=buttonproc,title="Calculate number of atoms"
Endmacro

Function ButtonProc(ctrlName) : ButtonControl
    String ctrlName
    Print "Button pressed"
    // Call your calculate routine here
End


--Jim Prouty
Software Engineer, WaveMetrics, Inc.
Yes, you are right.
I am newbie and I need work a little more.
I use your suggestion and it is great but some times it shows this error (while executing removecontour, the following error occurred:Expected the name of a contour matrix or z wave in the top graph), I want to know is correlate in my igor or maybe because of my data loding from another code?
By the way, If I want to add another button, should I do same process?
Thanks
For example I add this button (Integrate ROI), but both of those work similar, when I press either "Calculate number of atoms" or "Integrate ROI" is the same. I do not know how can introduce the second one?

Button button0,pos={60,110},size={161,35},proc=ROIProc,title="Integrate ROI"
Button button1,pos={60,65},size={161,35},proc=buttonproc,title="Calculate number of atoms"

Endmacro

Function ButtonProc(ctrlName) : ButtonControl
String ctrlName
string ctrlname0
variable nc=2
variable ic, nt=0
Post *all* of your code. Trying to guess what is wrong from the tiny pieces of code you posted is just not worth the effort.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
I have POPUMENU , SETVARIABLE and BUTTON, so I need each of this guy do especially job.
With your guide, I can do for one of the my button and as you see in my code , I put my calculate routine only for this button and it is work very well.
I have not any idea about, where I can put the calculation for another button,POPUMENU and ... or how can Igor knows them?

Thanks for your time Jim
You've added a proc=ROIProc statement for the button:
    Button button0_tab0,pos={60,310},size={161,35},proc=ROIProc,title="Integrate ROI"


but you haven't written a function or Proc named ROIProc.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
I did it and it works. Thanks
What about the popupmenu? I like when I switch between the value of the popumenu, its action change.
For it, do I need to write Function also? How can it understand this switch?
Sorry for a lot of questions
saeed wrote:
I did it and it works. Thanks
What about the popupmenu? I like when I switch between the value of the popumenu, its action change.
For it, do I need to write Function also? How can it understand this switch?
Sorry for a lot of questions


Use the control dialog to create the action function, even if you leave it blank.

Then find it in the Procedure window and fill it in.

Read the docs on the the PopupMenu value keyword; it is a little tricky.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
Button button1,pos={36,229},size={150,26}. Can I explain me pos=(36,229)? what's this?
A good starting point for this and similar questions is the online help.
displayhelptopic "button"
will list in the parameters section:
pos={left,top } Sets the position of the button in pixels.

HJ