Help me optimize my code :(

Results 1 to 2 of 2

Thread: Help me optimize my code :(

  1. #1
    Join Date
    Dec 1969

    Default Help me optimize my code :(

    Regrettably, I am a self-taught coder.. I&#039;ve taken little time to research more efficient ways to code, since I&#039;ve been thrown into many projects head first.. They all work.. But they aren&#039;t as efficient as they could be.. I&#039;m attaching a little code snippet here that represents some code that I typically use.. If you could suggest a more efficient way of doing it, I would be most appreciative... Don&#039;t laugh :)<BR><BR>&#060;%<BR>&#039;Counts the number of records in the DB<BR>SQLQUOTECOUNT = "SELECT Count(todaysdate) as quotecount FROM quotes"<BR>Set quotecount = Conn.Execute(SQLQUOTECOUNT)<BR><BR>&#039;Grabs the date stored in the DB<BR>SQLQUOTECHECK = "SELECT todaysdate FROM quotes"<BR>Set quotecheck = Conn.Execute(SQLQUOTECHECK)<BR><BR>&#039;If the date is not equal to today, then<BR>If quotecheck(0) &#060;&#062; date() Then<BR>&#039;Update the DB to the new date<BR> SQLUPDATE="UPDATE quotes SET todaysdate = #" & date() & "#"<BR> set RS = Conn.Execute(SQLUPDATE)<BR><BR>&#039;Get a random number<BR> RANDOMIZE<BR> LowestNumber = 81<BR> HighestNumber = quotecount("quotecount")<BR> <BR> RandomValue = INT((HighestNumber-LowestNumber+1)*Rnd+LowestNumber)<BR> <BR>&#039;Pull a quote out of the database with this number<BR> SQLSHOWQUOTE = "SELECT quote, author FROM quotes WHERE quoteid = " & randomvalue & ""<BR> Set showquote = Conn.Execute(SQLSHOWQUOTE)<BR><BR>&#039;Tell the database that this quote IS the quote of the day for multiple user purposes.<BR> SQLUPDATE="UPDATE quotes SET chosen = &#039;yes&#039; WHERE quoteid = " & randomvalue & ""<BR> set RS = Conn.Execute(SQLUPDATE)<BR><BR>&#039;Show the quote<BR> response.write(showquote(0))<BR>else<BR>&#039;Pull the flagged quote out of the DB<BR> SQLSHOWQUOTE = "SELECT quote, author FROM quotes WHERE chosen = &#039;yes&#039;"<BR> Set showquote = Conn.Execute(SQLSHOWQUOTE)<BR><BR>&#039;And show the quote (formatted with HTML)<BR> response.write("""" & showquote(0) & """&#060;P ALIGN=RIGHT&#062;-&#060;FONT COLOR=BLUE&#062;" & showquote(1) & "&#060;/FONT&#062;")<BR>end if<BR>%&#062;<BR><BR><BR>Thanks for any help :) It works.. It&#039;s just ugly.<BR><BR>dep

  2. #2
    Join Date
    Dec 1969

    Default Good use for Application variable

    This would be the perfect application for the Application variable! I&#039;d check the faqs on Applicaiton variables but the basic idea would be to just hit the database once a day to get your quote.<BR><BR>Psuedo code:<BR><BR>function getQuote()<BR> if Application("QuoteDate") &#060;&#062; Today Then<BR> set new quote<BR> set Application("QuoteDate") = Today<BR> end if<BR> getQuote = Application("Quote")<BR>end function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts