Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- ' Numbers Sorting App by Ryan Arnold.
- 'Code written with help from John Morgan, Eric Gimbel, RaspBarrySenpai, and TheDuckLord.
- Private Sub txtInput_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtInput.KeyPress
- ' This prevents the user from entering anything other than an integer from 0 to 9 in the text box.
- If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
- e.Handled = True
- End If
- End Sub
- Private Sub btnEnterAmount_Click(sender As Object, e As EventArgs) Handles btnEnterAmount.Click
- ' Make the TextBox Read Only, change the Text properties of btnEnterAmount and lblInstructions, and declare variables needed for adding to the ListBox.
- txtInput.ReadOnly = True
- btnEnterAmount.Text = "Next Number"
- lblInstructions.Text = "Please click 'Next Number'."
- Dim intUserInput As Integer
- Dim intListCount As Integer
- Dim strUserInput2 As String
- Dim intParseVariable As Integer = 0
- ' Convert user input to an Integer, put it into a variable, then make the ListBox count equal to that amount.
- intUserInput = CInt(txtInput.Text)
- intListCount = lstNumberList.Items.Count
- ' Make sure the ListBox Count is equal to the abovementioned variable, then display a MessageBox.
- If intListCount = intUserInput Then
- MessageBox.Show("All set! Please click the Sort List button below.")
- btnEnterAmount.Enabled = False
- ' Otherwise, display an InputBox.
- Else
- strUserInput2 = InputBox("Please enter a number.", "Need Input", , ,)
- ' If the user tries to enter anything besides a number, display a MessageBox.
- If Integer.TryParse(strUserInput2, intParseVariable) Then
- lstNumberList.Items.Add(strUserInput2)
- Else
- MessageBox.Show("Please enter a numeric value.")
- Return
- End If
- End If
- ' Change the text of btnEnterAmount.
- btnEnterAmount.Text = "Next Number"
- End Sub
- Private Sub btnSort_Click(sender As Object, e As EventArgs) Handles btnSort.Click
- ' Declare a variable as a Boolean value
- Dim blnSorted As Boolean
- ' Do Until loop for sorting the numbers in the ListBox
- Do Until blnSorted
- blnSorted = True
- For intCount As Integer = 0 To lstNumberList.Items.Count - 2
- If (lstNumberList.Items(intCount) > lstNumberList.Items(intCount + 1)) Then
- Dim intTemp As Integer = lstNumberList.Items(intCount)
- lstNumberList.Items(intCount) = lstNumberList.Items(intCount + 1)
- lstNumberList.Items(intCount + 1) = intTemp
- blnSorted = False
- End If
- Next
- Loop
- End Sub
- Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
- ' Exit program when Exit button is clicked.
- Me.Close()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement