Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 11th, 2004, 04:11 PM
Authorized User
 
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Brettvan1
Default Help..What am I doing wrong...

I am trying to create random unique numbers in the range of 1-49 and in ascending order..Now this part I have got and it works perfectly, now the problem I have is every now and again(I'm talking maybe25-30 clicks of the button later) a duplicate number will appear and then it will run perfectly again.Can anyone tell me where I'm going wrong ?
Here is my code....


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim intarray(5) As Integer
        Dim i As Integer
        Dim j As Integer
        Dim a As Integer
        Dim b As Integer
        Dim repeated As Boolean
        Dim tempnum As Integer


        Randomize()
        For i = 0 To 5
            intarray(i) = ((Rnd() * 48) + 1)
        Next
        For i = 0 To 5
            If i > 0 Then
                For j = 0 To i - 1
                    If intarray(i) = intarray(j) Then
                        intarray(i) = ((Rnd() * 48) + 1)
                        repeated = False

                    End If
                Next j
            End If
        Next i




        For a = LBound(intarray) To (UBound(intarray) - 1)
            For b = (a + 1) To UBound(intarray)
                If intarray(a) > intarray(b) Then
                    tempnum = intarray(a)
                    intarray(a) = intarray(b)
                    intarray(b) = tempnum
                End If
            Next b
        Next a

        Label1.Text = intarray(0)
        Label2.Text = intarray(1)
        Label3.Text = intarray(2)
        Label4.Text = intarray(3)
        Label5.Text = intarray(4)
        Label6.Text = intarray(5)


 
Old October 15th, 2004, 01:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not sure what you expect! The 49th time you hit the button you'd be bound to have a duplicate value. If it's something else you're looking for, maybe some of the principles on below site can help you:

http://www.vbexplorer.com/VBExplorer..._numbers_1.asp
 
Old October 18th, 2004, 02:36 AM
Authorized User
 
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Brettvan1
Default

Why on earth after the 49th click would I get a duplicate? Sorry am I being really dim here or what ? Is there something in my code that says after click 49 a duplicate will appear ?






Similar Threads
Thread Thread Starter Forum Replies Last Post
What's wrong ??? FT BOOK: ASP.NET Website Programming Problem-Design-Solution 2 November 3rd, 2005 09:18 AM
Where did I go wrong??? ahc2inc VB.NET 2002/2003 Basics 3 September 28th, 2004 08:19 PM
what's wrong with this? gilgalbiblewheel Classic ASP Databases 2 August 17th, 2004 07:22 PM
What's wrong?Help! amu BOOK: Beginning ASP.NET 1.0 1 October 28th, 2003 08:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.