Need some QUICK help.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Need some QUICK help.

  1. #1
    Join Date
    Dec 2011
    Posts
    6

    Question 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

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,825

    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.

  3. #3
    Join Date
    Dec 2011
    Posts
    6

    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

  4. #4
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,825

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center