Results 1 to 5 of 5

Thread: random number generator to get an item from access

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    2

    random number generator to get an item from access

    hi Everyone,

    I am trying to write a programme for a membership draw. I have created a membership database with 360 members.

    What I want to do is get VB to pick a random number from 1 to 360, then go to the database and then display what the field is located at that number.

    I have created the database so that there is a "number Record" as the key.

    ie if VB selects 60, I want VB to show what information is at record number 60.

    I have looked through the forums for an answer, but cant quite find what I am looking for.

    Hope someone can help

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: random number generator to get an item from access

    Welcome to VB forums.

    Checkout the link:

    How to generate a random number, in between two given values
    CS

  3. #3
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: random number generator to get an item from access

    what is your database structure?
    CS

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    2

    Re: random number generator to get an item from access

    Database structure is:

    Field 1 - Number
    Field 2 - Surname
    Field 3 - Given Name

    All I need it to do is randomly select a number, then display first and given name

  5. #5
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: random number generator to get an item from access

    Heres how to get a random between two values:

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.     'get a random with 5 being the low, 10 being the high boundry
    4.     MsgBox GetRandom(5, 10)
    5.  
    6. End Sub
    7.  
    8. Private Sub Form_Load()
    9.  
    10.     ' randomize to ensure it is random and
    11.     ' not the same sequence each time it runs
    12.     Randomize
    13.  
    14. End Sub
    15.  
    16. Public Function GetRandom(ByVal Low As Long, ByVal High As Long) As Long
    17.    
    18.     'This function takes a low and high and returns a random between them
    19.     GetRandom = CLng((High - Low + 1) * Rnd + Low)
    20.  
    21. End Function

    @cssriraman that function you posted returns a variant and tries to emulate a simple loop by using Goto labels!
    Chris

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