-
December 12th, 2011, 09:35 PM
#1
Need some QUICK help.
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
thanks, all help is greatly appreciated
-
December 12th, 2011, 10:39 PM
#2
Re: Need some QUICK help.
Use [code][/code] tags when posting code. To hard to read it as a jumbled blob.
Always use [code][/code] tags when posting code.
-
December 12th, 2011, 10:59 PM
#3
Re: Need some QUICK help.
Code:
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
-
December 13th, 2011, 12:22 AM
#4
Re: Need some QUICK help.
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 <
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|