Dialog Box Error

958 views
Skip to first unread message

Chris Spicer

unread,
Sep 6, 2009, 4:12:20 PM9/6/09
to ExcelDna
Hi All,

I'm struggling to get the Excel dialog box functionality to work
properly. I'm using the following code, driven from a menu item:

public static void Run()
{
object[,] DialogDef = new object[3, 7] {{"", "", "", 372,
200, "Test", ""},
{1, 100, 170, 90, "", "OK", ""},
{2, 200, 340, 90, "", "Cancel",
""}};
XlCall.Excel(XlCall.xlfDialogBox, DialogDef);
}

This gives me the following error in a dialog box:

"Error in dialog box at R1C2".

I'm basing my choices of parameters on the example Steve Dalton gives
on p.159 of his book (first edition), if that helps any.

Can anyone point me to where I'm going wrong here please?

Chris Spicer

Govert van Drimmelen

unread,
Sep 9, 2009, 3:55:07 AM9/9/09
to ExcelDna
Hi Chris,

The help file for the XlCall.xl... macros can be downloaded from here:
http://support.microsoft.com/kb/128185.
The Steve Dalton's book (Financial Applications using Excel Add-in
Development in C/C++) is also an awesome guide to the Excel API.

You are calling the DIALOG.BOX function (as XlCall.xlfDialogBox), and
you have it nearly right :-)
The problem is that Excel is not considering the empty strings as the
"blank" values you intend. Instead of the empty strings, you should
pass null, or ExcelDna.Integration.ExcelEmpty.Value or
ExcelDna.Integration.ExcelMissing.Value. These are marshalled to an
XLOPER of type xltypeNil or xltypeMissing, which Excel will accept
here.

The corrected function that displays a dialog box (with the buttons
moved a bit) is:
[ExcelCommand(MenuText="Show Dialog")]
public static void ShowTheDialog()
{
object[,] DialogDef = new object[3, 7] {{null, null, null,
372, 200, "Test", null},
{1, 170, 100, 90, null, "OK",
null},
{2, 270, 100, 90, null, "Cancel",
null}};
XlCall.Excel(XlCall.xlfDialogBox, DialogDef);
}

Regards,
Govert





On Sep 6, 10:12 pm, Chris Spicer <chris.spi...@technicana.com> wrote:
> Hi All,
>
> I'm struggling to get the Exceldialogbox functionality to work
> properly.  I'm using the following code, driven from a menu item:
>
>         public static void Run()
>         {
>             object[,] DialogDef = new object[3, 7] {{"", "", "", 372,
> 200, "Test", ""},
>                                     {1, 100, 170, 90, "", "OK", ""},
>                                     {2, 200, 340, 90, "", "Cancel",
> ""}};
>             XlCall.Excel(XlCall.xlfDialogBox, DialogDef);
>         }
>
> This gives me the following error in adialogbox:
>
> "Error indialogbox at R1C2".

Chris Spicer

unread,
Sep 15, 2009, 9:57:55 AM9/15/09
to ExcelDna
Ahh.. I hadn't thought of nulls vs. empty strings. Thanks for your
guidance.
Reply all
Reply to author
Forward
0 new messages