?
Solved

Replacing conditions of an If /Elseif with database fields

Posted on 2003-02-20
2
Medium Priority
?
179 Views
Last Modified: 2010-04-17
I am probably just having a brain fart, but I cant seem to see this answer.

I have the following code that works fine:

If ((navmonth = 4 And dateCounter > 4) Or (navmonth = 5 And dateCounter < 12)) And (Calendar = "Turkey") Then
    'do something
   
ElseIf ((navmonth = 9 And dateCounter > 26) Or (navmonth = 10 And dateCounter < 27) Or (navmonth = 11 And dateCounter >= 1) Or (navmonth = 1 And dateCounter < 5) Or (navmonth = 12)) And (Calendar = "Whitetail Archery") Then

    'do something else
Else
    'do default
   
End If

However, as you can see the conditions are hard coded.  I need this app to be dynamic, fed by a database.  I have set up a database and would like to sub the condtions of the If/elseIf for the values in the recordset.  I will need to loop through the records to see if the conditions will be true for each record.  Basically this populates an ASP Calendar.  I have the following code that works if I only have one record in the database:

dateSelect = navmonth & "/" & dateCounter & "/" & navyear
CalDate = cdate(dateSelect)

If (CalDate >= RSSeason("DateOpen") And CalDate <= RSSeason("DateClosed")) And (Calendar = RSSeason("Game")) Then
    'do something
   
Else
    'do default
   
End If

But if I use a Loop, I get multiple days(on the calendar) for each record in the table.  The only other ways I see scramble my conditional statements.  Any Ideas, its 5 in the morning and I am out of steam?

Thanks


0
Comment
Question by:rebaldy1
2 Comments
 

Accepted Solution

by:
gament earned 200 total points
ID: 7986416
I like to use ODBC connections myself but any SQL based connection should work.  The Select statement may need some tweeking depending upon field types.  Not knowing how the fields are setup in the database allows only a guess but hopefuly there's enough here to help out :)

dateSelect = navmonth & "/" & dateCounter & "/" & navyear
CalDate = cdate(dateSelect)

Set s = Server.CreateObject("ADODB.Connection")
s.Open("DSN=myodbcname;PWD=mypass;UID=myusername")

foundone=0

set RSSeason=s.execute("select myfield from mytable where DateOpen>="&CalDate&" And DateClosed<="&CalDate&" And Game='"&Calendar&"';")

do while not RSSeason.eof
foundone=1
   'do something
 
RSSeason.movenext
loop
s.close

if foundone=0 then
' do default cause there was nothing there
end if

... it may also be easier to do it like this if you have multiple choices for Calendar (this is a little crude - a switch may work better but you'll get the idea :):

dateSelect = navmonth & "/" & dateCounter & "/" & navyear
CalDate = cdate(dateSelect)

Set s = Server.CreateObject("ADODB.Connection")
s.Open("DSN=myodbcname;PWD=mypass;UID=myusername")

foundone=0

set RSSeason=s.execute("select myfield,Game from mytable where DateOpen>="&CalDate&" And DateClosed<="&CalDate&";")

do while not RSSeason.eof
foundone=1
if RSSeason("Game")="Choice1" then
'do the stuff for choice1
end if
if RSSeason("Game")="Choice2" then
'do the stuff for choice2
end if
RSSeason.movenext

loop
s.close

if foundone=0 then
' do default cause there was nothing there
end if

0
 
LVL 3

Expert Comment

by:FaithRaven
ID: 9307773
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept gament's comment
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

FaithRaven
EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Make the most of your online learning experience.
Introduction to Processes
Screencast - Getting to Know the Pipeline

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question