MG please help

Results 1 to 2 of 2

Thread: MG please help

  1. #1
    moti Guest

    Default MG please help

    How do i get a random record and not a rundom # ?<BR>I do not want to take your time but please help me I am putting here my source , please advise me what to do .<BR><BR><BR><BR>&#039The first SQL querry<BR> SQL = "select count(*) as maxID from books" <BR> <BR>&#039Using the Record Set to use the Sql via the Conection<BR> SQL, conn<BR>&#039Inserting the value got in the querry into this variable, <BR> &#039as I have only one value I can set it As the 0 part of the array .<BR> maxID = rs(0)<BR><BR>&#039Closing the first Record Set <BR> rs.Close<BR> set rs = nothing<BR> <BR>&#039Seting Variables (again)<BR> &#039 The rnums(x) is the size of the array , the number of records I want to display In this case <BR> &#039the (3) means 4 as the array star&#039s with 0.<BR> Dim rnums(3),sql1,rs1,rcount,strRandomNumbers,chk<BR> <BR>&#039As we must start from 0 and go on we have to start the DO from -1 so we don&#039t skeap the 0. <BR> rcount = -1<BR> <BR>&#039Here we start the Do , (Do while the rcount is smaller then the rnums),<BR> &#039 the UBound is for<BR> Do While rcount &#060; UBound(rnums)<BR> <BR> &#039the (randomize ) is used so the random nubers change in each refreash <BR> randomize<BR> <BR> &#039the random function<BR> randVal = Int( Rnd * maxID ) + 1<BR> <BR> <BR>&#039Here we want to check if in the current slot in the array contain&#039s a random number<BR> &#039 that matches the random value ("randVal") that we just chose?<BR> &#039We Start the (FOR) with 0 As the first time the (Do above) will start will be From -1.<BR> For chk = 0 To rcount<BR> <BR> &#039Here is the actual check told explained above <BR> If rnums(chk) = randVal Then<BR><BR> &#039 yes! a match! So we have a duplicate that we want to ignore!<BR> &#039 1- we say we have a duplicate random number (** And it will not be saved in the array).<BR> duplicate = True <BR> &#039 2- And and no need to check further<BR> Exit For <BR><BR> End If<BR> <BR> Next<BR><BR>&#039As advised beforw(**) Only if duplicate false the value will be save in the array <BR> If duplicate = False Then<BR> &#039So lets go slut ahead in our array <BR> rcount = rcount + 1<BR><BR> &#039now put the random value we chose into THAT slot in the array!<BR> rnums(rcount) = randVal<BR> End If<BR> <BR>Loop<BR><BR>&#039 As here We should get as many numbers we have decided in the (rnums(X)) we have to put them<BR> &#039 in a string separated by comas so we are joining tha values of (rnums) in string by commas <BR> strRandomNumbers = Join( rnums, "," )<BR><BR>&#039Creating the Secound Record Set<BR> set rs1 = server.CreateObject ("ADODB.recordset")<BR> <BR>&#039The sql querry asking for every thing were the book_id has a match in the trRandomNumbers varible ,<BR> &#039 That is the random result&#039s<BR> SQL1 = "select * from books where book_id IN (" & strRandomNumbers & ")"<BR> <BR><BR>I have put some comments so you understand .<BR>Please help me .<BR>Regards Moti<BR><BR>

  2. #2
    MG Guest

    Default RE: MG please help

    I did a search on 4guys site for "random" and it returned this url<BR><BR><BR>Have fun.<BR>MG

Posting Permissions

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