CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 1999
    Location
    North Wales, UK
    Posts
    1

    Sorting Integer arrays

    Hi,

    I'm taking a VB course at evening class and I have been given the task of generating lottery numbers.

    I need to sort the generated numbers into ascending order and display them at the bottom of the form. I have tried putting the values into a sorted listbox but this seems to add a second copy of the numbers.

    eg 1, 1, 23, 23 .....

    Can anyone help?

    I would be most grateful for any suggestions.


  2. #2
    Join Date
    Oct 1999
    Location
    CA
    Posts
    91

    Re: Sorting Integer arrays

    Not to do your homework or anything, but here you go: (I ought to tell your teacher of this!!!)


    for a = LBound(Lottery) to UBound(Lottery) 'Pass through the array once for every index.
    for b = LBound(Lottery) to UBound(Lottery) - 1
    If Lottery(b) > Lottery(b + 1) then 'Swap positions if number is greater
    temp = Lottery(b + 1)
    Lottery(b + 1) = Lottery(i)
    Lottery(b) = temp
    End If
    next
    next





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured