By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,578 Members | 1,771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,578 IT Pros & Developers. It's quick & easy.

Time?

P: n/a
Hi,
I am using Vb.net and I want to know how to put the Time, Date
which ticks??

Please reply as soon as possible

Dean

PS: Please make the answer simple because I am only 11 Yrs old and New
to VB

Feb 12 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"Dean" <si************@gmail.com> wrote in news:1139737865.257284.320820
@g14g2000cwa.googlegroups.com:
Hi,
I am using Vb.net and I want to know how to put the Time, Date
which ticks??

Please reply as soon as possible

Dean

PS: Please make the answer simple because I am only 11 Yrs old and New
to VB


First, make sure you have a label or some other control on your form that
can display the data. If you don't, you can create one by double-clicking
the control marked "Label" on the toolbox...

Next, double-click the form to open the Form.Load procedure. Stuff you
put in there gets done as soon as the program starts.

Copy and paste this bit of code into that procedure. Make sure you put it
all on one line!

Label1.Text = Microsoft.VisualBasic.DateAndTime.DateString & " " &
Microsoft.VisualBasic.DateAndTime.TimeOfDay

That will put the time and date on the form when the program starts, but
it won't make it tick...

You'll need to add a Timer to do that! The Timer is also on the toolbar,
but you'll need to scroll down by clicking the arrow at the bottom of the
toolbox to find it.

Double-click to add it to the form. It should show up in a little tan
area right below the form.

Select it, and look at its properties; they'll usually show up in a big
box to the right. All timers start off disabled, so you'll have to change
*Enabled* to *True* to make sure it starts working as soon as the program
starts.

See that number *100* next to the word Interval? That's how often the
Timer tries to do its job. I know it seems like a big number, but it's
actually in milliseconds, which means that you need *1000* to have one
second.

Since the timer will only need to tick once every second, an interval of
*100* means that it will only do something useful once every ten times
that it's run. So an interval of *1000* is actually much better.

Now double-click the timer, and add the same code that you added to the
Form.Load procedure earlier.

Now you should have an updating date and time in your program!

(Apologies if the foregoing appears condescending; I have so little
immediate experience w/ children that my assumptions & expectations may
be inaccurate.)

The Confessor
Feb 12 '06 #2

P: n/a
"Dean" <si************@gmail.com> schrieb:
I am using Vb.net and I want to know how to put the Time, Date
which ticks??


Add a 'System.Windows.Forms.Timer' component from the toolbox to the form.
Set its interval property to an appropriate value and its 'Enabled' property
to 'True'. Double-click the component and add this code to the 'Tick' event
handler:

\\\
Me.Label1.Text = Now.ToShortDateString() & " " & Now.ToShortTimeString()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 12 '06 #3

P: n/a
Dean,

It makes no sense use ticks with the datetime. It is a "long" value without
a real meaning, than that it starts at 1-1-1 at 1:1:1 with a non existing
calendar. There is now not really any calendar anymore which really starts
at 1-1-1, is it saying absolute nothing.

The only way I know that it can be used is to compare if date a is equal
date b.

Just to give you an idea.

Cor
Feb 12 '06 #4

P: n/a
> (Apologies if the foregoing appears condescending; I have so little
immediate experience w/ children that my assumptions & expectations may
be inaccurate.)

The Confessor


Hi Confessor,

Well, I think you did a pretty admirable job with the explanation. And no,
it didn't appear condescending to me, atleast. ;-)

Regards,

Cerebrus.
Feb 12 '06 #5

P: n/a
The Confessor <in*****@reply.to.group> wrote in
news:Xn*********************************@130.81.64 .196:
"Dean" <si************@gmail.com> wrote in
news:1139737865.257284.320820 @g14g2000cwa.googlegroups.com:
Hi,
I am using Vb.net and I want to know how to put the Time, Date
which ticks??

Please reply as soon as possible

Dean

PS: Please make the answer simple because I am only 11 Yrs old and
New to VB


First, make sure you have a label or some other control on your form
that can display the data. If you don't, you can create one by
double-clicking the control marked "Label" on the toolbox...

Next, double-click the form to open the Form.Load procedure. Stuff you
put in there gets done as soon as the program starts.

Copy and paste this bit of code into that procedure. Make sure you put
it all on one line!

Label1.Text = Microsoft.VisualBasic.DateAndTime.DateString & " " &
Microsoft.VisualBasic.DateAndTime.TimeOfDay

That will put the time and date on the form when the program starts,
but it won't make it tick...

You'll need to add a Timer to do that! The Timer is also on the
toolbar, but you'll need to scroll down by clicking the arrow at the
bottom of the toolbox to find it.

Double-click to add it to the form. It should show up in a little tan
area right below the form.

Select it, and look at its properties; they'll usually show up in a
big box to the right. All timers start off disabled, so you'll have to
change *Enabled* to *True* to make sure it starts working as soon as
the program starts.

See that number *100* next to the word Interval? That's how often the
Timer tries to do its job. I know it seems like a big number, but it's
actually in milliseconds, which means that you need *1000* to have one
second.

Since the timer will only need to tick once every second, an interval
of *100* means that it will only do something useful once every ten
times that it's run. So an interval of *1000* is actually much better.

Now double-click the timer, and add the same code that you added to
the Form.Load procedure earlier.

Now you should have an updating date and time in your program!

(Apologies if the foregoing appears condescending; I have so little
immediate experience w/ children that my assumptions & expectations
may be inaccurate.)

The Confessor


From another poster, you can do date/time much more succinctly by adding:

Label1.Text = Now

to both procedures, instead of that massively elongated bit of text I
posted earlier.

This highlights my biggest beef with VB.Net: There are generally at least
three ways to accomplish any simple task, be it creating a date/time, or
creating a two-dimensional control array.

And there's nothing to tell you which is more efficient.

The Confessor
Feb 12 '06 #6

P: n/a
>>Hi,
I am using Vb.net and I want to know how to put the Time, Date
which ticks??


well Cor ,,, i hope you see it now :-) ,,,,, cause you are talking about
a different form of ticks asd the poor boy mentioned
He means with ticks a ticking clock ( one that updates )

You mean with ticks the processor ticks
PS: Please make the answer simple because I am only 11 Yrs old and New
to VB

it took me a few minutes before i understood what you meant ( the poor ,
poor boy )

( just kidding )

regards

Michel Posseth [MCP]
"Cor Ligthert [MVP]" <no************@planet.nl> schreef in bericht
news:%2****************@TK2MSFTNGP11.phx.gbl... Dean,

It makes no sense use ticks with the datetime. It is a "long" value
without a real meaning, than that it starts at 1-1-1 at 1:1:1 with a non
existing calendar. There is now not really any calendar anymore which
really starts at 1-1-1, is it saying absolute nothing.

The only way I know that it can be used is to compare if date a is equal
date b.

Just to give you an idea.

Cor

Feb 12 '06 #7

P: n/a
Thank you "The Confessor" you gave the answer wanted this code for so
long!!

Feb 13 '06 #8

P: n/a
Hi,
This highlights my biggest beef with VB.Net: There are generally at least
three ways to accomplish any simple task, be it creating a date/time, or
creating a two-dimensional control array.

And there's nothing to tell you which is more efficient.

That I have with the English language as well (what is not more than a
program language to communicate between one or more peers). If there was one
way .................... than it would probably give even more
misunderstandings.

Cor
Feb 13 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.