Clear a date variable

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

  1. Contributor
    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
    1. Moderator
      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
      1. Contributor
        Good evening pijaku,

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

        Have a good evening.
        0
      2. Moderator
        @gbinformeHi 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