Trouble with arrays

Just starting out? Need help? Post your questions and find answers here.
Banaticus
User
User
Posts: 21
Joined: Fri Oct 24, 2003 5:49 am
Location: Redlands, CA
Contact:

Trouble with arrays

Post by Banaticus »

I'm having a bit of trouble with arrays.

Code: Select all

  Dim long_array.b(94)

  Repeat
    do_over=0
    For J = 0 To 93
      random_number=Random(93) + 1
      For K=0 To J
        If random_number = long_array(K)
          do_over=1
        EndIf
      Next K
      If do_over = 0
        random_number = long_array(J)
      EndIf
    Next J
  Until do_over=0
  
  OpenConsole()
 
  For K=0 To 93
    Print(Str(long_array(K)))
    Print(" ")
  Next K
  
  PrintN("")
  Print("Press 'Enter' to continue")
  pause$=Input()
  CloseConsole()
  End
I'm trying to list the numbers from 1 to 94 in random order. But everytime I run this code it displays, "0 0 0 0 0 0 . . ." What am I doing wrong?[/code]
--BX
Mr Tickle
User
User
Posts: 25
Joined: Mon Oct 13, 2003 10:33 pm
Location: England, Derbyshire.

Post by Mr Tickle »

You got line 12 the wrong way around is should be long_array(J) = random_number It works for me anyway ;)
Mr Tickle.
Athlon xp 2500+, Gigabyte KT400-FSB333, Gf3 Ti200, SB Live 5.1
Banaticus
User
User
Posts: 21
Joined: Fri Oct 24, 2003 5:49 am
Location: Redlands, CA
Contact:

How to order a singly incremented set of numbers randomly

Post by Banaticus »

Thanks! I made some changes (such as fixing the never-ending loop I created), and am posting the corrected version (including my insight into return statements nestled in If/Then loops as replacing GOTO statements) into the Tip's and Trick's forum as Replacement for GOTO command
--BX
Post Reply