Results 1 to 2 of 2

Thread: random number generator problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Posts
    65

    random number generator problem

    I am doing a program where I build a two-dimensional array and then populate it with elements by using a random number generator. It is supposed to have random numbers between 1 and 100. I keep getting a compiler error saying that I have the wrong number of dimensions. Is this something about the way I set up the array or is it the code for the random number generator? This is what I have so far:

    Dim x(1 To 5, 1 To 10) As Single
    Dim n As Long, i As Long
    For i = 1 To 5
    x(i) = Int(Rnd * 100) + 1
    Next i
    For i = 1 To 5
    Print i, x(i)
    Next i
    For n = 1 To 10
    x(n) = Int(Rnd * 100) + 1
    Next n
    For n = 1 To 10
    Print n, x(n)
    Next n

  2. #2
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    you are using this line in your code

    x(i) = Int(Rnd * 100) + 1


    it's a 2-dimensional array. You're trying to use it as a 1-dimensional array.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width