Things You'll Need:
- VB.net
- basic programming skills
-
Step 1
Open VB.net
-
Step 2
Create a new project
-
Step 3
Sort ButtonPlace a button on the form and change its text property to "Sort".
-
Step 4
ListboxPlace a listbox on the form. This is where we will display the sorted list.
-
Step 5
Click EventDouble click on the button control to bring up the code window and the button's click event.
-
Step 6
Global VariableDirectly above the click event subroutine type in:
Public aryNumberList(5) As Integer
This creates our public global variable array that we will use in our example to hold our numbers. -
Step 7
Loop variableIn the button's click event delcare a loop variable. This will be used to add our array items after they have been sorted the our listbox.
-
Step 8
Assign numbersAdd numbers in a random order to our array variable that we declared in step 6.
-
Step 9
SubroutineBefore we do anything else we must now create our sorting subroutine. Remember this is just an example so to keep it simple I am using a basic swapping sort. You can see the code in the picture.
-
Step 10
Call SubroutineGo back into the click event and call the subroutine passing the global array variable as a parameter.
-
Step 11
Display the sorted listDisplay the sorted list in the listbox.
-
Step 12
Press the "F5" key on your keyboard to run the application.
-
Step 13
Click the sort button.
-
Step 14
Final ResultsYour listbox should now display the numbers in their proper order.











