[DATE - newbie] change and set back

A

an

TOTAL NEWBIE

I need to change the date to 05/05/2005,
display a messagebox,
then set the current date back.

In VB6 I use:

aaa = Date
Date = #05/05/2005#
Msgbox "Hallo"
Date = aaa


In VbNet I'm in a nightmare.
Can you help me?
 
S

Steve_Black

Are you saying you need to change the computer's system date?

If so, I'm not sure how to do that. However, to get access to the date
use Today.Date.
 
A

an

Yes I need to change the computer's system date,
after having stored the current one in a variable,
then set it back...
 
H

Herfried K. Wagner [MVP]

an said:
I need to change the date to 05/05/2005,
display a messagebox,
then set the current date back.

In VB6 I use:

aaa = Date
Date = #05/05/2005#
Msgbox "Hallo"
Date = aaa


In VbNet I'm in a nightmare.

\\\
Dim aaa As Date = Today
Today = #5/5/2005#
MsgBox("Hallo")
Today = aaa
///
 
A

an

The snippet doesn't work
all the rows
(except the MessageBox one)
have one or more errors.

Note:
I use Option Explicit and option Strict both set ON
 
H

Herfried K. Wagner [MVP]

an said:
The snippet doesn't work
all the rows
(except the MessageBox one)
have one or more errors.

Note:
I use Option Explicit and option Strict both set ON

I have turned them on too (VB.NET 2003) and the code compiles just fine.
 
A

an

I have VS2005 TeamSuite Italian.

First of all
I've turned now both the Option Explicit and Strict OFF
to have more flexiblity.
 
A

an

Re-check my solution. The screenshots are not showing the solution I
posted!

Sorry
it was driving me crazy;
it works,


I have a couple of questions:

what's the difference beteween
aaa = Today
aaa = DateTime.Today
both works,
so what the difference consist of?

If I want to perform the same task,
but changing the time only
(set to: h 10 m 10 s10 )
and then set it back?
 
H

Herfried K. Wagner [MVP]

an said:
what's the difference beteween
aaa = Today
aaa = DateTime.Today
both works,
so what the difference consist of?

Did you already check out the documentation on both? To do so, place the
caret over them and press the F1 key.
If I want to perform the same task,
but changing the time only
(set to: h 10 m 10 s10 )
and then set it back?

Maybe you want to use 'TimeOfDay' instead of 'Today'.
 
A

an

Did you already check out the documentation on both? To do so, place the
caret over them and press the F1 key.


I did:
Today seems a member of the DateandTime module
but
honestly I didn't understand a lot about the usage difference
also because in the same datetime.today page

there is the following example

Dim value As DateTime
value = DateAndTime.Today
DateAndTime.Today = value

and then this slightly different one

Dim thisDate As Date
thisDate = Today

so currently I 'm not sure about the usage
of datetime.today and of today

----------

Also, we have:
Date, DateTime, DateandTime, Today, DateTime.Today, DateAndTime.Today
isn't it?
Well I'm confused;
just to not bother you,
have you a page with a schema/diagram/chart ?


Maybe you want to use 'TimeOfDay' instead of 'Today'.


shortly back to the time setting task:

by following your hint, I succeeded,
but at the beginning I declared :
Dim aaa As DateTime
while DateTime is not a Type (although the IDE gave me no error).

How would you have declared it?
 
H

Herfried K. Wagner [MVP]

an said:
Also, we have:
Date, DateTime, DateandTime, Today, DateTime.Today, DateAndTime.Today
isn't it?

'Date' and 'DateTime' are types. 'Date' is VB's alias for 'DateTime'.
'DateTime' has a 'Today' property, thus you can either write
'DateTime.Today' or 'Date.Today'.

'DateAndTime' is a module in VB's function library
("Microsoft.VisualBasic.dll"). 'Today' is a property of this module. As
modules are imported automatically in VB, it's not necessary to qualify
access to the 'Today' property with the name of the module containing it
('DateAndTime.Today').
by following your hint, I succeeded,
but at the beginning I declared :
Dim aaa As DateTime
while DateTime is not a Type (although the IDE gave me no error).

'DateTime' is actually a type, but VB defines 'Date' as an alias for
'DateTime'. Thus personally I always use 'Date' instead of 'DateTime' in my
code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top