badsha

VB App w/ Lists

Dec 1st, 2012
80
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.  
  3. Dim letterOne, letterTwo, letterThree, compLetterOne, compLetterTwo, compLetterThree, posCorrect, colCorrect As Integer
  4. Dim compList, userList As List(Of Integer)
  5. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6. Randomize()
  7. compLetterOne = (3 * Rnd() + 1) : compLetterTwo = (3 * Rnd() + 1) : compLetterThree = (3 * Rnd() + 1)
  8. compList.Add(compLetterOne)
  9. compList.Add(compLetterTwo)
  10. compList.Add(compLetterThree)
  11. posCorrect = 0 & colCorrect = 0
  12. End Sub
  13. Private Function getLetter(ByVal letter As String) As Integer
  14. Dim result As Integer
  15. Select Case letter
  16. Case "r" : result = 1
  17. Case "g" : result = 2
  18. Case "b" : result = 3
  19. Case "y" : result = 4
  20. End Select
  21. Return result
  22. End Function
  23. Private Sub userWon()
  24. MessageBox.Show("You win!")
  25. End Sub
  26.  
  27. Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
  28. letterOne = getLetter(txtColor1.Text) 'Asc(txtColor1.Text.ToLower()) - 96 'convert first letter to integer
  29. letterTwo = getLetter(txtColor2.Text) 'Asc(txtColor2.Text.ToLower()) - 96 'convert second letter to integer
  30. letterThree = getLetter(txtColor3.Text) 'Asc(txtColor3.Text.ToLower()) - 96 'convert third letter to integer
  31.  
  32. userList.Add(letterOne)
  33. userList.Add(letterTwo)
  34. userList.Add(letterThree)
  35.  
  36. 'Get number correct
  37. If userList(0) = compList(0) Then
  38. posCorrect += 1
  39. colCorrect += 1
  40. End If
  41. If userList(1) = compList(1) Then
  42. posCorrect += 1
  43. colCorrect += 1
  44. End If
  45. If userList(2) = compList(2) Then
  46. posCorrect += 1
  47. colCorrect += 1
  48. End If
  49. If userList(1) = compList(0) Or userList(2) = compList(0) Then 'If first letter of computer is equal to second or third user number
  50. colCorrect += 1
  51. End If
  52. If userList(0) = compList(1) Or userList(2) = compList(1) Then 'If second letter of computer is equal to first or third user number
  53. colCorrect += 1
  54. End If
  55. If userList(0) = compList(2) Or userList(1) = compList(2) Then 'If third letter of computer is equal to first or second user number
  56. colCorrect += 1
  57. End If
  58.  
  59. lblColCorrect.Text = "Colors Correct: " & colCorrect
  60. lblPosCorrect.Text = "Positions Correct: " & posCorrect
  61.  
  62. MsgBox(letterOne & "-" & letterTwo & "-" & letterThree & "-vs-" & compLetterOne & "-" & compLetterTwo & "-" & compLetterThree)
  63. End Sub
  64.  
  65. Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
  66. txtColor1.Text = ""
  67. txtColor2.Text = ""
  68. txtColor3.Text = ""
  69. posCorrect = 0
  70. colCorrect = 0
  71. lblColCorrect.Text = "Colors Correct: 0"
  72. lblPosCorrect.Text = "Positions Correct: 0"
  73. End Sub
  74. End Class
Advertisement
Add Comment
Please, Sign In to add comment