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

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!

commented: agree +13
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.