How to Reverse Numbers on Visual Basic

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Reverse Numbers on Visual Basic
Sort integers in descending order in VB. (John Foxx/Stockbyte/Getty Images)

In computer programming, being able to reverse numbers in an integer array can save you time by not having to write extra code. In Visual Basic you can use the "Array.Reverse" method to reverse the order of the elements in a one-dimensional array. Using this method may be needed when you need to display results in ascending and descending order. You can use this method instead of writing loops to reverse integers.

Skill level:
Moderate

Other People Are Reading

Instructions

  1. 1

    Launch Microsoft Visual Basic Express, then click "New Project..." on the left pane of your screen and select "Console Application." Click "OK" to create a new console project.

  2. 2

    Type the following to create the integer array that will hold numbers 1 to 9:

    Dim numArray() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9}

        numArray.Reverse(numArray)
    
  3. 3

    Create the following "For...Loop" to display the numbers in reverse order through the console window:

        For xCntr = 0 To 8
    
            Console.Write(numArray(xCntr))
    
        Next
    
  4. 4

    Type the following to display a message box when the program is done:

        MsgBox("Array numbers reversed.")
    
  5. 5

    Press "F5" to execute the program and reverse the order of the array elements.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.