473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

If then statement

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

Jan 22 '07 #1
3 2357
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
<snip>
>
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 & "#<BR>"
Dim today, yesterday, tomorrow, todayhour
Dim testdate

today = DateSerial(Year(Now), Month(Now), Day(Now))
<chuckle>
today = Date()
Response.Write "today contains #" & today & "#<BR>"
yesterday = DateAdd("d", -1, today)
tomorrow = DateAdd("d", 1, today)
todayhour = Hour(Time())
Response.Write "todayhour contains #" & todayhour & "#<BR>"
>
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.
--
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.
Jan 22 '07 #2
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)
Jan 22 '07 #3
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)
Jan 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
37
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
23
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.