|
-
Nov 5th, 2005, 04:46 PM
#1
[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:
oApp.Quit();
oApp.Quit([color=blue]false[/color]);
oApp.Quit([color=blue]false[/color],1,[color=blue]false[/color]);
[color=darkgreen]//Destroy the reference[/color]
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 5th, 2005, 05:57 PM
#2
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:
[COLOR=Blue]object[/COLOR] a = ( [COLOR=Blue]object[/COLOR] ) [COLOR=Blue]true[/COLOR]; [COLOR=Green]/// a [B]bool[/B][/COLOR]
[COLOR=Blue]object[/COLOR] b = ( [COLOR=Blue]object[/COLOR] ) 1; [COLOR=Green]/// an [B]int[/B][/COLOR]
[COLOR=Blue]object[/COLOR] c = ( [COLOR=Blue]object[/COLOR] ) [COLOR=Blue]false[/COLOR];
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]
-
Nov 5th, 2005, 06:09 PM
#3
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:
[color=blue]object[/color] a = ([color=blue]object[/color]) [color=blue]false[/color];
[color=blue]object[/color] b = ([color=blue]object[/color]) 1;
oApp.Quit([color=blue]ref[/color] a, [color=blue]ref[/color] b, [color=blue]ref[/color] a);
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 5th, 2005, 06:14 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 5th, 2005, 06:18 PM
#5
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.
-
Nov 5th, 2005, 06:38 PM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 5th, 2005, 06:53 PM
#7
Re: Cant Quit :(
 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?
-
Nov 5th, 2005, 07:16 PM
#8
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 6th, 2005, 04:39 AM
#9
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:
[COLOR=Green]/// if you use the normal method, you pass all the parameters...[/COLOR]
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:
[COLOR=Green]/// to bypass any optional paramters ...[/COLOR]
[COLOR=Blue]object[/COLOR][] args = {"http://google.co.uk"}; [COLOR=Green]/// ignore the extra parameters[/COLOR]
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]
-
Nov 6th, 2005, 09:15 AM
#10
Re: Cant Quit :(
 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:
[color=blue]object[/color] a = ([color=blue]object[/color]) [color=blue]false[/color];
[color=blue]object[/color] b = ([color=blue]object[/color]) 1;
oApp.Quit([color=blue]ref[/color] a, [color=blue]ref[/color] b, [color=blue]ref[/color] a);
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.
-
Nov 6th, 2005, 11:30 AM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 6th, 2005, 11:34 AM
#12
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.
-
Nov 6th, 2005, 11:47 AM
#13
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 6th, 2005, 11:57 AM
#14
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.
-
Nov 6th, 2005, 12:04 PM
#15
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 6th, 2005, 04:26 PM
#16
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.
-
Nov 6th, 2005, 09:17 PM
#17
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.
-
Nov 6th, 2005, 09:41 PM
#18
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|