none
"Misssing "parameter in VSTO RRS feed

  • Question

  •  I am newbie to VSTO.can anyone help me to overcome my doubt???my doubt is what is the difference between the following codes??

     

    newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add(
     Office.MsoControlType.msoControlPopup,missing,
     missing, missing, false);

    buttonOne = (Office.CommandBarButton)newMenuBar.Controls. Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true);

    foundmenu = (Office.CommandBarPopup)this.Application.ActiveExplorer().
    CommandBars.ActiveMenuBar.FindControl
    (Office.MsoControlType.msoControlPopup, System.Type.Missing,
    menuTag, true, true);

    //menuTag means private string menuTag="unique string";



    why we are using 3 "missing" fields??why we are assigning some values
     (in the above example 1)???plz help me????




    • Edited by Arun Raju Friday, June 10, 2011 5:53 AM For development
    • Moved by CoolDadTx Friday, June 10, 2011 1:30 PM Not IDE related (From:Visual C# IDE)
    Friday, June 10, 2011 5:51 AM

Answers

  • Hi Arun

    The Office object models were created for use with VB languages. VB languages support optional and named parameters - something that was only introduced in C# with version 4.0.

    So almost all the C# code samples you'll find that work with Office applications base on earlier versions of C#.

    C# has to find some way to deal with these optional parameters. Since C# does not support optional parameters, something must be passed for ALL parameters. When you know what value you want to pass, that's not a problem - you pass the value.

    But Office works best using its built-in defaults unless you specifically WANT to change something. In the VB languages, you simply leave the optional parameter out. In C#, you still need to pass something. So C# lets you pass the value System.Type.Missing. This tells Office to treat the optional parameter as if nothing had been passed to the method.

    With VSTO you do not need to declare the data type "missing" (as Bruce shows) because VSTO provides it for you, pre-defined. If you were to automate Office using a Windows Form or Console App then you would need to define it as Bruce shows you.


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Bruce Song Friday, June 24, 2011 1:08 PM
    • Marked as answer by Bruce Song Tuesday, June 28, 2011 12:41 PM
    Thursday, June 16, 2011 8:45 AM
    Moderator
  • Hi Arun,

    >>why we are using 3 "missing" fields??why we are assigning some values
    (in the above example 1)???plz help me????
    The missing stands for the parameter is optional. It can be declared like this in C#:

    object missing = System.Type.Missing;

    Hope this can explain your problem.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Proposed as answer by Bruce Song Friday, June 24, 2011 1:08 PM
    • Marked as answer by Bruce Song Tuesday, June 28, 2011 12:41 PM
    Tuesday, June 14, 2011 12:05 PM

All replies

  • Hi Arun,

    >>why we are using 3 "missing" fields??why we are assigning some values
    (in the above example 1)???plz help me????
    The missing stands for the parameter is optional. It can be declared like this in C#:

    object missing = System.Type.Missing;

    Hope this can explain your problem.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Proposed as answer by Bruce Song Friday, June 24, 2011 1:08 PM
    • Marked as answer by Bruce Song Tuesday, June 28, 2011 12:41 PM
    Tuesday, June 14, 2011 12:05 PM
  • Hi Arun

    The Office object models were created for use with VB languages. VB languages support optional and named parameters - something that was only introduced in C# with version 4.0.

    So almost all the C# code samples you'll find that work with Office applications base on earlier versions of C#.

    C# has to find some way to deal with these optional parameters. Since C# does not support optional parameters, something must be passed for ALL parameters. When you know what value you want to pass, that's not a problem - you pass the value.

    But Office works best using its built-in defaults unless you specifically WANT to change something. In the VB languages, you simply leave the optional parameter out. In C#, you still need to pass something. So C# lets you pass the value System.Type.Missing. This tells Office to treat the optional parameter as if nothing had been passed to the method.

    With VSTO you do not need to declare the data type "missing" (as Bruce shows) because VSTO provides it for you, pre-defined. If you were to automate Office using a Windows Form or Console App then you would need to define it as Bruce shows you.


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Bruce Song Friday, June 24, 2011 1:08 PM
    • Marked as answer by Bruce Song Tuesday, June 28, 2011 12:41 PM
    Thursday, June 16, 2011 8:45 AM
    Moderator