Results 1 to 18 of 18

Thread: [RESOLVED] Cant Quit :(

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Resolved [RESOLVED] Cant Quit :(

    What am I doing wrong when trying to .Quit an office app?

    ...Form1.cs(116): No overload for method 'Quit' takes '0' arguments
    'Or
    ...Form1.cs(116): No overload for method 'Quit' takes '1' arguments
    ...Form1.cs(116): Argument '1': cannot convert from 'bool' to 'ref object'

    'Or
    ...Form1.cs(116): No overload for method 'Quit' takes '3' arguments
    ...Form1.cs(116): Argument '1': cannot convert from 'bool' to 'ref object'
    ...Form1.cs(116): Argument '2': cannot convert from 'int' to 'ref object'
    ...Form1.cs(116): Argument '3': cannot convert from 'bool' to 'ref object'
    None of these work...

    VB Code:
    1. oApp.Quit();
    2. oApp.Quit([color=blue]false[/color]);
    3. oApp.Quit([color=blue]false[/color],1,[color=blue]false[/color]);
    4. [color=darkgreen]//Destroy the reference[/color]
    5. oApp = [color=blue]null[/color];
    Last edited by RobDog888; Nov 5th, 2005 at 04:52 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: Cant Quit :(

    depending on how many parameters you need to quit ...
    you need to create a ref object of each parameter.
    eg:
    VB Code:
    1. [COLOR=Blue]object[/COLOR] a = ( [COLOR=Blue]object[/COLOR] ) [COLOR=Blue]true[/COLOR]; [COLOR=Green]///  a [B]bool[/B][/COLOR]
    2. [COLOR=Blue]object[/COLOR] b = ( [COLOR=Blue]object[/COLOR] ) 1; [COLOR=Green]/// an [B]int[/B][/COLOR]
    3. [COLOR=Blue]object[/COLOR] c = ( [COLOR=Blue]object[/COLOR] ) [COLOR=Blue]false[/COLOR];
    4.  
    5. oApp.Quit([COLOR=Blue]ref[/COLOR] a , [COLOR=Blue]ref[/COLOR] b , [COLOR=Blue]ref[/COLOR] c);
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cant Quit :(

    It worked. Man, VB.NET lets you do it easily with .Quit(False).
    I searched MSDN and couldnt find anything on .Quit and C#.

    Thanks a million
    Hopefully you will settle for 10.

    VB Code:
    1. [color=blue]object[/color] a = ([color=blue]object[/color]) [color=blue]false[/color];
    2. [color=blue]object[/color] b = ([color=blue]object[/color]) 1;
    3. oApp.Quit([color=blue]ref[/color] a, [color=blue]ref[/color] b, [color=blue]ref[/color] a);
    4. oApp = [color=blue]null[/color];
    Edit: just seen you changed your avatar. Congrats on your new Baby
    Last edited by RobDog888; Nov 5th, 2005 at 06:15 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cant Quit :(

    Another question, Why do I have to pass an argument as it wont let me pass nothing? Each argument has a default so like in VB.NET and VB 6 you dont need to specify one.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Cant Quit :(

    Note that the methods you call in Office apps are written in VB and many use optional arguments. There is no support for optional arguments in C# so you ALWAYS have to provide a value for EVERY argument when calling those methods from C#. That's a good reason to use overloading in your own VB code rather than optional parameters. I've made the switch for that very reason.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cant Quit :(

    Ah, yes. I remember reading that C# has no optional parameters/arguments. That makes sense now. Thanks for the Tip too.

    For more clarification, the a and b object variables are just empty containers of the designated types for filling in the required args, correct?

    Edit: Since I have your attention, is there an Option Explicit and Otpion Strict for C#? I couldnt find one.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Cant Quit :(

    Quote Originally Posted by RobDog888
    is there an Option Explicit and Otpion Strict for C#?
    No. Assume that they are both set to On and there is no way to turn them Off, as it should really be in VB.NET as well, or at least have Option strict On by default. Those Options are part of the reason that VB.NET is probably easier for the beginner than C#, but C# enforces good practices more strictly so I think you tend to become a better programmer more quickly in C# as a result. How mystified do people get when they have been using VB.NET for six months or so and then someone suggests that they turn Option Strict On and they suddenly have hundreds of errors?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cant Quit :(

    Yup I know what you mean. I always use it On but until I realized that it was On by default in C#, I dont have to worry about it. Thanks.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: [RESOLVED] Cant Quit :(

    if you use the Type.InvokeMethod of your object, you can often avoid having to specify extra paramters ( it's a way around the Optional items of a method / function )

    eg:
    take the Webbrowser Control, in C# you must specify the ref objects when navigating
    VB Code:
    1. [COLOR=Green]/// if you use the normal method, you pass all the parameters...[/COLOR]
    2. browser.Navigate2("the url" , ref object , ref object , ref object , ref object);

    but you can avoid using all the extra bits like this ...
    VB Code:
    1. [COLOR=Green]/// to bypass any optional paramters ...[/COLOR]
    2. [COLOR=Blue]object[/COLOR][] args = {"http://google.co.uk"}; [COLOR=Green]/// ignore the extra parameters[/COLOR]
    3. axWebBrowser1.GetType().InvokeMember("Navigate2" , System.Reflection.BindingFlags.InvokeMethod , [COLOR=Blue]null[/COLOR], axWebBrowser1 , args);
    btw, thanks for the Congrats
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Cant Quit :(

    Quote Originally Posted by RobDog888
    It worked. Man, VB.NET lets you do it easily with .Quit(False).
    I searched MSDN and couldnt find anything on .Quit and C#.

    Thanks a million
    Hopefully you will settle for 10.

    VB Code:
    1. [color=blue]object[/color] a = ([color=blue]object[/color]) [color=blue]false[/color];
    2. [color=blue]object[/color] b = ([color=blue]object[/color]) 1;
    3. oApp.Quit([color=blue]ref[/color] a, [color=blue]ref[/color] b, [color=blue]ref[/color] a);
    4. oApp = [color=blue]null[/color];
    Edit: just seen you changed your avatar. Congrats on your new Baby
    I guess you could do it a bit shorter
    Code:
    oApp.Quit(ref (object) false, ref (object) 1, ref (object) false);
    oApp = null;
    tedious as it still is.

  11. #11

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Cant Quit :(

    How come if you can do it that shorter way you dont have to explicitly instanciate the object as you dont get an "Object not set to an instance ..." error?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] Cant Quit :(

    If you cast something to an object, you make an object instance, and you can pass a reference to it without keeping one yourself. So my code is the same as yours without actually storing local references to the newly created objects.

  13. #13

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Cant Quit :(

    I'm still new to C# PG. Could you explain a little more? "(object) false" is casting false to an object varaible type?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] Cant Quit :(

    Yep that's it. "false" is obviously a Boolean which is a value type. The brackets () in front of a variable is the cast operator. Inside the brackets you specify what type you want to cast to. In this case we are just casting to a generic object. The process here of casting a value type to a reference type (object) containing the value is known as "boxing", and there is a decent page detailing it here. Going the other way is, as you would expect, "unboxing". In VB.NET, I think the one-line version is unachievable, without using an object-typed variable and setting that variable to your value-type variable, due to the lack of a cast operator.

  15. #15

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Cant Quit :(

    Ok, Thanks. Seems C# is reverse from vb.net when it comes to variables. Maybe now my dyslexia will come in handy.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Cant Quit :(

    "CObj(False)" is the VB.NET equivalent of "(object)false" in C#. I doubt that the IL is exactly the same but the effect within your app is the same: a reference-type Object instance containing the boolean value False is created.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  17. #17
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] Cant Quit :(

    I thought C...() were functions, so it would be a little bit different under the hood. Although, the JIT compiler might look for and optimise that.

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Cant Quit :(

    I'm quite sure that the IL is different in each case, but using CObj, et al. is not like using most VB.NET functions:
    These functions are compiled inline, meaning the conversion code is part of the code that evaluates the expression. Execution is faster because there is no call to a procedure to accomplish the conversion.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width