AllExperts > Experts 
Search      

VB.NET

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB.NET Answers
Question Library

Ask a question about VB.NET
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Syed Rizwan Muhammad Rizvi
Expertise
I can answers questions regarding web based and desktop based programming in VB.Net. Which can include SOAP, XML, Custom Controls, COM Interoperability etc.

Experience
Have been working in this specific area for last 2 years previously I was a VB 6 Developer with experties in other languages as well. Total 10 years of programming experience.

 
   

You are here:  Experts > Computing/Technology > Basic > VB.NET > Help with VB sorting

Topic: VB.NET



Expert: Syed Rizwan Muhammad Rizvi
Date: 7/2/2007
Subject: Help with VB sorting

Question
Hi there,  I am contructing a VB lottery program for Uni but am stuck on the last bit as i am very new to programing.  I have to make the system generate 7 random numbers from 1-49 and then arrange in ascending order.  I have got as far as to generating the unique 7 numbers 1-49 but cant arrange.  I have used one form, one button with the code, 7 labels in one groupbox.  Could you help me with making some kind of code to arrange labels or array in the groupbox?  I am using vb exp 2005.  Thank a million.  My code so far is bellow.  
Best Regards

   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(2)
       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)

       Next  

Answer
I suggest that rather than using Simple Arrays you use ArrayList so e.g. your declaration would become

dim intArray as new ArrayList(49)

and once you have assigned values to it you can simply use
intArray.Sort() to sort the whole array.

Regards,
Rizwan

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.