Im currently trying to make a deal or no deal with 26 unique amounts. Here ive added the loopings to try and make all the values unique, but when i debug the program, it seems to be stuck on the first loop but doesnt return any errors...

``````Dim Amount() As String 'declaring the amounts
Amount = Split("0, 1, 2, 3, 5, 10, 20, 50, 100, 200, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 10000, 15000, 20000, 30000, 50000, 75000, 100000, 200000")

Randomize() 'randomizing values
Dim x As Integer 'x randomised number
x = Int(Rnd() * 26)
Amount1 = Amount(x)
Do
Randomize(x = Int(Rnd() * 26))
Amount2 = Amount(x)
Loop While Amount2 = Amount1 'loops the randomizer to eliminate any repeats!
Do
x = Int(Rnd() * 26)
Amount3 = Amount(x)
Loop While Amount3 = Amount1 Or Amount2
Do
x = Int(Rnd() * 26)
Amount4 = Amount(x)
Loop While Amount4 = Amount1 Or Amount2 Or Amount3
Do
x = Int(Rnd() * 26)
Amount5 = Amount(x)
Loop While Amount5 = Amount1 Or Amount2 Or Amount3 Or Amount4
Do
x = Int(Rnd() * 26)
Amount6 = Amount(x)
Loop While Amount6 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5
x = Int(Rnd() * 26)
Do
Amount7 = Amount(x)
Loop While Amount7 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6
x = Int(Rnd() * 26)
Do
Amount8 = Amount(x)
Loop While Amount8 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7
x = Int(Rnd() * 26)
Do
Amount9 = Amount(x)
Loop While Amount9 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8
Do
x = Int(Rnd() * 26)
Amount10 = Amount(x)
Loop While Amount10 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9
Do
x = Int(Rnd() * 26)
Amount11 = Amount(x)
Loop While Amount11 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10
Do
x = Int(Rnd() * 26)
Amount12 = Amount(x)
Loop While Amount12 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11
Do
x = Int(Rnd() * 26)
Amount13 = Amount(x)
Loop While Amount13 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12
Do
x = Int(Rnd() * 26)
Amount14 = Amount(x)
Loop While Amount14 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12 Or Amount13
Do
x = Int(Rnd() * 26)
Amount15 = Amount(x)
Loop While Amount15 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12 Or Amount13 Or Amount14
Do
x = Int(Rnd() * 26)
Amount16 = Amount(x)
Loop While Amount16 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12 Or Amount13 Or Amount14 Or Amount15
Do
x = Int(Rnd() * 26)
Amount17 = Amount(x)
Loop While Amount17 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12 Or Amount13 Or Amount14 Or Amount15 Or Amount16
Do
x = Int(Rnd() * 26)
Amount18 = Amount(x)
Loop While Amount18 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12 Or Amount13 Or Amount14 Or Amount15 Or Amount16 Or Amount17
Do
x = Int(Rnd() * 26)
Amount19 = Amount(x)
Loop While Amount19 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12 Or Amount13 Or Amount14 Or Amount15 Or Amount16 Or Amount17 Or Amount18
Do
x = Int(Rnd() * 26)
Amount20 = Amount(x)
Loop While Amount20 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12 Or Amount13 Or Amount14 Or Amount15 Or Amount16 Or Amount17 Or Amount18 Or Amount19
Do
x = Int(Rnd() * 26)
Amount21 = Amount(x)
Loop While Amount21 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12 Or Amount13 Or Amount14 Or Amount15 Or Amount16 Or Amount17 Or Amount18 Or Amount19 Or Amount20
Do
x = Int(Rnd() * 26)
Amount22 = Amount(x)
Loop While Amount22 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12 Or Amount13 Or Amount14 Or Amount15 Or Amount16 Or Amount17 Or Amount18 Or Amount19 Or Amount20 Or Amount21
Do
x = Int(Rnd() * 26)
Amount23 = Amount(x)
Loop While Amount23 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12 Or Amount13 Or Amount14 Or Amount15 Or Amount16 Or Amount17 Or Amount18 Or Amount19 Or Amount20 Or Amount21 Or Amount22
Do
x = Int(Rnd() * 26)
Amount24 = Amount(x)
Loop While Amount24 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12 Or Amount13 Or Amount14 Or Amount15 Or Amount16 Or Amount17 Or Amount18 Or Amount19 Or Amount20 Or Amount21 Or Amount22 Or Amount23
Do
x = Int(Rnd() * 26)
Amount25 = Amount(x)
Loop While Amount25 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12 Or Amount13 Or Amount14 Or Amount15 Or Amount16 Or Amount17 Or Amount18 Or Amount19 Or Amount20 Or Amount21 Or Amount22 Or Amount23 Or Amount24
Do
x = Int(Rnd() * 26)
Amount26 = Amount(x)
Loop While Amount26 = Amount1 Or Amount2 Or Amount3 Or Amount4 Or Amount5 Or Amount6 Or Amount7 Or Amount8 Or Amount9 Or Amount10 Or Amount11 Or Amount12 Or Amount13 Or Amount14 Or Amount15 Or Amount16 Or Amount17 Or Amount18 Or Amount19 Or Amount20 Or Amount21 Or Amount22 Or Amount23 Or Amount24 Or Amount25``````

All 2 Replies

I dont know what exactly is this code for, but from your description I can tell you one thing: Amount2 IS NEVER EQUAL TO Amout1.
Thats why it never leaves the while loop.

Double check why those two variables are never equal.

A better way to generate non-repeating random sequences (for example, dealing cards from a deck) is to start with your array, Amount, then generate a random integer from 0 to last (where last is initially set to Ubound(Amount). When you generate your first random index (let's call it rind), adjust your Amount array as follows:

Amount(rind) = Amount(last)
last -= 1

That guarantees that you never get the same "amount" twice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.