-
ok.. there is a loop..
It looks just dandy to me..
Whats the problem it??
ALL the code..
------------------------
Dim RndNum As Integer
Dim RecordRndNum(200) As Integer
Dim KeepRecordPlace As Integer
Dim Matches As Integer
Dim looper As Integer
Startover:
Randomize
RndNum = Int(Rnd * 84) + 1
RecordRndNum(KeepRecordPlace) = RndNum
KeepRecordPlace = KeepRecordPlace + 1
Do While looper <= 200
If RndNum = RecordRndNum(looper) Then
Matches = Matches + 1
End If
looper = looper + 1
Loop
If Matches > 1 Then
KeepRecordPlace = KeepRecordPlace - 1
Matches = 0
GoTo Startover
End If
Counter = RndNum
-------------------------------------------
-
Goto!!
Goto!!!
GOTO!!!!
ahhhhhhhhhhh!!!!!!!!
Run away!!!
-
-
What do I write to make it go back to the
Original place 'startover'????
-
You're a braver man than me, posting a goto liek that on this forum. Everyone seems to hate it with a passion.
Also i can't see where you set looper back to zero any where in the loop.
Code:
Dim RndNum As Integer
Dim RecordRndNum(200) As Integer
Dim KeepRecordPlace As Integer
Dim Matches As Integer
Dim looper As Integer
While Matches <> 1
Matches = 0
Randomize
RndNum = Int(Rnd * 84) + 1
RecordRndNum(KeepRecordPlace) = RndNum
KeepRecordPlace = KeepRecordPlace + 1
Do While looper <= 200
If RndNum = RecordRndNum(looper) Then
Matches = Matches + 1
End If
looper = looper + 1
Loop
If Matches > 1 Then
KeepRecordPlace = KeepRecordPlace - 1
End If
Wend
Counter = RndNum
-
why do you want it to startover again?
-
What are you trying to accomplish? Do you want a list of 84 unique random numbers? Something else?
-
i hate the randomize function,
when i was writing a little program, it was a pain in the arse :(
-
Goto
I just wonder why everybody seems to be so upset about Goto?
Ok, I knowe it makes the code hard tu understand, maintain and change, but sometimes it's just the easiest way to solve a problem.
Maybe only the brave dare to use Goto?
And btw, we all use On Error Goto, don't we?
What's the difference between that and other Goto:s?
If Angry, Do Not Goto Pentax.
-
because it is annoying, and it does not always do what you want :(
-
GOTO
Goto have been pretty useless since i programmed in gwbasic, but there can be handy in Exiting more than one loop
-
Try programming in Assembly and you'll quickly understand why Goto is looked down upon so much. One little change and your entire logic structure is blown to sh!†, plus it's confusing and completely un-necessary in VB! Everything that needs to be accomplished with Gotos can be re-written using stronger logic and better planning. You can use loops, switches, flag variables, functions/subs, and recursion (not the best alternative). Just sit and do some Flow Charts, Data Diagrams, and Desk Checks before you start plugging away at your code. You'll appreciate this advice so much more when you come back to this app in a few years and try to understand what the hell you were smoking when you wrote it, and trust me, you will come back to it eventually if it was worth your time to write.
-
Thanks Guys!!
You know what.. Acutally I fingured out
what was wrong.. I learned something
valuable. NEVER NAME YOUR FUNCTION RANDOMIZE.
lol.. I must have been out of my mind!!
Did you guys know that if you name your
function after a call in vb your program
goes nuts?
-
you can always use exit do :)
for exit for
if you are using those loops :)