DO11: Scripting - Sample code using "choices' and "options"

If anyone has a VBScript code snippet to share showing how to use Dialog.choices and Dialog.options to display menus/checklists I would be most grateful to see how it is done.

Regards, AB

A very quick example of a popup menu:

[code]Dim test(5,2)
test(0,0) = "Choice 1"
test(0,1) = True
test(1,0) = "Choice 2"
test(2,0) = "Choice 3"
test(3,0) = "Choice 4"
test(4,0) = "Choice 5"

Set Dlg = DOpus.Dlg
Dlg.Window = DOpus.Listers(0)
Dlg.choices = test
Dlg.menu = True
i = CInt(Dlg.show)

If i > 0 Then
DOpus.OutputString test(i - 1,0)
End If
[/code]

Perfect. Thanks a lot Jon.

Regards, AB

I took Jon's sample code and modified it to present a list of target folders with a separator.

[code]@language vbscript

Function OnClick(ByRef ClickData)

Dim test(8,2)
test(0,0) = "/Downloads"
test(1,0) = "/DopusData"
test(2,0) = "/Desktop"
test(2,1) = True ' Makes this item BOLD and "default"
test(3,0) = "/Buttons"
test(4,0) = "/MyDocuments"
test(5,0) = "-"
test(6,0) = "C:\Relay"
test(7,0) = "C:\Utilities"

Set Dlg = DOpus.Dlg
Dlg.Window = DOpus.Listers(0)
Dlg.choices = test
Dlg.menu = True
Dlg.list = True ' Expected to see checkboxes..?
i = CInt(Dlg.show)

If i > 0 Then
DOpus.OutputString i & " : " & test(i - 1,0)
'Go /downloads USEQUALKEYS NEWTAB=findexisting
DOpus.CreateCommand.RunCommand "Go " & test(i - 1,0) & " NEW=nodual,tree"
End If

End Function[/code]


Two questions arise:

The description of the "menu" property says..

[quote]if True the choices array will be used to show a popup menu at the current
mouse coordinates (the VT_BOOL member specifies the default/bold item).
Use "-" as a menu label to insert a separator.[/quote]
This works as shown to insert a separator and to make one of the items bold but it's not clear what "default" means. An item has to be explicitly clicked. Pressing Enter does nothing.

The description of the "list" property says..

[quote]if True the choices array should be two dimensional (VT_BSTR,VT_BOOL),
and the dialog will show a list with checkboxes rather than a drop-down[/quote]
However, as can be seen from the screen grab, no checkboxes appear despite the list property being set to true in the code. What am I missing?

Regards, AB

With the menu, default just means bold.

With the checkbox choices, you can't have both menu and list set true at once.

When using the list mode, a few extra details are required which weren't needed for menu mode: The dialog title, text, and button(s) need to be defined.

I've also changed it to use Set Dlg = ClickData.Func.Dlg, and removed the line setting the window, so that it picks up the lister it is being run from automatically (which might not be DOpus.Listers(0)).

[code]@language vbscript
option explicit

Function OnClick(ByRef ClickData)
Dim i
Dim Dlg

Dim test(8,2)

test(0,0) = "/Downloads"
test(1,0) = "/DopusData"
test(2,0) = "/Desktop"
test(2,1) = True ' Makes this item selected initially
test(3,0) = "/Buttons"
test(4,0) = "/MyDocuments"
test(5,0) = "C:\"
test(6,0) = "C:\Relay"
test(7,0) = "C:\Utilities"

Set Dlg = ClickData.Func.Dlg
Dlg.message = "Select an item"
Dlg.title = "Title"
Dlg.buttons = "OK|Cancel"
Dlg.choices = test
Dlg.list = True
Dlg.show

End Function[/code]

That will show a dialog with a list of checkboxes...

I'm not sure how you tell which items were actually checked afterwards, though. I'll leave that part for Jon to explain as this is the first time I've tried to use this.

It turns out you can't, until the next beta. :slight_smile:

I used the examples above for a jscript version, but am getting an error. Any help would be appreciated.

[code]@language jscript

function OnClick(ClickData)
{
var test = new Array(5);
for(i = 0; i < test.length; i++)
test[i] = new Array(2);

test[0][0] = "Choice 1";
test[0][1] = true;
test[1][0] = "Choice 2";
test[2][0] = "Choice 3";
test[3][0] = "Choice 4";
test[4][0] = "Choice 5";

var dlg = ClickData.Func.Dlg;
dlg.choices = test;
dlg.menu = true;
var i = dlg.Show();

}[/code]

output of:
DOpus.OutputString(test);
Choice 1,true,Choice 2,,Choice 3,,Choice 4,,Choice 5,

The error "Invalid procedure call or argument (0x800a0005)"

It turns out that JScript arrays don't work properly in the context of Opus scripting, so the next beta will provide a Vector object that can be used interchangeably for the same effect.
We are also changing the requirements for a multi-dimension array in the above example, as this is unnecessarily complicated and not well supported by many scripting languages.

In the next beta, the above example would be implemented like this:

var dlg = DOpus.Dlg; dlg.window = DOpus.Listers(0); dlg.choices = DOpus.NewVector("Choice 1","Choice 2","Choice 3","Choice 4","Choice 5"); dlg.menu = DOpus.NewVector(1,0); var i = dlg.Show();