Results 1 to 7 of 7

Thread: Randomizer error

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    41

    Randomizer error

    I have tried two way to create a random number thing.

    here is the two way i used.

    Dim chooseNo As New Random()
    RanCol = chooseNo.Next(0, 6)


    Dim RanTurns As Integer
    Randomize()

    RanTurns = CInt(Int((100 * Rnd()) + 1))

    NOW both of them work fine ^^ , well that what i thought after so many goes i get a stack error

    do i use a try block to ingore the error or do i have to do something else to clear the stack in the randomize()

  2. #2
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    CInt(Int((100 * Rnd()) + 1))

    I see that you got that from the documentation for Randomize(), but the person who wrote it initially may have missed their morning coffee - Int() returns the integer portion of a number, so putting the results through CInt isn't terribly useful

    That doesn't have anything to do with your stack bug though. I am not able to reproduce your problem, I put your code in a loop like this:

    Code:
            Dim iCount As Integer
            Dim chooseNo As New Random()
            Dim RanCol As Integer
            For iCount = 1 To 5000
                RanCol = chooseNo.Next(0, 6)
                Dim RanTurns As Integer
                Randomize()
    
                RanTurns = CInt(Int((100 * Rnd()) + 1))
            Next
    and I don't get your bug even after running it many times (it's on a button). How many times are you talking about?

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    41
    Well here what my method do( umm kind of what it supose to do)
    i left out some steps to keep it simple

    private rancol(byval two Diamansion array)


    'do a random number on the col


    'do while if the col is not full

    else

    call rancol(two DiamannSion array)


    i know there is a way using double for loops but that is not the type of function i'm after cos i did left out some steps. I understand how i'm getting the errors but just don't know how to fix it. (The error is created if let say array(5,6) in size and if 6 coloumn is full then it will make the random() method alots harder to find the last Coloumn, that why you would get a stack error.)

    So do any of u know how to fix this problem with code ??

  4. #4
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Post all of your code, I don't have an idea of what you're trying to do from the bits and pieces you put up.

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    41
    here the code

    Private Sub ComputerT(ByVal pics(,) As PictureBox, ByVal image As Image)
    Dim chooseNo As New Random()
    Dim RanCol As Integer
    Dim MinRow As Integer
    Dim MaxRow As Integer

    MaxRow = 5
    MinRow = 0

    'create a Random positions
    RanCol = chooseNo.Next(0, 6)

    If PlayerTurn = False Then
    'Check where to put the picture in the array
    While ((Not pics(MaxRow, RanCol).Image Is EmptyPic And MaxRow > MinRow))
    MaxRow = MaxRow - 1
    End While

    'If the col is full call computer again to get a new random col
    If (MaxRow = MinRow) And (Not pics(MaxRow, RanCol).Image Is EmptyPic) Then


    ''HERE IS WHERE THE STACK ERROR SHOULD BE IF THIS BEEN CALL TOO MANY TIME WITH OUT GETTING THE LAST COLOUMN IN ARRAY
    ComputerT(pics, ComputerPic)

    Else

    PlayerTurn = True
    'Col,row is empty, put the computer picture into the array
    pics(MaxRow, RanCol).Image = ComputerPic

    'Check to see if there is a win or it a drawn
    CheckgameStatus(MaxRow, RanCol, pics, ComputerPic)


    End If
    Else


    End If
    End Sub

  6. #6
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    *cough* without the code around that one function I can't figure out how you are calling it, nor what it's supposed to be doing. Please give the code for the whole form (if it is large then zip it up and give as attachment).

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    41
    Don't worried about it
    i already know away to fix it



    I'm soz that i can't post more code cos it is a project that i'm doing ^^


    with the use of array you can store the value 0 to 6 etc...

    if one the the col is full then u can del the value from the array

    and then random() from 0 to y

    where y the array length
    the all i need is to read the array at the ran number and i get my same result with out getting a stuck error
    not sure if there a better of doing it thougth >.<

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