|
I need just a simple console program to tell how many days and hours (minutes if possible) until this persons next birthday.
He was born on July 26th 1983 at 8:00 pm.
I'm really new at this and I wanted to give him a small exe (console program) for his birthday.
This is all I oould come up with so far:
using System;
class myApp
{
public static void Main()
{
DateTime CurrTime = DateTime.Now;
DateTime JimBDay = DateTime.Compare(CurrTime, "08/01/2008");
Console.WriteLine("Jim's Birthdate: ", JimBDay);
Console.WriteLine("Jim's Birthday is July 26th at 8:00 pm");
Console.WriteLine("{0:F}", CurrTime);
// Need some code to say there are this many days and this many hours until your next birthday (minutes if possible).
Console.Read(); // wait
}
}
|
|
|
|
|
you can use subtract Method to get days and hours and minutes and seconds difference between two date.
see this code:
DateTime CurrTime = DateTime.Now;
DateTime JimBDay = new DateTime(1983,7,26,20,0,0);
TimeSpan span= CurrTime.Subtract(JimBDay);
now span has days and hours and minutes and seconds difference between jim birthday and now.
Human knowledge belongs to the world
|
|
|
|
|
|
JimBDay does not show up on Console.WriteLine("Jim's Birthdate is... ", JimBDay); it just says "Jim's Birthday is..."
and
"span" shows as 9132.03:46:30.4287493 / How can I format this to say...
This many months...
This many days...
This many hours...
and
This many minuts until your next birthday?
using System;
class myApp
{
public static void Main()
{
DateTime CurrTime = DateTime.Now;
Console.WriteLine("Right now the date and time are: {0:F}", CurrTime);
DateTime JimBDay = new DateTime(1983, 7, 26, 20, 0, 0);
Console.WriteLine("Jim's Birthdate is... ", JimBDay);
TimeSpan span = CurrTime.Subtract(JimBDay);
Console.WriteLine(span);
Console.Read();
}
}
|
|
|
|
|
You'll have to pick apart the pieces from the span. There's Days, Minutes, and other properties to investigate.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
try these properties:
Console.WriteLine(span.Days.ToString());
Console.WriteLine(span.Hours.ToString());
Console.WriteLine(span.Minutes.ToString());
Console.WriteLine(span.Seconds.ToString());
Console.WriteLine(span.Milliseconds.ToString());
Human knowledge belongs to the world
|
|
|
|
|
First you need to find the next birthday. Create a DateTime value for the birthday this year (from the current year and the month and day from the birthday). If it has passed, add a year to the value.
Now you just subtract the current date from the value, and you get a TimeSpan that holds the time difference.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
i have a client.exe and c# program. . my exe can open only with my program. my exe cannot open alone.when i click button1 on my program , client.exe will open. But when i double click to client.exe , client.exe cant open.
how can i do this ?
|
|
|
|
|
Please clean up your question. It really makes no sense and is confusing
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi there.
I have Visual Studio 2008.
I want to use this class HttpUtility.HtmlDecode
I couldn't find it in System.Web
Where is it ?
|
|
|
|
|
You have to add a System.Web.dll class library to your project's references.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
|
I see how you can bind to a checkedlistbox for one item to be checked. but what if you have multiple items selected. How can you bind that?
here would be my code for one checked item
fooCheckedListBox.DataBindings.Add("SelectedValue", fooDataSource, "SomePropertyinMyBindingSource");
But I have multiple selected values.
|
|
|
|
|
I have windows form where I am adding control at run time but I couldn't remove them all. Some of them get removed but some stays there. I have spent already 4 hours nothing making sense why I couldn't simply remove controls from the form.
this.Controls(btn);---> this is how iam adding Controls
foreach (Control c in this.Controls)---> this is how am removing-->no achievement
{
this.Controls.Remove(c);
}
=========
but if copy all the controls to an arraylist and then it works. What a nosense is this is C#
ArrayList a = new ArrayList();
foreach (Control c in this.Controls )
{
a.Add(c);
}
foreach (Control cc in a)
{
this.Controls.Remove(cc);
}
modified on Saturday, July 26, 2008 4:01 PM
|
|
|
|
|
Every iteration of your foreach loop is incrementing an index,
but you're removing a control so all the other controls are shifted
up one in the collection. That means you'll miss every other control I
suppose
Maybe something like this:
for (int i = this.Controls.Count - 1; i >= 0; i--)
{
this.Controls.RemoveAt(i);
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote:
for (int i = this.Controls.Count - 1; i >= 0; i--)
{
this.Controls.RemoveAt(i);
}
...or...
foreach (Control c in Controls)
c.Dispose();
Controls.Clear();
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Much better
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
A honeyed cute version of yours I'd say.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Hi,
Control.Controls is a collection with normal functionality.
As Mark said, you can't (reliably) modify a collection with a foreach loop.
However, isn't this.Controls.Clear() what you want?
|
|
|
|
|
How do I dispose the control before or after removeAt?
What i think about Controls.Clear() is that it doesn't remove resources taken by the object. It stays alive in the memory but Controls.Remove remove the object and it's resources. Corrrect me what you think of that
|
|
|
|
|
Neither of them remove the resources taken by the object.
Only the reference is removed from the collection. If there's
no more outstanding references, the objects will eventually
get cleaned up. You should iterate through and dispose any
disposable objects, however, to prevent leaks.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
netJP12L wrote: Controls.Remove remove the object and it's resources
I don't think so. The documentation clearly says:
ControlCollection.Remove Method "Removes the specified control from the control collection."
No more, no less.
The way I read this the Control is not modified, it just is removed from its parents Control list.
The Control remains intact, you can continue to use it, either as a hidden Control,
or you can add it to some other Container/Form/whatever.
The only method that clears resources is Dispose(); once called, the Control should not be used
any longer.
Besides, for Clear the documentation says: "Removes all controls from the collection."
Same verb, only difference is "all".
QED
|
|
|
|
|
Hi,
I investigated this a bit more, by experimenting and using Reflector.
These are my findings:
- a MenuItem holds a reference to the parent it is in, hence:
- a MenuItem is expected to be in no more than one MenuItemCollection, so it would be bad practice
to programmatically create a MenuItem then add it to two or more Menus or MenuItems.
- MenuItem.Dispose() does remove the menu item from its parents list by calling Remove().
- Remove() calls RemoveAt() based on the index kept in MenuItem;
- RemoveAt() modifies the collection, and for the last remaining item also calls Clear() which does
some extra stuff, e.g. repainting the main menu if that was the parent.
So instead of removing menu items and possibly worry about their disposal, one should
dispose of the menu items, and not worry about their removal!
This may be good then:
public static void ClearMenuItems(Menu menu) {
if (menu!=null) {
int count=menu.MenuItems.Count;
for (int i=count-1; i>=0; i--) {
MenuItem mi=menu.MenuItems[i];
if (mi!=null) mi.Dispose();
}
}
}
|
|
|
|
|
Hi,
I have a datagridview with a column that displays a number that comes from a database. I have a data table that has the numbers that show up in said column, and also text that corresponds to that number. I would like to set up a databinding scenario where I can make another column in that datagridview that will display the text that corresponds to the number one column over in that row.
Thanks
|
|
|
|
|
Is there something that you can use to count duplicate entries in an ArrayList?
I have a table that tells if a person is available and adds it to one arraylist. Then I have another table that contains tickets and who the ticket is assigned to. Now what I want to do is search the tickets for the Assigned field if that person is in the available ArrayList:
<br />
ArrayList admins = new ArrayList();<br />
ArrayList available = new ArrayList();<br />
<br />
SqlDataSource sa = new SqlDataSource(ConfigurationManager.ConnectionStrings["HelpDeskConnectionString"].ConnectionString, "SELECT [Admins] FROM [Admin_Table] WHERE ([Area] = 'System Administrator') AND ([Available] = 'True')");<br />
<br />
SqlDataSource count = new SqlDataSource(ConfigurationManager.ConnectionStrings["HelpDeskConnectionString"].ConnectionString, "SELECT [Assigned] FROM [User_Submit] WHERE ([Type] = 'System Administrator')");<br />
<br />
GridView gvAvail = new GridView();<br />
gvAvail.DataSource = sa;<br />
gvAvail.Visible = false;<br />
gvAvail.DataBind();<br />
this.Controls.Add(gvAvail);<br />
<br />
GridView gvCount = new GridView();<br />
gvCount.DataSource = count;<br />
gvCount.Visible = false;<br />
gvCount.DataBind();<br />
this.Controls.Add(gvCount);<br />
<br />
foreach (GridViewRow row in gvAvail.Rows)<br />
{<br />
available.Add(row.Cells[0].Text);<br />
}<br />
for (int i = 0; i < gvCount.Rows.Count; i++)<br />
{<br />
if (available.Contains(gvCount.Rows[i].Cells[0].Text))<br />
{<br />
admins.Add(gvCount.Rows[i].Cells[0].Text);<br />
}<br />
}<br />
<br />
Ok so now I have been racking my brain on this.. So as of right now I know who is available and I have the information of how many Tickets each System Administrator has at the current moment (that is the information in the admins ArrayList.
So I will have duplicate names. Lets say Jane Smith and John Doe are listed in the admins ArrayList. Jane Smith is listed 10 times and John Doe is listed 12 times. So the next ticket that comes in needs to be assigned to Jane Smith. BUT I do not know the names of the System Administrators.
So I need a way to count the duplicate entries and return whose name is listed the LEAST amount of time..
Any help would be greatful! I'm at a stand still.
|
|
|
|