|
Nico van der Plas wrote: p.s.
Which of the Code Project gurus around here can tell me how to make the tabs in my example code visible. It looks horribly unindented now...
Use the pre tag.
---
b { font-weight: normal; }
|
|
|
|
|
Mark06 wrote: Imagine Im developing a function. I can either account for errors by using a try...catch statment, or I can raise an exception.
You should only catch exceptions that you know how to handle within the function. A try/catch around all your functions is a bad idea.
Mark06 wrote: If I development a function that requires a integer parameter to be less than 10, why would I need to create an exception if its greater?
So the calling function knows why you couldn't process it's input.
Mark06 wrote: So therefore, raising exceptions is bad?
That depends, would you prefer the program to crash on your machine, or on your users ? When an exception occurs, it indicates that a situation has arisen in your code which you've not properly handled.
FWIW, any windows program I write handles exceptions at the top level and writes them to a log file, exceptions are also exceptionally useful at helping me to work out why code that runs fine here, doesn't always work in the real world. Code that swallowed exceptions would not give me that information, and would make my life a lot more difficult.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Mark06 wrote: I can either account for errors by using a try...catch statment, or I can raise an exception.
They are actually two sides of the same coin. You use try...catch to handle a sitation where an exception has been raised.
Exceptions are used to handle error messages that can travel up through the call stack until there is some code that knows how to handle it. If you for example have a function that takes a string as argument, and someone sends a null to the function, you can throw an ArgumentNullException to flag that an error has occured as you can't do anything meningfull with the argument. The code that called the function may anticipate that this might happen and catch the exception, or it can let the excpetion continue through the call stack to be handled at a higher level.
Mark06 wrote: If I development a function that requires a integer parameter to be less than 10, why would I need to create an exception if its greater? Surely Im going to be aware of that myself? Likewise, I would much rather the application deal with the problem using a try...catch, than throw an exception causing it to creash.
Perhaps you are not aware of an error that causes some code to send a higher value, then throwing an exception is a good way of telling exactly what went wrong. You can of course choose to handle it some other way, like clipping the values that are larger, but that depends on what you want to happen. Sometimes you want an error to cause an exception, so that you can fix it, instead of silently changing the value or returning an incorrect value that will cause problems later in the code.
---
b { font-weight: normal; }
|
|
|
|
|
Exceptions are for that moron that will modify your code. Always raise good exceptions (your own type too) always use if checks if an exception can be avoided, Assertions are your friend.
90% of the cost is maintenance. Make your code easy to maintain and your code will be great.
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
|
|
|
|
|
Hi All!
How can i get the duration of a song?
I have the Windows Media Player control in my Project but i do not know to get the duration, i found the curentMedia properity but it does not work.
Do you know?
Or is there another way to do so?
Thanks
|
|
|
|
|
There's a dll called dexter.dll in your system32 folder if you have DX. Import a reference to it. It contains a class called the MediaDetClass. You can create an instance of this class using the path to your video file, and it's properties will include a stream length. I have found no way to get the video size or length from the WMP classes.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
Use This ......
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand,StringBuilder strReturn,int iReturnLength, IntPtr hwndCallback);
public int Duration()
{
int ReturnSeconds;
sCommand = "status MediaFile length";
private StringBuilder sBuffer = new StringBuilder(128);
mciSendString(sCommand, sBuffer, 128, IntPtr.Zero);
ReturnSeconds = Convert.ToInt32((sBuffer.ToString()));
ReturnSeconds = ReturnSeconds/1000;
return ReturnSeconds;
}
It will return you the duration .....
Enjoy!!!!
<marquee>nishu
|
|
|
|
|
I am write code that print some lines and text.
In dialog box of printing , I am printing to file - "print to file".
how can I print this file now to the printer???
If i drag him to the menneger of printing it did not working
he write to me : "Can No Print this file,try to open with an apliction..."
when I save this file , what kind of extension I need to write ? ? ?
I mast an answer
Galigal156
|
|
|
|
|
I need your help guys. Thanks in advance.
Can you please teach me on how to create a string array property or give a snippet/sample code. I need this property to have a string editor for my custom web control.
|
|
|
|
|
Hello
Mark Anthony Sabado wrote: how to create a string array property
private string[] _myarray;
public string[] MyStringArray
{
get { return _myarray; }
set { _myarray = value; }
}
Was that what you were looking for?
Regards
|
|
|
|
|
|
Hello,
Maybe 'System.Collections.Specialized.StringCollection' can help you somehow, to make your code more dynamic.
private System.Collections.Specialized.StringCollection _mystringcollection = new System.Collections.Specialized.StringCollection;
public System.Collections.Specialized.StringCollection MyStringCollection
{
get
{
return _mystringcollection;
}
set
{
_mystringcollection = value;
}
}
All the best,
Martin
|
|
|
|
|
Well, i can succesfully get to the database, but get the error 'doesn't exist or access denied'
The problem is that the DB requires a username and password.
With ftp that I was checking out earlier this was in credentials, but i don't see that here, i'll keep looking but any help or articles that you can direct me to would be really great.
|
|
|
|
|
Take a look at connectionstrings.com[^], they have lots of examples for various connection strings for almost every database.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Thanks, thats really usefull
|
|
|
|
|
I am trying to install (with MSI) a Document to "My Documents" for the current user. So I need to do something like c:\Documents and Settings\[UserName]\My Documents as the DefaultDirectory. How do I get the User name in an Install?
|
|
|
|
|
I asked this a while ago, its quite simple really
string mydocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
the key part is obviously the environment.getfolderpath part, theres quite a few 'special folders' that are in there quite usefull
|
|
|
|
|
Sure in code. But I was talking about an install project. There is a property for a folder called DefaultDirectory. I havn't done very many installs and the ones I have done are pretty straight forward so I could be missing something.
|
|
|
|
|
Hello
You can make an exe file that will copy the files you want to "My Documents" using C# code, and excute it during/after your installation as a custom action.
Regards
|
|
|
|
|
Yes, but there must be a way to do it from the installer. That's probably too big of a hammer for this particular nail. MS must have allowed for a way to do this within the Install Project.
|
|
|
|
|
Tad McClellan wrote: MS must have allowed for a way to do this within the Install Project.
Sorry! Looks like you don't know MS that well!! They are not the "Good guys" anymore.. It would be rational to think that "My Documents" folder is private to the user and why would you put anything in it?!! Stupid, I know, but it's the case. The closest you can get is the "Application data" folder which is in the Documents folder. Otherwise there is one silly workaround. Get a special folder's path -eg. User's Start menu-, which is close to "My Documents" folder, then use a relative path from there to "My Documents".
Regards
|
|
|
|
|
|
I have application which need the windows based authentication so I need help to get the username and user password who has logged in the system currently for the authentication.
Please tell me it's urgent.
regards,
Mr. Dhiraj karmalkar
|
|
|
|
|
You probably can get this info our of MSDN but ...
You won't get the users password (You don't really need it if all you are looking for is to identify the current windows user). Other wise use ...
Environment.UserName
Lots of good stuff in the Environment class so you should check it out.
|
|
|
|
|
Damn right there is, its full of so much useful stuff its not even funny. (Oh, the time i could have saved if only i'd known sooner)
|
|
|
|