If then statement

If then statement

am 22.01.2007 14:38:09 von cmt

I am trying to display an image link based on the day of the week.

My code gets the days for today, yesterday, and tomorrow and also
today's hour.

Note:
function returns 1 if image link should work
function returns 0 if image link should be disabled

It should display the image link if:

the passed in date is yesterday
the passed in date is today
the passed in date is tomorrow(and today hour is 5pm or later)

It should ALSO display the image link if:

-the current day and hour is Friday AFTER 5pm and the passed in date is
Friday, Saturday, Sunday, or Monday.

Somehow I don't think my If/Then logic is working because come Friday
at 5pm and after, Sunday's image link is always disabled when it should
be enabled.


---begin code---

Function DispCaseInfo(completeddate)

Dim today, yesterday, tomorrow, todayhour
Dim testdate

today = DateSerial(Year(Now), Month(Now), Day(Now))
yesterday = DateAdd("d", -1, today)
tomorrow = DateAdd("d", 1, today)
todayhour = Hour(Time())

testdate = completeddate
testdate = DateSerial(Year(testdate), Month(testdate), Day(testdate))


If testdate = today OR testdate = yesterday OR (testdate = tomorrow AND
todayhour >= 17) Then
DispCaseInfo = 1 'link enabled
ElseIf WeekDay(today) <> 6 And Weekday(today) <> 7 And Weekday(today)
<> 1 Then
DispCaseInfo = 0 'link disabled
ElseIf testdate = 6 Or testdate = 7 Or testdate = 1 Or testdate = 2
Then
DispCaseInfo = 1 'link enabled
End If

End Function

---end code---

For example, if it's Tuesday then Mondays, Tuesdays image link should
be enabled, and if it happens to be after 5pm then Wednesdays image
link should be enabled. All else disabled.

If it's Friday afte 5pm, Fridays, Saturdays, Sundays, and Mondays image
links should all be enabled. All else disabled.

Can anyone see a flaw in my If/Then statement?

Thanks

Re: If then statement

am 22.01.2007 15:04:39 von reb01501

cmt wrote:
> I am trying to display an image link based on the day of the week.
>
> My code gets the days for today, yesterday, and tomorrow and also
> today's hour.
>
> Note:
> function returns 1 if image link should work
> function returns 0 if image link should be disabled
>

>
> Somehow I don't think my If/Then logic is working because come Friday
> at 5pm and after, Sunday's image link is always disabled when it
> should be enabled.
>
>
Here is how I go about solving this type of problem:
Add some debugging statements:

> ---begin code---
>
> Function DispCaseInfo(completeddate)
>
Response.Write "completeddate contains #" & completeddate & "#
"
> Dim today, yesterday, tomorrow, todayhour
> Dim testdate
>
> today = DateSerial(Year(Now), Month(Now), Day(Now))

today = Date()
Response.Write "today contains #" & today & "#
"

> yesterday = DateAdd("d", -1, today)
> tomorrow = DateAdd("d", 1, today)
> todayhour = Hour(Time())

Response.Write "todayhour contains #" & todayhour & "#
"

>
> testdate = completeddate
> testdate = DateSerial(Year(testdate), Month(testdate), Day(testdate))
>

Response.Write "testdate contains #" & testdate & "#
"

Response.Write "(testdate = today) evaluates to '" & _
(testdate = today) & "'
"

Response.Write "(testdate = yesterday) evaluates to '" & _
(testdate = yesterday) & "'
"

Response.Write "(testdate = tomorrow AND todayhour >= 17) " & _
"evaluates to '" & _
(testdate = tomorrow AND todayhour >= 17) & "'
"

etc.

Run the code and look at the result when it doesn't do what you expect
it to do. If you still cannot see the problem, show us the results.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Re: If then statement

am 22.01.2007 15:57:25 von exjxw.hannivoort

cmt wrote on 22 jan 2007 in microsoft.public.inetserver.asp.general:

> For example, if it's Tuesday then Mondays, Tuesdays image link should
> be enabled, and if it happens to be after 5pm then Wednesdays image
> link should be enabled. All else disabled.
>
> If it's Friday afte 5pm, Fridays, Saturdays, Sundays, and Mondays
> image links should all be enabled. All else disabled.
>
> Can anyone see a flaw in my If/Then statement?

Start over and try this:

Function DispCaseInfo(testdate)

today = Now()
tdhour = Hour(today)
wday = WeekDay(today)
diffdays = datediff("d",today,testdate)

DispCaseInfo = 0
If wday<3 OR (wday = 5 AND tdhour >= 17) OR wday>5 OR
diffdays = -1 OR diffdays = 0 OR
(diffdays = 1 AND tdhour >= 17) Then
DispCaseInfo = 1
End If

End Function

[ The If..Then on one line please! ]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Re: If then statement

am 22.01.2007 20:13:28 von cmt

Thanks guys! I will try these ideas out!


Evertjan. wrote:
> cmt wrote on 22 jan 2007 in microsoft.public.inetserver.asp.general:
>
> > For example, if it's Tuesday then Mondays, Tuesdays image link should
> > be enabled, and if it happens to be after 5pm then Wednesdays image
> > link should be enabled. All else disabled.
> >
> > If it's Friday afte 5pm, Fridays, Saturdays, Sundays, and Mondays
> > image links should all be enabled. All else disabled.
> >
> > Can anyone see a flaw in my If/Then statement?
>
> Start over and try this:
>
> Function DispCaseInfo(testdate)
>
> today = Now()
> tdhour = Hour(today)
> wday = WeekDay(today)
> diffdays = datediff("d",today,testdate)
>
> DispCaseInfo = 0
> If wday<3 OR (wday = 5 AND tdhour >= 17) OR wday>5 OR
> diffdays = -1 OR diffdays = 0 OR
> (diffdays = 1 AND tdhour >= 17) Then
> DispCaseInfo = 1
> End If
>
> End Function
>
> [ The If..Then on one line please! ]
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)