0
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...

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by BitBlt
1

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!

Edited by BitBlt: n/a

Votes + Comments
agree
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.