Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

wierd vb error

Name: Anonymous 2011-11-07 19:03

Im trying to make a piece of code that generates a 4 digit random number, then checks if any of the digits are equal, and check if the first number = 0 and if any of that is true, it genereates a new number. most of the time it works but sometimes it doesnt output anything and it gives me "A first chance exception of type 'System.IndexOutOfRangeException' occurred in WindowsApplication1.exe" its probably something really simple here is what i have so far

        Randomize()
        Do Until (oknumber = True)
            number = CStr(Int((9999 * Rnd())) + 1)
            number.Split()

            If number(0) = "0" Or number(0) = number(1) Or number(0) = number(2) Or number(0) = number(3) Or number(1) = number(2) Or number(1) = number(3) Or number(2) = number(3) Then
                oknumber = False
            Else
                oknumber = True
            End If
        Loop
        txtdigits.Text = number

Name: Anonymous 2011-11-07 19:10

Your Rnd() stuff seems wrong. I think you must write
number = CStr(Int((9999 - 1111 + 1) * Rnd) + 1111)
(source: http://www.vbexplorer.com/VBExplorer/random/random_numbers_1.asp). As a side note, VB is a bad languge.

Don't change these.
Name: Email:
Entire Thread Thread List