bug?

Add-in Express™ Support Service
That's what is more important than anything else

bug?
MessageBox in AddIn module 
An Ngo




Posts: 12
Joined: 2006-02-21
Hi,

I took the sample ExcelAutomationAddIn.
As I see a call to MessageBox.Show (in the exception handle)
(also in the example MyFirstAddIn)
I suppose that MessgaeBox.Show can be used in AddIn module. Is that right?

However, when I put just one MessageBox in the sample ExcelAutomationAddIn
as follow

public string MyFunc(object range)
{
Excel.Range xlRange = null;
string retVal = string.Empty;

try
{
if (range is Excel.Range)
{
// This is the only change I made
MessageBox.Show("What's wrong");

xlRange = range as Excel.Range;
int row = xlRange.Row;
... the rest is the same, I don't touch

the program behaves in a very strange way.

1 - If I type in this formular
=MyFunc(A1:A5)
then the result is normal

2 - But when I click on fx, select the function MyFunc and then use the mouse the select the range, a very strange thing happens:
* Before I can finish the selection, the messagebox just popup, at least twice. It seems that the function is called twice before a soon as I start the selection. And I can never finish the selection using the mouse
* If I give up the mouse, looking carefully at the range, and type the range to the formular then it's OK

Is it a bug? Or something wrong in my using MessageBox inside an AddIn module? Can you show me a walk around? It is impossible to ask the user not to use the mouse to select a range.

Thank you very much


Posted 25 Feb, 2006 03:46:05 Top
Eugene Starostin


Guest


An,

Excel is a multi-threaded application. So, it is a very bad practice to use forms or dialogs inside from your worksheet function. Instead of this, you MUST return #ERR in your retVal.
Posted 25 Feb, 2006 11:58:28 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi An.

This is not a bug. This is Excel behaviour. I would advise you to use the Debugger to debug Excel Automation add-ins. To return an error message you can use 'return err.Message;' or 'return new ErrorWrapper(err);' code.
Posted 27 Feb, 2006 07:13:54 Top
An Ngo




Posts: 12
Joined: 2006-02-21
Thank you,
However, I see that you use this MessageBox in your sample, instead of a return code?
I hope that this restriction applied only to Excel Automation Add Ins?
I can still use Forms in other Add In modules? (I see in another sample you use a form in an the Toys example)

Best regards,
An

Posted 01 Mar, 2006 04:47:44 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi An.

Yes, I use the MessageBox but it is not correct way. I will necessarily change this example.
Of course you can use winforms in COM add-ins.
Posted 01 Mar, 2006 09:13:53 Top