|
I am trying to calculate time differences in C#, I get the start time in a Lable1 and end time in Lable2, and The start time can start at 23:30 and end time at 0:30hrs, I am only looking for difference in time. Please advice.
Naveen
-- modified at 14:51 Tuesday 2nd October, 2007
It will help a lot if i can get the Code..
Naveen
|
|
|
|
|
You may subtract one time from other if you store data in two variables of DateTime type.
Such as-
DateTime i,j;
j.Subtract(i);
I hope this helps .
-Dave.
Dave Traister,
ComponentOne LLC.
www.componentone.com
|
|
|
|
|
Dave already gave you the answer, is it really that hard to understand what he explained?
DateTime startDate = DateTime.Parse(Label1.Text);
DateTime endDate = DateTime.Parse(Label2.Text);
TimeSpan span = endDate - startDate;
|
|
|
|
|
Thanks Chris
You'r code helped me a lot...
Appreciate your help...
|
|
|
|
|
Both Dave and Chris explain how to calculate the difference, but you really need the date part also. In your example, the time rolls over to the next day. So you really need the difference from (I just made up a date) "10/2/2007 23:30" to "10/3/2007 00:30" (a difference of 1 hour). If you just take the time, then the date part will most likely be the same and then the difference is 23 hours.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi Guys,
Application is almost done and now I'm trying to write the installer. Problem is I'm using an XML file for some of the configuration and I can't find how to create one using the installer.
Is there something built into visual studio that can do this or will I have to write create some sort of post-install script?
|
|
|
|
|
If you include the xml file in your Application project (e.g. the C# exe project), then set it's Build Action to Content (select the file in the Solution explorer and then look at the Properties window). Then in your installer you can include the "Content Files" from your project. The files will then be copied to the install directory.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thanks Tom,
but how do I modify the file during the install process? It's going to include some database strings, and other application/user specific settings. We normally have a wizard that runs on the first instance of the website that takes care of this. For security we have removed this and want it done during the install.
(The old method wasn't perfect, but as a web developer, it worked for me)
Regards.
Joe
|
|
|
|
|
If you want to create a config file during the install process, then I would use a Custom Action[^]. Here's an example[^] that creates a database.
This blog entry[^] may help if you are deploying a web project. This blog entry[^] may help you if you need to troubleshoot an issue with your Custom Action.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I'm trying to get the usernames of all the admins on the local machine. This is what I have:
<br />
DirectoryEntry admGroup = localMachine.Children.Find("administrators", "group");<br />
object members = admGroup.Invoke("members",null);<br />
<br />
foreach (object member in (IEnumerable) members)<br />
{<br />
DirectoryEntry admin = (DirectoryEntry)member;<br />
Console.WriteLine(admin.Name);<br />
}<br />
The problem I'm having is with generics. The compiler is requiring a type argument for IEnumerable, but I've tried object and System.__ComObject neither of which will work. I know in .NET 1.1 that should of worked, but I'm at a loss of how to fix it now.
|
|
|
|
|
Make sure you are "using System.Collections;". The generic version of IEnumerable is defined in System.Collection.Generic (which is included in new C# files created by Visual Studio by default). But System.Collections is not included by default.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
That worked perfectly. Thank you for your help.
|
|
|
|
|
Hi everyone,
I have a question here: I have a big project made in C# with lots of userforms and a huge code behind it. I want to convert the whole project to VB.NET 2005 project .Online convertors converts only few code not the whole userforms ..
Any ideas? :->
Thanks,
Dan
|
|
|
|
|
|
I used sharpdevelop and it works.
|
|
|
|
|
There are C# to VB converters (not online) that convert entire projects. Just google on "C# to VB converter".
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
C++ to C++/CLI Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: converts C# to C++/CLI and VB to C++/CLI
|
|
|
|
|
Hi,
Thankyou both of you for help.
When I tried SharpDevelop and converted the project but when I open it in VB.NET it showed me 210 errors !! & the forms can't be loaded in designer mode !
And the http://www.tangiblesoftwaresolutions.com
convertor converts only first 1000 lines . As In my project there are over 2000 lines of code so it everytimes shows that "No Line Of Code Converted !"
What to do now ??
Thanks,
Dan
|
|
|
|
|
I'm trying to figure out why you would want to do convert the library into another language. Except for the syntax, CSharp and VB.Net have access to the same libraries. And are compiled down to the same thing.
As a C# developer the convertors have only been useful in letting me understand the VB language. In the end it was easier to leave things they way they were and create a new namespace.
|
|
|
|
|
Hi,
Yes , now I am understanding the real matter..
WhoisUrBuddy wrote: I'm trying to figure out why you would want to do convert the library into another language
It's working programme not a library & I want to run it in VB.NET so I was looking for such things..
WhoisUrBuddy wrote: In the end it was easier to leave things they way they were and create a new namespace.
Yes, Now I am planning to rewite the code so that I can learn VB and my work will be completed ...
Anyway , Thanks for help,
Dan
|
|
|
|
|
How does one change the color of a listview's header? Code please. Thanks
|
|
|
|
|
You need to draw the header yourself. This article[^] should get you started.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I have too many functions in one class, therefore, I want to know is it possible to seperate the functions into seperate files? So far, I only know one class is saved as one file ".cs".
|
|
|
|
|
|
You can have the same class split over multiple files (from .NET 2 on), by using the partial keyword. It doesn't matter what the filenames are (before the .cs that is), because the compiler will combine them together.
However, if you have too many functions then this would tend to indicate that there may be a problem with your design. You may be linking too many things together that really should be separated.
Anyway here's a quick example:
FirstFile.cs
public partial class MyClass
{
}
SecondFile.cs
public partial class MyClass
{
} Interestingly enough, you could create a member in FirstFile.cs and it would be available in SecondFile.cs. This behaviour is visible in the way that Visual Studio.Net breaks up form files.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
As a best practice it is advised to refractor functions that do similar things in different classes. That way you avoid having problem with too much code in the same .cs file. In my case I choose to have at most 400 lines of code in a class.
I am fighting against the Universe...
Reference-Rick Cook
|
|
|
|