08-03-2011, 11:54 PM
(This post was last modified: 08-03-2011, 11:55 PM by AceInfinity.)
You have a lot of unnecessary code in this one. Also you wouldn't even need the combo box lol, it's just there to make it look like those random results are based off your choice from the combobox lol.
Here's the cleaner code though:
You did not need this: (Highlighted in red)
Why? Because userselected is just defined as an integer. There is no changing value. It will always be "0"
Here's the cleaner code though:
Code:
Public Class Form1
Dim userselected As Integer
Dim gameresult As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.SelectedIndex = 0
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Random As New Random
'Random value with max 3
Dim computerchoice = Random.Next(3)
'Finding the game result
Select Case computerchoice
Case 0
If computerchoice = userselected Then gameresult = 0
Case 1
If userselected = 0 Then gameresult = 1
Case 2
If userselected = 0 Then gameresult = 2
End Select
'Outputting proof of the game result to the label
Select Case gameresult
Case 0
Label1.Text = "It Was A Draw"
Case 1
Label1.Text = "Bad Luck! Computer Wins"
Case 2
Label1.Text = "You Win!"
End Select
End Sub
End Class
You did not need this: (Highlighted in red)
Quote:Public Class Form1
Dim userselected As Integer
Dim gameresult As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.SelectedIndex = 0
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Random As New Random
Dim computerchoice = Random.Next(3)
If computerchoice = userselected Then gameresult = 0
Select Case computerchoice
Case 0
If userselected = 1 Then gameresult = 2
If userselected = 2 Then gameresult = 1
Case 1
If userselected = 0 Then gameresult = 1
If userselected = 2 Then gameresult = 2
Case 2
If userselected = 0 Then gameresult = 2
If userselected = 1 Then gameresult = 1
End Select
Select Case gameresult
Case 0
Label1.Text = "It Was A Draw"
Case 1
Label1.Text = "Bad Luck! Computer Wins"
Case 2
Label1.Text = "You Win!"
End Select
End Sub
End Class
Why? Because userselected is just defined as an integer. There is no changing value. It will always be "0"