Clear a date variable

geo3701 Posted messages 60 Status Member -  
pijaku Posted messages 13513 Registration date   Status Moderator Last intervention   -
Hello,

Here is my problem.

I declare my variables:

Public p_prev, r_prev, p_real, r_real As Date

Then I initialize them:

p_prev = Empty
p_real = Empty
r_prev = Empty
r_real = Empty

But as soon as I query them, here is the result:

p_prev =
p_real =
r_prev =
r_real = 00:00:00

And I don't understand at all why "r_real" returns "00:00:00"

Do you have any idea why or how this is happening?

Thank you

Configuration: Windows Vista / Firefox 35.0

2 answers

gbinforme Posted messages 14930 Registration date   Status Contributor Last intervention   4 744
 
Hello,

As you defined
r_real As Date 
your variable is in date format: this is only normal because a zero date is empty.

--
Always zen
Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupéry
0
pijaku Posted messages 13513 Registration date   Status Moderator Last intervention   2 772
 
Hello,

I would like to add to gbinforme's response (greetings, by the way) that this declaration:
Public p_prev, r_prev, p_real, r_real As Date

is equivalent to:
Public p_prev As Variant, r_prev As Variant, p_real As Variant, r_real As Date

In VBA, you need to specify the type for each variable. So:
Public p_prev As Date, r_prev As Date, p_real As Date, r_real As Date

That's why you get:
p_prev =
p_real =
r_prev =
r_real = 00:00:00

Before, I could never finish my sentences... but now I
0
gbinforme Posted messages 14930 Registration date   Status Contributor Last intervention   4 744
 
Good evening pijaku,

Well spotted! I read a bit too quickly, focusing on the exception.

Have a good evening.
0
pijaku Posted messages 13513 Registration date   Status Moderator Last intervention   2 772 > gbinforme Posted messages 14930 Registration date   Status Contributor Last intervention  
 
Hi gbinforme,

No problem.
The answers complement each other, and the main thing is that the issue is resolved.
See you later
Have a good day
0