?
Solved

Replacing conditions of an If /Elseif with database fields

Posted on 2003-02-20
2
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

801 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