|
-
Jun 15th, 2001, 10:59 AM
#1
Thread Starter
Hyperactive Member
A simple Do While Loop gone bad....
I am doing a loop and it's giving me a hard time. The result of this loop is the opposite of what I'm looking for. Here's the code:
Code:
<%
Dim Suit
Dim Value
Dim numValue
Dim intScore
intScore = 0
Sub GetCards
For x = 0 To 4
If Request.Form("Session" & x) <> "on" Then
randomize()
'Do Until (randomNumber <> Session0) AND (randomNumber <> Session1) AND (randomNumber <> Session2) AND (randomNumber <> Session3) AND (randomNumber <> Session4)
randomNumber=Int(51 * rnd())
'Loop
Session(x) = randomNumber
Loop
End If
%>
I had to comment the Do While Loop out because it makes every card the same one. I have tried a lot of different ways to make it work but it never will. The goal is to make it keep generating random numbers until it's chosen a card that has not been chosen already.
Please tell me where I'm going wrong with this. Thank you.
If you know a better way to get this to work please tell me.
If you think education is expensive, try ignorance.
-
Jun 15th, 2001, 01:26 PM
#2
Thread Starter
Hyperactive Member
I am using 5 sessions to keep track of the cards being used.
Session0
Session1
Session2
Session3
Session4
I tried different ways of working with it including an array but nothing would make it work right.
Thanks for your help.
If you think education is expensive, try ignorance.
-
Jun 15th, 2001, 01:38 PM
#3
Fanatic Member
Ok, a couple more questions then:
Where is randomNumber declared?
Is Session0 a variable that's declared elsewhere?
Is this the complete code that giving you the problem or is there more?
Chris
-
Jun 15th, 2001, 01:54 PM
#4
Thread Starter
Hyperactive Member
This is the complete code that is giving me the problems. I have a lot more code to make it look nice and format it correctly, but that part is working fine.
The goal I'm trying to reach is to make sure the different sessions do not equal each other (different cards). Even though they are not dimensioned anywhere that isn't where I'm having the problem. It is using each variable, but it's sometime using the same one as one of the other sessions.
If you think education is expensive, try ignorance.
-
Jun 15th, 2001, 02:13 PM
#5
Fanatic Member
To access a Session value you can't refer to it as Session0. You must have previous set the value:
Session("card1") = myNumber
Session(1) or Session("card1") would then refer to the value of the variable myNumber.
Also, the first time through the loop randomNumber isn't set to anything. You could do this:
randomNumber=Int(51 * rnd())
Do Until (randomNumber <> Session(1)) AND (randomNumber <> Session(2)) AND (randomNumber <> Session(3)) AND (randomNumber <> Session(4)) AND (randomNumber <> Session(5))
randomNumber=Int(51 * rnd())
Loop
-
Jun 15th, 2001, 02:18 PM
#6
Fanatic Member
One more thing, you are also missing the NEXT for your FOR loop and missing the END SUB.
Chris
-
Jun 15th, 2001, 02:21 PM
#7
Fanatic Member
I gotta run, if nobody else helps you can email me the code and I'll take a look at it.
Chris
-
Jun 15th, 2001, 02:39 PM
#8
Thread Starter
Hyperactive Member
Here is the zip file which has all of the files being used included (3 files). I am unable to get your email address (Psyrus) so I just uploaded it here.
Anyone wanting to help is more than welcome to view these files. Thanks for any help.
If you think education is expensive, try ignorance.
-
Jun 16th, 2001, 08:43 PM
#9
Fanatic Member
Hey,
Try changing your loop to this:
Do Until (randomNumber <> Session(0) _
AND (randomNumber <> Session(1)) _
AND (randomNumber <> Session(2)) _
AND (randomNumber <> Session(3)) _
AND (randomNumber <> Session(4))
randomNumber=Int(51 * rnd())
Loop
In your version you where comparing the randomNumber to Session0 which from what I have read in your code can only be a text value.
You have to check randomNumber against the Session value.
I ran it and it worked fine.
One other thing you will have to address, unless it doesn't matter, is the fact that you can still get the same card back after you have chosen to discard it.
You might consider adding an array to store the used numbers so they do not appear in any subsequent selections during that particular hand.
Chris
-
Jun 17th, 2001, 07:28 PM
#10
Thread Starter
Hyperactive Member
Pefect, thank you.
I will look into the array also, I'm sure I shouldn't have too many problems with that but I will post a reply if I do.
Thanks again for your help (everyone).
If you think education is expensive, try ignorance.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|