Visual InterDev

Quote of the Day Sample

See Also      Tasks

This sample displays a random quote returned from the Quote table in the Gallery database.

Behind the Scenes

This sample uses one file: Quote.asp. This file generates a random number based on the total number of quotes in the Quote table and moves the record pointer in the recordset to this random number.

Once the recordset has opened the table, a Visual Basic®, Scripting Edition (VBScript) routine is run to generate the random number. The routine uses the Recordset.getCount method to determine the number of records in the recordset.

Once the random number is generated the record pointer in the recordset is moved using the Recordset.moveAbsolute method. The code below demonstrates how this done:

   Sub QuoteRecordset_ondatasetcomplete()
      Randomize()
      intQuote = Int((QuoteRecordset.getCount()) * Rnd + 1)
      QuoteRecordset.moveAbsolute(intQuote)
   End sub

The quote and the author are displayed using two data-bound labels. The first one is bound to the quote field and the second one is bound to the author field.