Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. Public Class Form1
  2. ' Numbers Sorting App by Ryan Arnold.
  3. 'Code written with help from John Morgan, Eric Gimbel, RaspBarrySenpai, and TheDuckLord.
  4. Private Sub txtInput_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtInput.KeyPress
  5. ' This prevents the user from entering anything other than an integer from 0 to 9 in the text box.
  6. If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
  7. e.Handled = True
  8. End If
  9. End Sub
  10.  
  11. Private Sub btnEnterAmount_Click(sender As Object, e As EventArgs) Handles btnEnterAmount.Click
  12. ' Make the TextBox Read Only, change the Text properties of btnEnterAmount and lblInstructions, and declare variables needed for adding to the ListBox.
  13. txtInput.ReadOnly = True
  14. btnEnterAmount.Text = "Next Number"
  15. lblInstructions.Text = "Please click 'Next Number'."
  16. Dim intUserInput As Integer
  17. Dim intListCount As Integer
  18. Dim strUserInput2 As String
  19. Dim intParseVariable As Integer = 0
  20.  
  21. ' Convert user input to an Integer, put it into a variable, then make the ListBox count equal to that amount.
  22. intUserInput = CInt(txtInput.Text)
  23. intListCount = lstNumberList.Items.Count
  24.  
  25. ' Make sure the ListBox Count is equal to the abovementioned variable, then display a MessageBox.
  26. If intListCount = intUserInput Then
  27. MessageBox.Show("All set! Please click the Sort List button below.")
  28. btnEnterAmount.Enabled = False
  29. ' Otherwise, display an InputBox.
  30. Else
  31. strUserInput2 = InputBox("Please enter a number.", "Need Input", , ,)
  32. ' If the user tries to enter anything besides a number, display a MessageBox.
  33. If Integer.TryParse(strUserInput2, intParseVariable) Then
  34. lstNumberList.Items.Add(strUserInput2)
  35. Else
  36. MessageBox.Show("Please enter a numeric value.")
  37. Return
  38. End If
  39. End If
  40. ' Change the text of btnEnterAmount.
  41. btnEnterAmount.Text = "Next Number"
  42. End Sub
  43.  
  44. Private Sub btnSort_Click(sender As Object, e As EventArgs) Handles btnSort.Click
  45. ' Declare a variable as a Boolean value
  46. Dim blnSorted As Boolean
  47. ' Do Until loop for sorting the numbers in the ListBox
  48. Do Until blnSorted
  49. blnSorted = True
  50. For intCount As Integer = 0 To lstNumberList.Items.Count - 2
  51. If (lstNumberList.Items(intCount) > lstNumberList.Items(intCount + 1)) Then
  52. Dim intTemp As Integer = lstNumberList.Items(intCount)
  53. lstNumberList.Items(intCount) = lstNumberList.Items(intCount + 1)
  54. lstNumberList.Items(intCount + 1) = intTemp
  55. blnSorted = False
  56. End If
  57. Next
  58. Loop
  59. End Sub
  60.  
  61. Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
  62. ' Exit program when Exit button is clicked.
  63. Me.Close()
  64. End Sub
  65. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement