If then statement

C

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
 
B

Bob Barrows [MVP]

cmt said:
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 & "# said:
Dim today, yesterday, tomorrow, todayhour
Dim testdate

today = DateSerial(Year(Now), Month(Now), Day(Now))
<chuckle>
today = Date()
Response.Write "today contains #" & today & "# said:
yesterday = DateAdd("d", -1, today)
tomorrow = DateAdd("d", 1, today)
todayhour = Hour(Time())

Response.Write "todayhour contains #" & todayhour & "# said:
testdate = completeddate
testdate = DateSerial(Year(testdate), Month(testdate), Day(testdate))

Response.Write "testdate contains #" & testdate & "#<BR>"

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

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

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

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.
 
E

Evertjan.

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! ]
 
C

cmt

Thanks guys! I will try these ideas out!


Evertjan. said:
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! ]
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top