If then statement

Discussion in 'ASP General' started by cmt, Jan 22, 2007.

  1. cmt

    cmt Guest

    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
    cmt, Jan 22, 2007
    #1
    1. Advertising

  2. 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.
    Bob Barrows [MVP], Jan 22, 2007
    #2
    1. Advertising

  3. cmt

    Evertjan. Guest

    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)
    Evertjan., Jan 22, 2007
    #3
  4. cmt

    cmt Guest

    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)
    cmt, Jan 22, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWlrZQ==?=

    greater then / less then

    =?Utf-8?B?TWlrZQ==?=, Nov 4, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,560
    Kevin Spencer
    Nov 4, 2004
  2. JosephByrns

    Slow, then quick then slow

    JosephByrns, Jul 10, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    2,467
    codezilla94
    Nov 13, 2007
  3. Mufasa
    Replies:
    7
    Views:
    400
    Alexey Smirnov
    Sep 4, 2007
  4. Replies:
    0
    Views:
    252
  5. Replies:
    4
    Views:
    519
    cwdjrxyz
    Jan 17, 2006
Loading...

Share This Page