|
Hi,
I have to open the outlook application.
olApp = new Outlook.ApplicationClass();
But if the outlook is already running, what should I do?
I have the following code to find out if the outlook applicatin is already running. Once I got the processes of current Outlook, how should I assign to olApp??
bool found=false;
Process [] processes = Process.GetProcessesByName("OUTLOOK");
if (processes.Length >= 1)
{
found=true;
}
Thanks.
|
|
|
|
|
I need a variable whose value is known in all program code.
No it's not a constant, it's a variable whose value changes, but i need to access to its value in other program parts.
If i create a class with a property, everytime i change module i need to create a class reference again, and the property is reset to its default value, i need to keep its value all along the program life, this is simple in all other programing languages, but in C# i didn't manage to do this.
How do i do this, and where to do this?
Thank you,
Joaquim
|
|
|
|
|
have you tried creating a public sealed static class with a public static property to get and set the value for that variable. if the class is sealed and static then you don't have to create a reference, all you need is classname.propertyname ....
-----
|
|
|
|
|
Thank you SABhatti, it worked.
But wowww... alone i wouldn't go there.
I did not see any reference to 'public sealed static classes' (uufff..., i'm tired) anywhere in the documentation.
In Visual FoxPro i would do: 'addproperty(_application,PropertyName)', anywhere in the code, and voilá i would have a property that i could access at any part of the code simply by writing:
_application.Propertyname = "value"
or
this.text1.value = _application.Propertyname
Thank you,
Joaquim
|
|
|
|
|
Global variables are generally an indication of poor design. C# therefore does not support them. You can however simiulate them through other means such as the one you have now discovered.
|
|
|
|
|
No Angus, Global variables, or in this case properties, are a means to an end, bad use of global variables are indication of poor design.
And as we now see: C# support them
Joaquim
|
|
|
|
|
joaquimc wrote: Global variables, or in this case properties, are a means to an end, bad use of global variables are indication of poor design.
I didn't say all uses were bad. I said "generally" they were bad. Every time I have the urge to use a global variable I sit and think if it is really really necessary first. Most of the time I come up with a better solution that doesn't involve global variables. These days I rarely think of global variables at all.
Next, properties do not have values. In C# properties are methods dressed up in syntactic sugar. Any value they appear to have is a result of the value that is returned from the underlying method.
joaquimc wrote: And as we now see: C# support them
It doesn't. It is just sugar dressing. It just appears to support them in a contrived way.
|
|
|
|
|
You can't really say that global variables or result of bad design, instead using them badly is bad. But in some cases you definitely need them depending on the requirement..
-----
|
|
|
|
|
Sure you can. Wether or not it's valid to say that is up for debate.
But seriously, I've never seen a situation that warranted globals. Point is there are better ways to handle situations where you want to use them.
|
|
|
|
|
SABhatti wrote: You can't really say that global variables or [are]result of bad design
Yes. I can say that. 99.99% of the time global variables are the result of bad design.
In any situation that I've used them, I've come back to the code sometime later and think why I made that poor descision. Often, rereading the code I'll come up with a better solution.
SABhatti wrote: But in some cases you definitely need them depending on the requirement..
Such as?
|
|
|
|
|
Example: you need a path for a file you'll need throghout the code.
And there are other examples.
Many other examples...
Joaquim
|
|
|
|
|
|
That is a good candidate for something that should be in the app.config file. I have a configuration class in my applications that convert and cache the values from the config file so they are available throughout. In fact, I often have several configuration handling classes because the application has many subsystems that need handling separately.
|
|
|
|
|
And how do you know where is the config file?
(I also use config files, the reason to start this discussion is my config file, i need to know where it is)
Joaquim
-- modified at 19:05 Friday 6th April, 2007
|
|
|
|
|
joaquimc wrote: And how do you know where is the config file?
It is in the same directory as the executable. It will have the same name as the EXE with a .config extension added. You can override that, but that is the default for .NET applications. Or are you not using the builtin configuration classes for some reason?
If you are not using the inbuilt method then how would you be intending to populate the initial value of your global variable?
|
|
|
|
|
The app.config file defaults to being in the same folder as the .EXE. If you didn't want to use the inbuilt configuration handler classes, it's a trivial matter to get the app's, or any assembly for that matter, path that it was loaded from. For example, Application.StartupPath returns the path to the folder that the .EXE was launched from. Couple that with Path.Combine and you can build a fully qualified path to any file or folder in your application.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
joaquimc wrote: you need a path for a file you'll need throghout the code.
You actually made the mistake of hard coding a path?? I'd store that in a config file and create a static class that retrieved that path from the config file.
joaquimc wrote: And there are other examples.
Many other examples...
None of them good, I'm sure.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
What is the app.config file, can you give me an example of its use?
Joaquim
|
|
|
|
|
|
Is there any Visual Studio utility/addin for editing comments in a c# application?
There is an addin for VC++ see http://www.codeproject.com/macro/CommentsWorkbench.asp, but I could not find any for c#.
|
|
|
|
|
I am not sure about that.
But in Visual studio there are lot of controls are there.
Have a look at this[^]
Regards,
Satips.
|
|
|
|
|
There used to be a little tool by Lutz Roeder[^] that was great for that... I'm not seeing it now. He used to have Reflector and Documentor. I can't find it now, but I have a copy of it. Mail me at boneheadiii@hotmail.com and I'll send you a copy.
|
|
|
|
|
Actually, I take that back... What this does is shows you what your comments will look like in documentation. It doesn't automatically add them to code for you or help you write them.
|
|
|
|
|
I have found a really good software for editing XML comments within visual studio. I am going to try the trial version which you can use for 14 days. Has anybody tried that??
Take a look
http://www.helixoft.com/vsdocman/overview.html
|
|
|
|
|
Looks interesting, I may have to try it out.
|
|
|
|