Problem with alert dialog

Hello.

I have two radio buttons and wrote a function for them, that only one of them can be checked at the same time. Depending which radio button is chosen a global variable is set to 1 or 2. When I switch between the two radio buttons I have an alert dialog to remind me to switch valves.

My problem is when I want to close my whole panel the alert dialog appears two times in a row and I have to click "Ok" each time. And only then the panel is closed.

I don't know where the mistake is and why it opens two times.

Here is my code for the radio buttons.

Thank you in advance.

 

Function particle_size_proc(cb):CheckboxControl

	STRUCT WMCheckboxAction &cb
	NVAR ParticleSizeG=root:ParticleSizeG
	
	DoAlert/T="Check Valves" 0, "Please switch the valves!"
		
	strswitch (cb.ctrlname)
		case "PM1_panel":
		ParticleSizeG=1
		break
		
		case "PM1_10_panel":
		ParticleSizeG=2
		break
	endswitch
	
	CheckBox PM1_panel,value=ParticleSizeG==1
	CheckBox PM1_10_panel,value=ParticleSizeG==2
	
	PanelApp()
End

 

Your particle_size_proc function is called multiple times for different events. The eventCode field of the cb structure parameter tells you which event has occurred. You need to switch on cb.eventCode.

I see that the example function MyCheckProc in the documentation for the Checkbox operation omits this switch. I will fix that for the next release.

Here is an example. For clarity, I have factored the click handling into a separate function.

Function HandleMouseUpForCheckboxes(controlName)
    String controlName
   
    DoAlert/T="Check Valves" 0, "Please switch the valves!"
       
    NVAR ParticleSizeG=root:ParticleSizeG
    strswitch (controlName)
        case "PM1_panel":
        ParticleSizeG=1
        break
       
        case "PM1_10_panel":
        ParticleSizeG=2
        break
    endswitch
   
    CheckBox PM1_panel,value=ParticleSizeG==1
    CheckBox PM1_10_panel,value=ParticleSizeG==2
End

Function particle_size_proc(cb):CheckboxControl
    STRUCT WMCheckboxAction &cb
   
    switch(cb.eventCode)
        case 2:                 // Mouse up
            HandleMouseUpForCheckboxes(cb.ctrlname)
            break
    endswitch
   
    // PanelApp()               // I don't know what this is for
End

 

Thank you very much for your help. It works perfectly.

 

Just for a better understanding, what is the difference between using cb.eventCode and cb.ctrlname?

Right-click "WMCheckboxAction" and choose "Help for WMCheckboxAction". That will take you to the reference documentation for the structure which explains each of the fields in it.