Page 1 of 1

Date() in If statement

Posted: Wed Jan 16, 2008 10:41 am
by CoolIce
Hi

I was just wondering why

Code: Select all

If Date() = specifiedDate$
doesn't work. Is there another method of doing this?
I want to launch some code when the specifiedDate$ is equal to the day the exe is started and
launch some other code if this is not the case.

I tried

Code: Select all

    If Date() = specifiedDate$
        hooray()
    Else
        loose()
    EndIf
but it always launches the second subroutine (else statement).

Re: Date() in If statement

Posted: Wed Jan 16, 2008 11:24 am
by Misthema
CoolIce wrote:I tried

Code: Select all

    If Date() = specifiedDate$
        hooray()
    Else
        loose()
    EndIf
but it always launches the second subroutine (else statement).
It _ALWAYS_ runs the Else -statement, it the If -statement isn't true.

And have you even tried "today" -day (stupidly said :D) on it?
When I tried it, it worked:

Code: Select all

If Date() = "16 Jan 2008" Then Print "Today is 16th day of January 2008"
WaitKey
Remember to input the day like I did on that code.

Re: Date() in If statement

Posted: Wed Jan 16, 2008 12:05 pm
by CoolIce
You don't understand.

Of course I know that specifiedDate$ has to be the "today" day.
I put the date (today) in afile, read it into the variable specifiedDate$ and just want to check with the if-statement if it is really the todays date.

The reading loop works, I tried it via "print".
When I tried it, it worked:
Yes, but you didn't do the same thing. I want to compare the variable to "Date()", not a text. This is a difference, and THIS didn't work in my code.

Re: Date() in If statement

Posted: Wed Jan 16, 2008 2:12 pm
by Misthema
CoolIce wrote:I want to compare the variable to "Date()", not a text. This is a difference, and THIS didn't work in my code.
Hmm.. Why don't you try to check it this way (if I understanded correctly):

Code: Select all

If specificDate$ = Date() Then
    code...
Else
    more_code...
EndIf
And there must be text in the variable, like "16 Jan 2008" etc., 'coz Date() shows it like that.

Re: Date() in If statement

Posted: Wed Jan 16, 2008 2:14 pm
by CoolIce
that's what i first tried and it didn't work either.

the variable content is like you wrote. so that's not the problem.

Re: Date() in If statement

Posted: Wed Jan 16, 2008 2:30 pm
by TheFish
CoolIce wrote:that's what i first tried and it didn't work either.

the variable content is like you wrote. so that's not the problem.
Did you write "jan" or "Jan" in the variable? because this works well for me:

Code: Select all

specifiedDate$ = "16 Jan 2008"
If Date() = specifiedDate Then
    Print "If-statement"
Else
    Print "Else-statement"
EndIf
WaitKey 
Or did you declare specifiedDate in another function than the one youre comparing it in? If you did, it must be a global variable.