Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi Every one. Lottery prediction. Does any one know the code for VB6 to arrange 6 randomly generated numbers to.
1. Using an array to sort numbers into Ascending numerical order. Lowest to highest.
2.The code to put ascending numbers into labels which have already been designed.
3. To put colours into circles.Must be an array, i have used bubble sort with no luck. Many thanks for any advice. regards bill Underwood

Why didn't the bubble sort work? It is ideal for sorting an array of six numbers.
You need to explain the second two questions a bit more. At a guess I would say:
For a = 1 to 6
Label1(a).Caption = Array(a)
NextThat is assuming you are using and Control Array of six label to correspond to the six numbers.
Stuart

Dear Stuart, Thanks for the reply. The bubble sort may not have been the correct formula or i may have missed one or two digits out, it just kept on saying sytex error all the time. I thought the array would be slightly quicker although i ma unsure that it would. When the 6 random numbers are generated, the are put into the suares by the code Label1. caption = print, which works well, but they are not in a ascending numerical order.
If you know off the code to put them in ascending numerical order, ie 1-49 range that would be great. If you think bubble sort would be better can you send the code for that, as i am new to this programming world. Best personal regards bill Underwood.

If you were getting Syntax Error all it means is that that there is something wrong with what you typed - a simple typing error perhaps. Could be something as simple as a misplaced comma.
You can get a Bubble Sort Algorithm hear:
http://zone.ni.com/devzone/conceptd.nsf/webmain/60E39A753406EE7986256E5C000030C6
Stuart

Dear Stuart,
MAny thanks for the e-mail for National Instruments website.Unfortunatly i do not know which part i need to go into for the code, as there were so many parts that i do not want to do something wrong or copy code that is copyrighted, can you please advise, many thanks for all your help.best regards bill underwood.

This bit:
Public Sub BubbleSort(ByRef sortArray() As Integer)
Dim i As Integer
Dim j As Integer
Dim Temp As Integer
For i = LBound(sortArray) To UBound(sortArray)
For j = LBound(sortArray) To (UBound(sortArray) - i - 1)
If sortArray(j + 1) < sortArray(j) Then
Temp = sortArray(j) 'swap if the two items
sortArray(j) = sortArray(j + 1) 'are out of order
sortArray(j + 1) = Temp
End If
Next j
Next i
End SubI wouldn't worry about copyright in this case. The bubble sort is a old as computers themselves. If you don't use this code there are bound to be hundreds of other examples on the Internet. This was just the first one I came to.
Stuart

Dear Stuart, Many thanks, i will give it a try and see if it comes out ok and let you know in due course. Best personal regards bill underwood.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |