Public Class Form1
Dim Original(0 To 10) As Integer
Dim Sorted(0 To 10) As Integer
Dim FinalList As String
Dim n As Integer
Dim m As Integer
Dim pos As Integer
Dim f As Integer
Private Sub SortButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SortButton.Click
If TextBox1.Text = "" Then
MsgBox("Please enter a value in all the boxes")
Exit Sub
ElseIf TextBox2.Text = "" Then
MsgBox("Please enter a value in all the boxes")
Exit Sub
ElseIf TextBox3.Text = "" Then
MsgBox("Please enter a value in all the boxes")
Exit Sub
ElseIf TextBox4.Text = "" Then
MsgBox("Please enter a value in all the boxes")
Exit Sub
ElseIf TextBox5.Text = "" Then
MsgBox("Please enter a value in all the boxes")
Exit Sub
ElseIf TextBox6.Text = "" Then
MsgBox("Please enter a value in all the boxes")
Exit Sub
ElseIf TextBox7.Text = "" Then
MsgBox("Please enter a value in all the boxes")
Exit Sub
ElseIf TextBox8.Text = "" Then
MsgBox("Please enter a value in all the boxes")
Exit Sub
ElseIf TextBox9.Text = "" Then
MsgBox("Please enter a value in all the boxes")
Exit Sub
ElseIf TextBox10.Text = "" Then
MsgBox("Please enter a value in all the boxes")
Exit Sub
End If
Original(1) = TextBox1.Text
Original(2) = TextBox2.Text
Original(3) = TextBox3.Text
Original(4) = TextBox4.Text
Original(5) = TextBox5.Text
Original(6) = TextBox6.Text
Original(7) = TextBox7.Text
Original(8) = TextBox8.Text
Original(9) = TextBox9.Text
Original(10) = TextBox10.Text
For n = 1 To 10
pos = n
For m = 1 To (n - 1)
If Sorted(m) > Original(n) Then
pos = m
For f = (n - 1) To m Step -1
Sorted(f + 1) = Sorted(f)
Next f
m = n
End If
Next m
Sorted(pos) = Original(n)
Next n
FinalList = ""
For n = 1 To 10
FinalList = FinalList & Str(Sorted(n))
If n < 10 Then
FinalList = FinalList & ", "
Else
FinalList = FinalList & "."
End If
Next n
SortedValuesLabel.Text = FinalList
End Sub
End Class
insertion sort?
Edit the code and surround it with [ source lang="vb" ] [ /source ] only without all the spaces.
Dim num(100) As Integern = 100For pass = 2 To n temp = num(pass) slide = pass While temp < num(slide - 1) num(slide) = num(slide - 1) slide = slide - 1 Wend num(slide) = tempNext passFor i = 1 To nList1.AddItem num(i)Next i
Try looking at that, it should make more sense.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement