Passing variables between functions in a gui

I have 3 functions, the first one creates the gui. The other two functions are called from the gui, one executes upon entering a number in a fill box (I would like the default number to be zero in the box.) I would like the number entered into the fill box to be accessed in the third function as well as other functions, which executes upon pressing a button.

I have tried using setvariable svBolo_ShotNumber variable=plasmashot but have been unsuccessful

Below is a snippet of the code.

function BoloGui() //Creates the gui
variable/G PlasmaShot
variable/G VACShot
SetDrawEnv fillbgc=(65000,65000,65000)
NewPanel/N=BolometerProcessorPanel /K=1 /W=(389,58,1360,596) as "Bolometer Processor"
SetVariable svBolo_ShotNumber,pos={70,9},size={136,21},proc=BoloSetVarProc, title=" Plasma Shot"
SetVariable svBolo_ShotNumber,fSize=14
SetVariable svBolo_ShotNumber,limits={-inf,inf,0},value= ShotList,bodyWidth= 100
SetVariable svBolo_ShotNumber proc=BoloSetVarProc,value=_NUM:0

SetDrawEnv fsize=10
button disp_intensity, pos={400,10}, size={130,30}, proc=BoloDispIntensity, title="Display Intensity"
end

function BoloSetVarProc(sva) : SetVariableControl //Executes upon entering the information in a fill box
STRUCT WMSetVariableAction &sva
variable plasmashot
switch( sva.eventCode )
case 1: // mouse up
case 2: // Enter key
case 3: // Live update
Variable dval = sva.dval
String sval = sva.sval
plasmashot=str2num(sval)
break
endswitch
return 0
end

function BoloDispIntensity(ba) : ButtonControl //Executes upon the push of a button
STRUCT WMButtonAction &ba
variable plasmashot
print plasmashot
switch( ba.eventCode )
case 2: // mouse up
// click code here
// print num2str(plasmashot)
// print num2str(vacshot)
// boloDiffs(PlasmaShot,VACShot)
break
endswitch

return 0
//print num2str(plasmashot)
//print num2str(vacshot)

end
There are a number of problems here.

(BTW, use <igor> to embed code in an IgorExchange window. Use </igor> at the end to stop embedding.)

As you have written it, this:

    variable/G PlasmaShot
    variable/G VACShot


creates globals in the current data folder. You probably want to always create the globals in the root data folder, so do this:

    variable/G root:PlasmaShot
    variable/G root:VACShot


(For more on storing package globals, execute DisplayHelpTopic "Managing Package Data")

This next line should either be removed or placed after NewPanel:

SetDrawEnv fillbgc=(65000,65000,65000)


You set the SetVariable to be connected to the ShotList global with this command:

SetVariable svBolo_ShotNumber,limits={-inf,inf,0},value=ShotList


but you override that and set it to use internal storage with this command:

SetVariable svBolo_ShotNumber proc=BoloSetVarProc,value=_NUM:0


The latter technique is generally better. If you use the internal storage you can read the value later using ControlInfo.

In your second and third procedures, you write this:

variable plasmashot


That creates a local variable in the function that has nothing to do with the plasmaShot global you created in the first function. Instead you need to write this:

NVAR plasmashot = root:plasmashot  // Create reference to global


However, if you use the internal storage method for SetVariable, you won't need either global. This is why internal storage is a better technique.



Awesome, thanks for the help. The buttons now work exactly as I would like them to.