Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 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 July 1st, 2007, 01:41 PM
Registered User
 
Join Date: Jul 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to 009221
Default Visual Basic Exp 2005 Sorting

Hi there,
I am a business student but have a small problem solving project to do. I have to contruct a lottery system that generates 7 random numbers 1-49. I have done this, but i also have to arrange them. I have been looking into buble sort ect but nothing helpd so far so I was hoping someone could kindly help. My code so far is bellow. I have used 7 labels, one button. The labels are in a groupbox as I was trying to arrange them in ascending orde but kept failingr. Thanks a lot for your time and help.


ivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim intarray(49) As Integer
        Dim intcount As Integer
        Dim intindex As Integer
        Dim intnumber
        Dim repeated As Boolean
        Dim obj As Object

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

        For intcount = 0 To 6
            Do
                repeated = False
                intnumber = Int((50 * Rnd()) + 1)

                For intindex = 0 To 6
                    If intnumber = intarray(intindex) Then
                        repeated = True
                    End If
                Next
            Loop Until repeated = False

            intarray(intcount) = intnumber

        Next
        intindex = -1
        For Each obj In GroupBox1.Controls
            intindex += 1
            obj.text = intarray(intindex)



 
Old July 2nd, 2007, 03:02 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
                                ByVal e As System.EventArgs _
                               ) Handles Button1.Click

    Dim intarray(49) As Integer
    Dim intcount As Integer
    Dim intindex As Integer
    Dim intnumber
    Dim repeated As Boolean
    Dim obj As Object

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

    For intcount = 0 To 6
        Do
            repeated = False
            intnumber = Int((50 * Rnd()) + 1)

            For intindex = 0 To 6
                If intnumber = intarray(intindex) _
                    Then repeated = True
            Next
        Loop Until repeated = False

         intarray(intcount) = intnumber

    Next

    Array.Sort(intarray)  ' Sort() has 17 overloads.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Date in Visual Basic 2005. sheelnathkekre Visual Basic 2005 Basics 1 August 15th, 2008 09:42 AM
Visual Basic 2005 Express CForce Visual Basic 2005 Basics 1 June 22nd, 2008 10:21 PM
visual basic 2005 nidhigupta001 Visual Basic 2005 Basics 1 February 12th, 2007 08:26 AM
visual basic 2005 nidhigupta001 Visual Basic 2005 Basics 2 February 11th, 2007 04:06 PM
FTP in Visual Studio 2005 Pro (Visual Basic) shoopes VB How-To 1 June 29th, 2006 02:08 PM





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