Checkbox Handle on Detached Dialog

Background:
Running a dialog box with a checkbox to be ticked.
Looking for a handle to reflect checkbox status (Unticked(default) or Ticked)
What I thought should work is not.
What am I doing wrong?
I am using a Detatched dialog box having created a dialog box using the Dialog Editor
For anyone inclined I think this DCF file can be imported as a button and should run complete with dialog box and code:
2023-06-16 002 CheckBox.dcf (14.3 KB)

Fault Description:
I am trying to extract a handle to tell me if the checkbox has been ticked or not.
I run the script twice and get the unexpected results below.
Take1 - I am expecting a 0 or boolian negative to be returned.
The code I have to capture this return is not executed at all:

Take2 - I am expecting 1 or boolian positive to be returned.
The code at least in this case is executed but runs the default case statement.
Debug 002000-400-030 says my object has been returned undefined:

I think the Control object .value property is in play:

image

function OnClick(clickData)
{
    DOpus.ClearOutput;
	DOpus.Output("001000 Start CheckBox Troubleshoot");
//  001000
//  001000 Start
//  001000
//
    var Dlg = DOpus.Dlg;
    Dlg.window = clickData.func.sourcetab;          // Parent Window of the dialog
    Dlg.template = "Dialog_1";                      // GUI Script Dialog defined in Resources
    Dlg.detach = true;
    Dlg.Show();
//  002000
//  002000 Msg Loop
//  002000
    Dlg_Control_Check_Box_Folder = Dlg.Control("Check_Box_Folder")   // Returns a Control object
    i = 0;
    DOpus.Output("002000 Msg Loop ENTER");
    while (true)
	{
//        DOpus.Output("   000   Iteration ======================================================"+ i);
        var Dlg_Msg = Dlg.GetMsg();
        if (!Dlg_Msg.result) break;
		//	
		switch(Dlg_Msg.Control)
		{
            case "Check_Box_Folder":
			    {
					switch(Dlg_Control_Check_Box_Folder.value.name)
				    	{
							case 0:
						    	// Checbox is UNCHECKED
								DOpus.Output("     002000-400-010  Check_Box_Folder  =  "+ Dlg_Control_Check_Box_Folder.value.name);
								DOpus.Output("     002000-400-011  Unchecked");
								break;
							case 1:
							    // Checbox is CHECKED
								DOpus.Output("     002000-400-020  Check_Box_Folder  =  "+ Dlg_Control_Check_Box_Folder.value.name);
								DOpus.Output("     002000-400-021  Checked");
								break;
							default:
							    // Checbox not sure
								DOpus.Output("     002000-400-030  Check_Box_Folder  =  "+ Dlg_Control_Check_Box_Folder.value.name);
								DOpus.Output("     002000-400-031  Unsure");
								break;
						}
					break;
					DOpus.Output("   002000-100 case ComboB2 EXIT          =  "+ Dlg_Control_ComboB2.value.name);
				}
			default:
    			// code block
				DOpus.Output("   200d  Default we have a problem");                                                 // DailogListItem
		}
		if (Dlg_Msg.event == "focus")
		{
			// We have changed controls
			// We which control is in focus
			//
			DOpus.Output("   002000-150   Dlg_Msg_Event             = " + Dlg_Msg.event);
            DOpus.Output("   002000-170   Dlg_Msg.Control           = " + Dlg_Msg.Control);
			//
			// Populate ComboB2
			//
		}
    }
//  002200
//  002200 Exit Loop
//  002200
	DOpus.Output("002200 Dailog Box Loop EXIT");
	DOpus.Output("002200 Dailog Box Loop EXIT");
    DOpus.Output("002200-010 Return code                         = " + Dlg.result + "   0=CANCEL, 1=Ok" + "<<< Dialog Closed");
//	DOpus.Output(" 020 Destination_Alias never set at this point  =  "+ Destination_Alias);
//
	DOpus.Output("003000 Process Dialog box RETURN START");
	DOpus.Output("003000 Process Dialog box RETURN START");
	DOpus.Output("003000 Process Dialog box RETURN START");
	if (Dlg.result == 0)
	{
		// CANCEL Button so do nothing
	}
	else
	{
		//
		// Ok Button Pressed
		// Assign Destination Alias if not already set above.
		// Maybe they should all move here
		// 2023-03-26 Yes move ALL assignmetns here. Above processing DB is too iterative
		//
	}
	// 003000
	// 003000 Summary
	// 003000
	   DOpus.Output(" 003100 Summary");
       DOpus.Output("   003100-280  Dlg_Control_Check_Box_Folder.value.name  =  "+ Dlg_Control_Check_Box_Folder.value.name);
		//
        // 004000
	DOpus.Output("003990 Process Dialog box RETURN END");
    DOpus.Output("");
}


					switch(Dlg_Control_Check_Box_Folder.value)
				    	{
							case false:
						    	// Checbox is UNCHECKED
								DOpus.Output("     002000-400-010  Check_Box_Folder  =  "+ Dlg_Control_Check_Box_Folder.value);
								DOpus.Output("     002000-400-011  Unchecked");
								break;
							case true:
							    // Checbox is CHECKED
								DOpus.Output("     002000-400-020  Check_Box_Folder  =  "+ Dlg_Control_Check_Box_Folder.value);
								DOpus.Output("     002000-400-021  Checked");
								break;
							default:
							    // Checbox not sure
								DOpus.Output("     002000-400-030  Check_Box_Folder  =  "+ Dlg_Control_Check_Box_Folder.value);
								DOpus.Output("     002000-400-031  Unsure");
								break;
						}

Thanks WKen
No change unfortunately
Debug 003100-280 is telling us that the .value item is being returned "undefined":
Appreciate the reply though....

BTW am running an old version of code.
I will upgrade later and test.....
image

Upgraded to current 13.31 no change.
003100-280 Dlg_Control_Check_Box_Folder.value.name = undefined
image

This simple code works here, responding to clicks on the checkbox:

function OnClick(clickData)
{
    DOpus.ClearOutput;
    var Dlg = clickData.func.Dlg;
    Dlg.template = "Dialog_1"; // Dialog defined in Resources
    Dlg.detach = true;
    Dlg.Show();
    var Dlg_Control_Check_Box_Folder = Dlg.Control("Check_Box_Folder")
    while (true)
	{
        var Dlg_Msg = Dlg.GetMsg();
        if (!Dlg_Msg.result)
			break;
		if (Dlg_Msg.event == "click" && Dlg_Msg.Control == "Check_Box_Folder")
		{
			if (Dlg_Control_Check_Box_Folder.value)
			{
				DOpus.Output("Checked");
			}
			else
			{
				DOpus.Output("Unchecked");
			}
		}
    }
}
<resources>
	<resource name="Dialog_1" type="dialog">
		<dialog fontsize="8" height="50" lang="english" standard_buttons="ok,cancel" title="Prepare to Go" width="131">
			<control height="10" name="Check_Box_Folder" title="Folder" type="check" width="64" x="18" y="12" />
		</dialog>
	</resource>
</resources>

I would not assume Dlg_Msg.Control has any meaning unless Dlg_Msg.event is an event that deals with controls.

I also wouldn't assume that true and false are 1 and 0. Test with "if" instead.

1 Like

Thanks Leo
Arising from your reply I see that you reference
Dlg_Control_Check_Box_Folder.value
Whereas I was referencing
Dlg_Control_Check_Box_Folder.value.name
My error.

Your comment about what assumptions to make also corresponds to the outputs I have gotten above. By default the checkbox is unticked. If left unticked there is in fact no event and so
Dlg_Control_Check_Box_Folder.value
is left undefined. So testing with "if" does the trick.
Thanking you....

It's initially zero here, not undefined. This will output 0, for example:

    Dlg.Show();
    var Dlg_Control_Check_Box_Folder = Dlg.Control("Check_Box_Folder")
    DOpus.Output(Dlg_Control_Check_Box_Folder.value);
1 Like