badsha

VB App

Nov 29th, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. Public Class Form1
  2.  
  3. Dim letterOne, letterTwo, letterThree, compLetterOne, compLetterTwo, compLetterThree, posCorrect, colCorrect As Integer
  4. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5. Randomize()
  6. compLetterOne = (3 * Rnd() + 1) : compLetterTwo = (3 * Rnd() + 1) : compLetterThree = (3 * Rnd() + 1)
  7. posCorrect = 0 & colCorrect = 0
  8. End Sub
  9. Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
  10. letterOne = getLetter(txtColor1.Text) 'Asc(txtColor1.Text.ToLower()) - 96 'convert first letter to integer
  11. letterTwo = getLetter(txtColor2.Text) 'Asc(txtColor2.Text.ToLower()) - 96 'convert second letter to integer
  12. letterThree = getLetter(txtColor3.Text) 'Asc(txtColor3.Text.ToLower()) - 96 'convert third letter to integer
  13.  
  14. 'Get number correct
  15. If letterOne = compLetterOne Then
  16. posCorrect += 1
  17. colCorrect += 1
  18. End If
  19. If letterTwo = compLetterTwo Then
  20. posCorrect += 1
  21. colCorrect += 1
  22. End If
  23. If letterThree = compLetterThree Then
  24. posCorrect += 1
  25. colCorrect += 1
  26. End If
  27. If letterTwo = compLetterOne Or letterThree = compLetterOne Then 'If first letter of computer is equal to second or third user number
  28. colCorrect += 1
  29. End If
  30. If letterOne = compLetterTwo Or letterThree = compLetterTwo Then 'If second letter of computer is equal to first or third user number
  31. colCorrect += 1
  32. End If
  33. If letterOne = compLetterThree Or letterTwo = compLetterThree Then 'If third letter of computer is equal to first or second user number
  34. colCorrect += 1
  35. End If
  36.  
  37. lblColorsCorrect.Text = "Colors Correct: " & colCorrect
  38. lblPosCorrect.Text = "Positions Correct: " & posCorrect
  39.  
  40. MsgBox(letterOne & "-" & letterTwo & "-" & letterThree & "-vs-" & compLetterOne & "-" & compLetterTwo & "-" & compLetterThree)
  41. End Sub
  42. Private Function getLetter(ByVal letter As String) As Integer
  43. Dim result As Integer
  44. Select Case letter
  45. Case "r" : result = 1
  46. Case "g" : result = 2
  47. Case "b" : result = 3
  48. Case "y" : result = 4
  49. End Select
  50. Return result
  51. End Function
  52. Private Sub userWon()
  53. MessageBox.Show("You win!")
  54. End Sub
  55.  
  56. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  57. txtColor1.Text = ""
  58. txtColor2.Text = ""
  59. txtColor3.Text = ""
  60. posCorrect = 0
  61. colCorrect = 0
  62. lblColorsCorrect.Text = "Colors Correct: 0"
  63. lblPosCorrect.Text = "Positions Correct: 0"
  64. End Sub
  65. End Class
Advertisement
Add Comment
Please, Sign In to add comment