954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Buble Sort

public i As Integer
Dim num(18) As Integer
Private Sub cmdEntry_Click()
  
     For i = 0 To 18 Step 1
        num(i) = InputBox("Enter a number:", "Array", 0)
        
     Next i
    
         
        grd.TextMatrix(0, 0) = "Array"
    For i = 0 To 18 Step 1
        grd.TextMatrix(grd.Rows - 1, 0) = num(i)
        grd.Rows = grd.Rows + 1
    Next i
End Sub

 

Private Sub cmdSort_Click()

    Dim p As Integer, c As Integer, t As Integer
        
            For p = 0 To 18 Step 1
                For c = 0 To 18 - p
                    num (c) <= num(c + 1)
                    t = num(c)
                    num(c) = num(c + 1)
                    num(c + 1) = t
                Next c
            Next p
            
     grd.TextMatrix(0, 1) = "Sorted"
    
        For c = 0 To 18
            grd.TextMatrix(1, 1) = num(i)
        Next c
    
End Sub

 
           Private Sub cmdExit_Click()
    End
End Sub

Can someone correct me with my code about sorting numbers in flexgrid my cmdSort doesn't work...

churva_churva
Junior Poster
135 posts since Aug 2010
Reputation Points: 1
Solved Threads: 0
 

Line 28 should be for c = 0 to 18 - p - 1, otherwise you overrun your bounds. Line 29 should be an "if" statement. Line 29 should also be >= rather than <= unless you want a descending sort. Then line 39 should use grd.TextMatrix(c + 1, 1) = num(c).

Good luck!

BitBlt
Master Poster
711 posts since Feb 2011
Reputation Points: 367
Solved Threads: 109
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: