In this article, we will create a program that can sort values into ascending or descending order in numbers in visual basic 6.0.
Now, let's start this tutorial!
1.Let's start this tutorial by following the following steps in Microsoft Visual Basic 6.0: Open
Microsoft Visual Basic 6.0, click
Choose Standard EXE, and click
Open.
2. Next, add 2 Buttons named
Command1 and labeled it as "
Asc" for ascending order and
Command2 and labeled it as "
Desc" for descending order. Insert 3 textboxes named
txtFN for first number,
txtSN for second number, and
txtTN for third number. Add also a ListBox named
List1 for displaying the result. You must design your interface like this:

3. For Button1 as Ascending Button, put this code below:
If txtFN has the lowest value, it will automatically add first in the List. It will decide also if what number is the next lower value between txtSN and txtTN.
If Val(txtFN.Text) <= Val(txtSN.Text) And Val(txtFN.Text) <= Val(txtTN.Text) Then
List1.AddItem txtFN
If Val(txtSN.Text) <= Val(txtTN.Text) Then
List1.AddItem txtSN.Text
List1.AddItem txtTN.Text
Else
List1.AddItem txtTN.Text
List1.AddItem txtSN.Text
End If
If txtSN has the lowest value, it will automatically add first in the List. It will decide also if what number is the next lower value between txtFN and txtTN.
ElseIf Val(txtSN.Text) <= Val(txtFN.Text) And Val(txtSN.Text) <= Val(txtTN.Text) Then
List1.AddItem txtSN
If Val(txtFN.Text) <= Val(txtTN.Text) Then
List1.AddItem txtFN.Text
List1.AddItem txtTN.Text
Else
List1.AddItem txtTN.Text
List1.AddItem txtFN.Text
End If
If txtTN has the lowest value, it will automatically add first in the List. It will decide also if what number is the next lower value between txtFN and txtSN.
Else
List1.AddItem txtTN
If Val(txtFN.Text) <= Val(txtSN.Text) Then
List1.AddItem txtFN.Text
List1.AddItem txtSN.Text
Else
List1.AddItem txtSN.Text
List1.AddItem txtFN.Text
End If
End If
4. For Button2 as Ascending Button, put this code below:
If txtFN has the greatest value, it will automatically add first in the List. It will decide also if what number is the next greater value between txtSN and txtTN.
If Val(txtFN.Text) >= Val(txtSN.Text) And Val(txtFN.Text) >= Val(txtTN.Text) Then
List1.AddItem txtFN
If Val(txtSN.Text) >= Val(txtTN.Text) Then
List1.AddItem txtSN.Text
List1.AddItem txtTN.Text
Else
List1.AddItem txtTN.Text
List1.AddItem txtSN.Text
End If
If txtSN has the greatest value, it will automatically add first in the List. It will decide also if what number is the next greater value between txtFN and txtTN.
ElseIf Val(txtSN.Text) >= Val(txtFN.Text) And Val(txtSN.Text) >= Val(txtTN.Text) Then
List1.AddItem txtSN
If Val(txtFN.Text) >= Val(txtTN.Text) Then
List1.AddItem txtFN.Text
List1.AddItem txtTN.Text
Else
List1.AddItem txtTN.Text
List1.AddItem txtFN.Text
End If
If txtTN has the greatest value, it will automatically add first in the List. It will decide also if what number is the next greater value between txtFN and txtSN.
Else
List1.AddItem txtTN
If Val(txtFN.Text) >= Val(txtSN.Text) Then
List1.AddItem txtFN.Text
List1.AddItem txtSN.Text
Else
List1.AddItem txtSN.Text
List1.AddItem txtFN.Text
End If
End If
5. Filter all the textboxes that it can only input numbers. Put this code below:
Private Sub txtFN_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Is < 32
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub txtSN_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Is < 32
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub txtTN_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Is < 32
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Output:

Download the source code and try it! :)
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below and hire me.
Best Regards,
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09488225971
Telephone:826-9296
E-mail:
[email protected]
Follow and add me in my Facebook Account: https://www.facebook.com/donzzsky
Visit my page on Facebook at: https://www.facebook.com/BermzISware