If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

You have two For... statements, but only one Next statement. You need a Next for each For.

Also, your Next statement is within an If...Then block that's within one of the For... loops, which won't work. Your code should look like this:

Code:

For MAX = 1 To 200
For MIN = 1 To 200
If cmdRandom.CausesValidation Then
' Do something
End If
Next MIN
Next MAX

Finally, the code in the inner loop will execute 40,000 times (200 * 200). It's unlikely that cmdRandom's CausesValidation property will change inside the loop, so you should probably test it once before entering the loops, rather than testing it 40,000 times.

Code:

If cmdRandom.CausesValidation Then
For MAX = 1 To 200
For MIN = 1 To 200
' Do something
Next MIN
Next MAX
End If

You have two For... statements, but only one Next statement. You need a Next for each For.

Also, your Next statement is within an If...Then block that's within one of the For... loops, which won't work. Your code should look like this:

Code:

For MAX = 1 To 200
For MIN = 1 To 200
If cmdRandom.CausesValidation Then
' Do something
End If
Next MIN
Next MAX

Finally, the code in the inner loop will execute 40,000 times (200 * 200). It's unlikely that cmdRandom's CausesValidation property will change inside the loop, so you should probably test it once before entering the loops, rather than testing it 40,000 times.

Code:

If cmdRandom.CausesValidation Then
For MAX = 1 To 200
For MIN = 1 To 200
' Do something
Next MIN
Next MAX
End If

That Worked Perfect thanks...But, How Do I make it choose any number out of the 1 to 200?

your code is really confusing, because before you set X and Y from two text boxes, then just after that you assign MIN and MAX to them. What's the point of using the text boxes if their values are not used?
To generate a random number between 1 and 200:

Did you at least try to debug your code? Put a break at the first for statement, run and go step by step using F8....
The first two nested for statements loop a lot of times (set by two random numbers) but in the end in txtdone what you see is the results of only the last loop.
What about the completely useless two nested loops inside the last if statement, that don't do anything at all?
Sorry, but I am still trying to find out what you want to accomplish...
If you want to click in a button and multiply two random numbers, this is my code (not tested):