so this code works for making my array display in ascending order but i cant figure out how to make it work in descending order help!
Private Sub btnAscendingOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAscendingOrder.Click
Dim SwapFlag As Boolean
Dim UpperSub As Integer
Dim Temp As Integer
UpperSub = 4
SwapFlag = True
While SwapFlag = True And UpperSub >= 1
J = 0
SwapFlag = False
While J <= UpperSub - 1
If Array(J) > Array(J + 1) Then
Temp = Array(J)
Array(J) = Array(J + 1)
Array(J + 1) = Temp
SwapFlag = True
End If
J = J + 1
End While
UpperSub = UpperSub - 1
End While
txtDisplayNumbers.Clear()
txtDisplayNumbers.Focus()
For J As Integer = 0 To Array.Count - 1
txtDisplayNumbers.Text &= Array(J).ToString & Environment.NewLine
Next
End Sub
Private Sub btnAscendingOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAscendingOrder.Click
Dim SwapFlag As Boolean
Dim UpperSub As Integer
Dim Temp As Integer
UpperSub = 4
SwapFlag = True
While SwapFlag = True And UpperSub >= 1
J = 0
SwapFlag = False
While J <= UpperSub - 1
If Array(J) > Array(J + 1) Then
Temp = Array(J)
Array(J) = Array(J + 1)
Array(J + 1) = Temp
SwapFlag = True
End If
J = J + 1
End While
UpperSub = UpperSub - 1
End While
txtDisplayNumbers.Clear()
txtDisplayNumbers.Focus()
For J As Integer = 0 To Array.Count - 1
txtDisplayNumbers.Text &= Array(J).ToString & Environment.NewLine
Next
End Sub
Better but still no formatting, you should always indent code properly with in If blocks For, While, Do Loops and other such statements. Makes it much easier to read and makes it more likely that someone will try to help.
As to your problem you simply need to reverse your process. In one case you would want the items arranged > and in the other <
Bookmarks