CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Random Searches

  1. #1
    Join Date
    Jul 1999
    Posts
    1

    Random Searches

    This actually deals with Visual Basic and Access. Here's the scenario: I have an Access Database that I want to do a query/report on. I have a selection criteria screen which can return the results of my query into the report. My results always comes up in the order that the data is stored in the database. I want my data to be returned in a random order.
    I thought about adding a numeric field to the Table and leaving it blank. Is it possible to generate a random number using Visual Basic and assign that number to that numeric field, then sort on that field so that everytime I run the query, it will be in a different order? Or does anyone know of a way of returning a search in random order. I eventually want to move this to a website, so do you think that Visual InterDev could return a search in random order?


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Random Searches

    that's a funny requirement, that I've never heard before.
    I'd read all rows from your query using the GetRows method of the recordset object.
    Then, all your rows are in memory.
    You can then use VB's Randomize statement and Rnd function to display your records in a random fashion.

    if you query returned e.g. 6 records you could use this code to get a random number.
    MyValue = Int((6 * Rnd) + 1) ' Generate random value between 1 and 6. (stolen from the vb docs).

    Just store you numbers in an array so as to avoid displaying the same record multiple times.


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured