Computing.Net > Forums > Programming > VB 6 Ascending numerical order code

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VB 6 Ascending numerical order code

Reply to Message Icon

Name: mobius1
Date: February 23, 2005 at 06:16:50 Pacific
OS: XP Office
CPU/Ram: Pentium 4
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: wizard-fred
Date: February 23, 2005 at 15:34:41 Pacific
Reply:

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.


0

Response Number 2
Name: Chi Happens
Date: February 24, 2005 at 04:58:34 Pacific
Reply:

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 Sub

Hope this helps,
Chi

They mostly come at night...mostly


0

Response Number 3
Name: mobius1
Date: March 2, 2005 at 04:37:43 Pacific
Reply:

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


0

Response Number 4
Name: wizard-fred
Date: March 2, 2005 at 09:42:29 Pacific
Reply:

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 y

NEXT pass


0

Response Number 5
Name: Chi Happens
Date: March 2, 2005 at 11:17:49 Pacific
Reply:

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 command1

Private Sub Command1_Click()
    Call SortEm
End Sub

Private 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
Chi

They mostly come at night...mostly


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VB 6 Ascending numerical order code

VB 6 decompiler www.computing.net/answers/programming/vb-6-decompiler/3040.html

VB 6 SendKeys www.computing.net/answers/programming/vb-6-sendkeys/19879.html

Ascending Array www.computing.net/answers/programming/ascending-array/12730.html