Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Does anyone out there know the code to put ascending numerical order into shapes for a lottery predictor i am building in vb6. many thanks in advance. bill underwood

How do we get from shapes to number?
Otherwise if each shape has a value, then store the values in an array and sort then.

i think he is wondering how to create graphics.
since you are wanting to use shapes, i can assume that your application is not using graphics (win32/mfc/or directx) so why not just put them into labels with a background color and border?
' note, tile is a label with a background color
' sized int a square and font size increased
' with a BorderStyle of SINGLE and
' FLAT Appearance
private sub GenerateTiles()
Dim MAX_TILE as integer
MAX_TILE = 30
Dim tileindex as integer
' first unload all
for tileindex = 1 to tile.count-1
uload tile(tileindex)
next tileindex
' next hide tile(0)
tile(0).visible = false
' finally load the ones you want
for tileindex = 1 to MAX_TILE
load tile(tileindex)
tile(tileindex).captioin = tileindex
next tileindex
End Sub
private sub PickTiles()
Dim MAX_PICK as integer
DIM LEFT_START_POSITION as long
dim TOP_POSITION as long
TOP_POSITION = 100
LEFT_START_POSITION = 1560
MAX_PICK = 6
Dim tileindex as integer
Dim leftpos as long
dim randomnum as integer
for tileindex = 0 to MAX_PICK-1
randomnum = rnd(tile.count)
leftpos = START_LEFT_POSITION + (100 * tileindex)
Tile(randomnum).Left = leftpos
Tile(randomnum).top = TOP_POSITION
Tile(randomnum).visible = true
next tileindex
End SubHope this helps,
ChiThey mostly come at night...mostly

Thanks for the replies, What i need is the code to sort 6 randomly selected numbers into ascending numerical order the other code i have managed to work out.If some one knows the code then the rest will be easy. Many thanks in advance. regards bill underwood

If you only have 6 items and they are being generated one at a time. I would use a modified bubble sort. Place the generated item at the end of the list and sort up to the beginning. The list is always sorted except when you add a new item.
I use other dialects of BASIC rather than VB, so for sample code I would suggesting searching - VB6 array sort. Apparently VB.net may have the function built-in.
Here is my example of sorting a 2 dim array after a random number selection. Part of my Powerbasic code. 14 lines.
PRINT "Sorting List"
FOR pass = 1 TO INT(SelectNeeded / 2)REM Up Sort
FOR x = pass TO SelectNeeded - pass
IF Choice(x, 1) > Choice((x + 1), 1) THEN
SWAP Choice(x, 1), Choice((x + 1), 1)
SWAP Choice(x, 2), Choice((x + 1), 2)
END IF
NEXT x
REM Down Sort
FOR y = SelectNeeded - pass TO 1 + pass STEP -1
IF Choice(y, 1) < Choice((y - 1), 1) THEN
SWAP Choice(y, 1), Choice((y - 1), 1)
SWAP Choice(y, 2), Choice((y - 1), 2)
END IF
NEXT yNEXT pass

here is vb6 code to perform an intelligent bubble sort: (most bubble sorts state the number of loops to take through the items as n-1...this one can take as few as 1 and as many as n-1...so potentially faster. You are fee to use this code any way you wish)
Private Function SmartBubbleSort(ByRef Numbers() As Integer) As Long
Dim Upper As Long ' this will hold upper bound of array
Dim T As Long ' this will be used in the for loop
Dim Swapped As Boolean ' this is the smart part
Dim TempNumber As Integer ' this will hold the number to be swapped
Dim TotalPasses As Long ' this is for reporting purposes only
Swapped = True ' initialise it
Upper = UBound(Numbers) - 1 ' find upper bounds of the array
TotalPasses = 0
Do While Swapped
TotalPasses = TotalPasses + 1
Swapped = False ' this is our exit condition
For T = 1 To Upper
If Numbers(T - 1) > Numbers(T) Then
' swap the numbers
TempNumber = Numbers(T)
Numbers(T) = Numbers(T - 1)
Numbers(T - 1) = TempNumber
Swapped = True
End If
Next T
Loop
SmartBubbleSort = TotalPasses
End Function
Here is a complete project using this code:
' note there are two labels on the form
' both called label1 (it's a collection)
' and a button called command1Private Sub Command1_Click()
Call SortEm
End SubPrivate Sub SortEm()
Dim Numbers(6) As Integer
For T = 0 To 5
Numbers(T) = Rnd(1) * 100
Next T
Call PrintNumbers(Label1(0), Numbers)
Form1.Caption = "Total Passes: " & SmartBubbleSort(Numbers)
Call PrintNumbers(Label1(1), Numbers)
End Sub
Private Sub PrintNumbers(ByRef objLabel As Label, ByRef Numbers() As Integer)
Dim T As Long
Dim Upper As Long
Upper = UBound(Numbers) - 1 ' find upper bounds of the array
objLabel.Caption = ""
For T = 0 To Upper
objLabel.Caption = objLabel.Caption & Numbers(T) & vbCrLf
Next T
End Sub
Private Function SmartBubbleSort(ByRef Numbers() As Integer) As Long
Dim Upper As Long ' this will hold upper bound of array
Dim T As Long ' this will be used in the for loop
Dim Swapped As Boolean ' this is the smart part
Dim TempNumber As Integer ' this will hold the number to be swapped
Dim TotalPasses As Long ' this is for reporting purposes only
Swapped = True ' initialise it
Upper = UBound(Numbers) - 1 ' find upper bounds of the array
TotalPasses = 0
Do While Swapped
TotalPasses = TotalPasses + 1
Swapped = False ' this is our exit condition
For T = 1 To Upper
If Numbers(T - 1) > Numbers(T) Then
' swap the numbers
TempNumber = Numbers(T)
Numbers(T) = Numbers(T - 1)
Numbers(T - 1) = TempNumber
Swapped = True
End If
Next T
Loop
SmartBubbleSort = TotalPasses
End Function
Hope this helps
ChiThey mostly come at night...mostly

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

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