Click here to Skip to main content
15,924,196 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Generaladding autonumber to VB form - beginner question Pin
pawn_me7-May-04 14:42
pawn_me7-May-04 14:42 
GeneralRe: adding autonumber to VB form - beginner question Pin
Dave Kreskowiak7-May-04 17:46
mveDave Kreskowiak7-May-04 17:46 
GeneralRe: adding autonumber to VB form - beginner question Pin
pawn_me8-May-04 19:51
pawn_me8-May-04 19:51 
GeneralRe: adding autonumber to VB form - beginner question Pin
Dave Kreskowiak9-May-04 3:57
mveDave Kreskowiak9-May-04 3:57 
GeneralAccessing a database on a network drive Pin
ccotton3337-May-04 6:38
ccotton3337-May-04 6:38 
GeneralRe: Accessing a database on a network drive Pin
Dave Kreskowiak7-May-04 9:52
mveDave Kreskowiak7-May-04 9:52 
GeneralRandom Number Generator Pin
Britnt77-May-04 3:31
Britnt77-May-04 3:31 
GeneralRe: Random Number Generator Pin
Colin Angus Mackay7-May-04 3:59
Colin Angus Mackay7-May-04 3:59 
I've not put this in a compiler to check the syntax, so appologies in advance if I'm mistyped something. Here is a solution.

On each iteration the previous values are checked with the current random value and if they match a new random number is generated, this checking continues until there are no matches, at which point the value is put in the array and it moves on to the next element, like in your original code.

Dim Array(4) As Integer
Dim Counter As Integer
Dim CheckCounter As Integer
Dim Current As Integer
Dim IsOkay As Boolean

For Counter = 0 To 4
    IsOkay = True
    Do
        Current = CInt(Int((49 * Rnd()) + 1))
        For CheckCounter = 0 to Counter-1
        If Current = Array(CheckCounter)
            IsOkay = False
        End If
    Next
    Loop While IsOkay = False
    Array(Counter) = Current
Next
Array.Sort(Array)
lbl1.Text = Array(0)
lbl2.Text = Array(1)
lbl3.Text = Array(2)
lbl4.Text = Array(3)
lbl5.Text = Array(4)


Does this help?


"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar

Coming soon: The Second EuroCPian Event


GeneralRe: Random Number Generator Pin
Britnt77-May-04 4:51
Britnt77-May-04 4:51 
GeneralRe: Random Number Generator Pin
Colin Angus Mackay7-May-04 5:02
Colin Angus Mackay7-May-04 5:02 
GeneralRe: Random Number Generator Pin
Britnt77-May-04 5:29
Britnt77-May-04 5:29 
GeneralRe: Random Number Generator Pin
Colin Angus Mackay7-May-04 12:08
Colin Angus Mackay7-May-04 12:08 
GeneralRe: Random Number Generator Pin
Britnt712-May-04 2:29
Britnt712-May-04 2:29 
GeneralRe: Random Number Generator Pin
Nick Seng12-May-04 0:02
Nick Seng12-May-04 0:02 
GeneralRe: Random Number Generator Pin
Britnt712-May-04 2:38
Britnt712-May-04 2:38 
GeneralRe: Random Number Generator Pin
Britnt712-May-04 3:23
Britnt712-May-04 3:23 
GeneralVB.NET Forms and Painting Pin
opopov6-May-04 22:08
opopov6-May-04 22:08 
GeneralRe: VB.NET Forms and Painting Pin
Syed Abdul Khader7-May-04 0:45
Syed Abdul Khader7-May-04 0:45 
GeneralRe: VB.NET Forms and Painting Pin
opopov7-May-04 5:29
opopov7-May-04 5:29 
GeneralRe: VB.NET Forms and Painting Pin
Syed Abdul Khader10-May-04 21:11
Syed Abdul Khader10-May-04 21:11 
Generalslideshow app in vb6 Pin
Ashwin C6-May-04 9:07
Ashwin C6-May-04 9:07 
GeneralRe: slideshow app in vb6 Pin
Dave Kreskowiak7-May-04 10:06
mveDave Kreskowiak7-May-04 10:06 
GeneralCom based add-in office Pin
skoizumi291106-May-04 6:01
sussskoizumi291106-May-04 6:01 
GeneralFrom C# to VB.Net Pin
Clandestine6-May-04 5:32
Clandestine6-May-04 5:32 
GeneralRe: From C# to VB.Net Pin
Dave Kreskowiak6-May-04 6:18
mveDave Kreskowiak6-May-04 6:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.