Updating the upper limit of a second set variable limits control

Hi all,

I am just wondering is there any way to set the upper limit of a second setvariable control which will be consequently updated after I insert the value of the first setvariable and do some stuff using a button control i.e. I want the upper limit of the second setvariable will be the value of the first setvariable? 

I am attacing a portion of the code to make it clear what I want to do.

#pragma TextEncoding = "MacRoman"
#pragma rtGlobals=3     // Use modern global access method and strict wave access.

Menu "Macros"
 "My Joint Histo Panel Creation", MyHisData()//MyJointHisData()//MyJoinHistoPanel()
End

Function MyHisData()

    Make/O/N=5000000 timeData=30+gnoise(10)
    Make/O/N=5000000 energyData=1000+gnoise(10)
   
   
   Variable/G gtimeBin = 50
   Variable/G genergyBin = 50
   
   JointHistogram/BINS={gtimeBin, genergyBin}/C/DEST=myJointHisData energyData, timeData
   
   // Energy projection (ON TIME BIN AXIS)
   Make/O/N=(gtimeBin) timeBinAxis
   
   Variable/G timebin_1 = 0, timebin_2=0, energybin_1=0, energybin_2=0
   Variable row, column, sum_Event=0
   
   Make/O/N=(timebin_2-timebin_1) timeBinAxis
   
   For (row=timebin_1; row < timebin_2; row++)
       For(column=energybin_1; column<energybin_2; column++ )
         sum_Event +=myJointHisData[row][column]
       endfor
       timeBinAxis[row] = sum_Event
       sum_Event = 0
   endfor
     
   
End

Function ButtonProc(ba) : ButtonControl //button for 2d image bin setting
    STRUCT WMButtonAction &ba

    switch( ba.eventCode )
        case 2: // mouse up
            // click code here
            WAVE/Z timeData
            WAVE/Z energyData
            NVAR gtimeBin, genergyBin
            //NVAR genergyBin
           
            JointHistogram/BINS={gtimeBin, genergyBin}/C/DEST=myJointHisData timeData, energyData
                   
        case -1: // control being killed
            break
    endswitch

    return 0
End

Window Panel00() : Panel
    PauseUpdate; Silent 1       // building window...
    NewPanel /W=(304,279,993,759)
    ShowTools/A
    SetVariable setvar0,pos={0.00,1.00},size={99.00,14.00},bodyWidth=60,title="time bin"
    SetVariable setvar0,limits={0,inf,1},value= gtimeBin
    SetVariable setvar1,pos={137.00,4.00},size={114.00,14.00},bodyWidth=60, title="energy bin"
    SetVariable setvar1,limits={0,inf,1},value= genergyBin
    Button button0,pos={16.00,30.00},size={165.00,16.00},proc=ButtonProc,title="Draw 2dImage"
   
    //for energy projection (ON TIME BIN AXIS)
    SetVariable time1SetVariableSetLimt title="time1SetVariableSet", proc=SetVarProcForbin_1Limit,value=timebin_1

    SetVariable setvar2,limits={0,gtimeBin,1},value=_NUM:0 //here I want the upper limit will be the value of setvar0's value
  i.e. the number of time bin axis
   
    Display/W=(172,120,517,360)/HOST=#
    AppendImage myJointHisData
    ModifyImage myJointHisData ctab= {0.1,*,Red,1}
    ModifyGraph margin(left)=43,margin(bottom)=43,margin(top)=43,margin(right)=43
    ModifyGraph mirror=0
    RenameWindow #,G0
    SetActiveSubwindow ##
EndMacro

//I think this fragment of code will parse the value of setvar0's but not sure how to extract that
Function SetVarProcForbin_1Limit(sva) : SetVariableControl
    STRUCT WMSetVariableAction &sva

    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

 

The strswitch approach below would get you started:

Function SetVarProc(sva) : SetVariableControl
    STRUCT WMSetVariableAction &sva

    switch( sva.eventCode )
        case 1: // mouse up
        case 2: // Enter key
        case 3: // Live update
            Variable dval = sva.dval
            String sval = sva.sval
            strswitch(sva.ctrlName)
                case "setvar1":
                    // do whatever is required when setvar1 changes
                    ...
                    // now change the limits on setvar2
                    SetVariable setvar2, win=..., limits={0,dval,1}
                    break
                case "setvar2":
                    // do whatever is required when setvar2 changes
                    ...
                    break
            endswitch
            break
        case -1: // control being killed
            break
    endswitch

    return 0
end