michellemonty
New member
- Joined
- Dec 19, 2007
- Messages
- 1
- Programming Experience
- Beginner
Hello all. I am new to VB.net. I'm taking an online course and I'm having some difficulty with a project I'm doing. I'm creating a basketball game with two teams of five players each. I have randomly assigned each player an offensive stat, defensive stat and a shooting percentage. The program randomly picks one player from each team to match up. If the home team is offense and the player's offensive stat is greater than the other player's defensive stat, that player gets to shoot. I've coded the program and I'm not sure where I went wrong but no matter what the matchups are, it gives me "Offensive player does not get to shoot." Can someone take a look at my code and help me figure out where I'm going wrong? I apologize, my code is very basic and I'm sure there are much easier and shorter ways to do what I'm trying to accomplish but here's my code for this portion of my program:
VB.NET:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim homebeginningscore As Integer
Dim awaybeginningscore As Integer
homebeginningscore = 0
awaybeginningscore = 0
Dim homeplayeroffensestat(4) As Integer
Dim homeplayerdefensestat(4) As Integer
Dim homeplayershootingstat(4) As Integer
Dim awayplayeroffensestat(4) As Integer
Dim awayplayerdefensestat(4) As Integer
Dim awayplayershootingstat(4) As Integer
'convert numbers in textboxes to integers
Static isconverted As Boolean
isconverted = Integer.TryParse(Label37.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayeroffensestat(0))
isconverted = Integer.TryParse(Label38.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayerdefensestat(1))
isconverted = Integer.TryParse(Label39.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayershootingstat(2))
isconverted = Integer.TryParse(Label40.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayeroffensestat(3))
isconverted = Integer.TryParse(Label41.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayeroffensestat(4))
isconverted = Integer.TryParse(Label42.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayeroffensestat(0))
isconverted = Integer.TryParse(Label43.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayeroffensestat(1))
isconverted = Integer.TryParse(Label44.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayerdefensestat(2))
isconverted = Integer.TryParse(Label45.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayerdefensestat(3))
isconverted = Integer.TryParse(Label46.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayerdefensestat(4))
isconverted = Integer.TryParse(Label47.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayerdefensestat(0))
isconverted = Integer.TryParse(Label48.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayershootingstat(1))
isconverted = Integer.TryParse(Label49.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayershootingstat(2))
isconverted = Integer.TryParse(Label50.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayershootingstat(3))
isconverted = Integer.TryParse(Label51.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, homeplayershootingstat(4))
isconverted = Integer.TryParse(Label52.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayeroffensestat(0))
isconverted = Integer.TryParse(Label53.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayeroffensestat(1))
isconverted = Integer.TryParse(Label54.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayeroffensestat(2))
isconverted = Integer.TryParse(Label55.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayeroffensestat(3))
isconverted = Integer.TryParse(Label56.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayeroffensestat(4))
isconverted = Integer.TryParse(Label57.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayerdefensestat(0))
isconverted = Integer.TryParse(Label58.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayerdefensestat(1))
isconverted = Integer.TryParse(Label59.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayerdefensestat(2))
isconverted = Integer.TryParse(Label60.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayerdefensestat(3))
isconverted = Integer.TryParse(Label61.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayerdefensestat(4))
isconverted = Integer.TryParse(Label62.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayershootingstat(0))
isconverted = Integer.TryParse(Label63.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayershootingstat(1))
isconverted = Integer.TryParse(Label64.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayershootingstat(2))
isconverted = Integer.TryParse(Label65.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayershootingstat(3))
isconverted = Integer.TryParse(Label66.Text, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, awayplayershootingstat(4))
'randomly pick two players to compete
Static homeplayer As Integer
Static awayplayer As Integer
Static randomgenerator As New Random
homeplayer = randomgenerator.Next(0, 5)
awayplayer = randomgenerator.Next(0, 5)
If homeplayer = 0 Then Label67.Text = "Michelle Johnson" Else
If homeplayer = 1 Then Label67.Text = "Jennifer Smith" Else
If homeplayer = 2 Then Label67.Text = "Jessica Doe" Else
If homeplayer = 3 Then Label67.Text = "Rebecca Clark" Else
If homeplayer = 4 Then Label67.Text = "Allison James"
If awayplayer = 0 Then Label69.Text = "Monica Hargrove" Else
If awayplayer = 1 Then Label69.Text = "Micah Manning" Else
If awayplayer = 2 Then Label69.Text = "Amberly Thompson" Else
If awayplayer = 3 Then Label69.Text = "Linda Reynolds" Else
If awayplayer = 4 Then Label69.Text = "Brenda Cheatem"
'pick which team is offense and which is defense
Static offense As Integer
Static randomgenerator2 As New Random
offense = randomgenerator2.Next(0, 2)
If offense = 0 Then Label72.Text = "Offense"
If offense = 0 Then Label73.Text = "Defense"
If offense = 1 Then Label72.Text = "Defense"
If offense = 1 Then Label73.Text = "Offense"
'compare the offensive and defensive ranks to decide if offense gets to shoot
Dim homeplyr(4) As Boolean
Dim awayplyr(4) As Boolean
Dim hometeamisoffense As Boolean
Dim awayteamisoffense As Boolean
If Label72.Text = "Offense" Then hometeamisoffense = True
If Label72.Text = "Defense" Then awayteamisoffense = True
If hometeamisoffense = True Then
If Label67.Text = "Michelle Johnson" Then homeplyr(0) = True
If Label67.Text = "Jennifer Smith" Then homeplyr(1) = True
If Label67.Text = "Jessica Doe" Then homeplyr(2) = True
If Label67.Text = "Rebecca Clark" Then homeplyr(3) = True
If Label67.Text = "Allison James" Then homeplyr(4) = True
End If
If awayteamisoffense = True Then
If Label69.Text = "Monica Hargrove" Then awayplyr(0) = True
If Label69.Text = "Micah Manning" Then awayplyr(1) = True
If Label69.Text = "Amberly Thompson" Then awayplyr(2) = True
If Label69.Text = "Linda Reynolds" Then awayplyr(3) = True
If Label69.Text = "Brenda Cheatem" Then awayplyr(4) = True
End If
Dim matchup(24) As Boolean
If homeplyr(0) = True And awayplyr(0) = True Then matchup(0) = True
If homeplyr(0) = True And awayplyr(1) = True Then matchup(1) = True
If homeplyr(0) = True And awayplyr(2) = True Then matchup(2) = True
If homeplyr(0) = True And awayplyr(3) = True Then matchup(3) = True
If homeplyr(0) = True And awayplyr(4) = True Then matchup(4) = True
If homeplyr(1) = True And awayplyr(0) = True Then matchup(5) = True
If homeplyr(1) = True And awayplyr(1) = True Then matchup(6) = True
If homeplyr(1) = True And awayplyr(2) = True Then matchup(7) = True
If homeplyr(1) = True And awayplyr(3) = True Then matchup(8) = True
If homeplyr(1) = True And awayplyr(4) = True Then matchup(9) = True
If homeplyr(2) = True And awayplyr(0) = True Then matchup(10) = True
If homeplyr(2) = True And awayplyr(1) = True Then matchup(11) = True
If homeplyr(2) = True And awayplyr(2) = True Then matchup(12) = True
If homeplyr(2) = True And awayplyr(3) = True Then matchup(13) = True
If homeplyr(2) = True And awayplyr(4) = True Then matchup(14) = True
If homeplyr(3) = True And awayplyr(0) = True Then matchup(15) = True
If homeplyr(3) = True And awayplyr(1) = True Then matchup(16) = True
If homeplyr(3) = True And awayplyr(2) = True Then matchup(17) = True
If homeplyr(3) = True And awayplyr(3) = True Then matchup(18) = True
If homeplyr(3) = True And awayplyr(4) = True Then matchup(19) = True
If homeplyr(4) = True And awayplyr(0) = True Then matchup(20) = True
If homeplyr(4) = True And awayplyr(1) = True Then matchup(21) = True
If homeplyr(4) = True And awayplyr(2) = True Then matchup(22) = True
If homeplyr(4) = True And awayplyr(3) = True Then matchup(23) = True
If homeplyr(4) = True And awayplyr(4) = True Then matchup(24) = True
Static matchupshoot(49) As Boolean
If matchup(0) = True And hometeamisoffense = True And homeplayeroffensestat(0) > awayplayerdefensestat(0) Then matchupshoot(0) = True Else
If matchup(1) = True And hometeamisoffense = True And homeplayeroffensestat(0) > awayplayerdefensestat(1) Then matchupshoot(1) = True Else
If matchup(2) = True And hometeamisoffense = True And homeplayeroffensestat(0) > awayplayerdefensestat(2) Then matchupshoot(2) = True Else
If matchup(3) = True And hometeamisoffense = True And homeplayeroffensestat(0) > awayplayerdefensestat(3) Then matchupshoot(3) = True Else
If matchup(4) = True And hometeamisoffense = True And homeplayeroffensestat(0) > awayplayerdefensestat(4) Then matchupshoot(4) = True Else
If matchup(5) = True And hometeamisoffense = True And homeplayeroffensestat(1) > awayplayerdefensestat(0) Then matchupshoot(5) = True Else
If matchup(6) = True And hometeamisoffense = True And homeplayeroffensestat(1) > awayplayerdefensestat(1) Then matchupshoot(6) = True Else
If matchup(7) = True And hometeamisoffense = True And homeplayeroffensestat(1) > awayplayerdefensestat(2) Then matchupshoot(7) = True Else
If matchup(8) = True And hometeamisoffense = True And homeplayeroffensestat(1) > awayplayerdefensestat(3) Then matchupshoot(8) = True Else
If matchup(9) = True And hometeamisoffense = True And homeplayeroffensestat(1) > awayplayerdefensestat(4) Then matchupshoot(9) = True Else
If matchup(10) = True And hometeamisoffense = True And homeplayeroffensestat(2) > awayplayerdefensestat(0) Then matchupshoot(10) = True Else
If matchup(11) = True And hometeamisoffense = True And homeplayeroffensestat(2) > awayplayerdefensestat(1) Then matchupshoot(11) = True Else
If matchup(12) = True And hometeamisoffense = True And homeplayeroffensestat(2) > awayplayerdefensestat(2) Then matchupshoot(12) = True Else
If matchup(13) = True And hometeamisoffense = True And homeplayeroffensestat(2) > awayplayerdefensestat(3) Then matchupshoot(13) = True Else
If matchup(14) = True And hometeamisoffense = True And homeplayeroffensestat(2) > awayplayerdefensestat(4) Then matchupshoot(14) = True Else
If matchup(15) = True And hometeamisoffense = True And homeplayeroffensestat(3) > awayplayerdefensestat(0) Then matchupshoot(15) = True Else
If matchup(16) = True And hometeamisoffense = True And homeplayeroffensestat(3) > awayplayerdefensestat(1) Then matchupshoot(16) = True Else
If matchup(17) = True And hometeamisoffense = True And homeplayeroffensestat(3) > awayplayerdefensestat(2) Then matchupshoot(17) = True Else
If matchup(18) = True And hometeamisoffense = True And homeplayeroffensestat(3) > awayplayerdefensestat(3) Then matchupshoot(18) = True Else
If matchup(19) = True And hometeamisoffense = True And homeplayeroffensestat(3) > awayplayerdefensestat(4) Then matchupshoot(19) = True Else
If matchup(20) = True And hometeamisoffense = True And homeplayeroffensestat(4) > awayplayerdefensestat(0) Then matchupshoot(20) = True Else
If matchup(21) = True And hometeamisoffense = True And homeplayeroffensestat(4) > awayplayerdefensestat(1) Then matchupshoot(21) = True Else
If matchup(22) = True And hometeamisoffense = True And homeplayeroffensestat(4) > awayplayerdefensestat(2) Then matchupshoot(22) = True Else
If matchup(23) = True And hometeamisoffense = True And homeplayeroffensestat(4) > awayplayerdefensestat(3) Then matchupshoot(23) = True Else
If matchup(24) = True And hometeamisoffense = True And homeplayeroffensestat(4) > awayplayerdefensestat(4) Then matchupshoot(24) = True
If matchup(0) = True And hometeamisoffense = False And homeplayeroffensestat(0) < awayplayerdefensestat(0) Then matchupshoot(25) = True Else
If matchup(1) = True And hometeamisoffense = False And homeplayeroffensestat(0) < awayplayerdefensestat(1) Then matchupshoot(26) = True Else
If matchup(2) = True And hometeamisoffense = False And homeplayeroffensestat(0) < awayplayerdefensestat(2) Then matchupshoot(27) = True Else
If matchup(3) = True And hometeamisoffense = False And homeplayeroffensestat(0) < awayplayerdefensestat(3) Then matchupshoot(28) = True Else
If matchup(4) = True And hometeamisoffense = False And homeplayeroffensestat(0) < awayplayerdefensestat(4) Then matchupshoot(29) = True Else
If matchup(5) = True And hometeamisoffense = False And homeplayeroffensestat(1) < awayplayerdefensestat(0) Then matchupshoot(30) = True Else
If matchup(6) = True And hometeamisoffense = False And homeplayeroffensestat(1) < awayplayerdefensestat(1) Then matchupshoot(31) = True Else
If matchup(7) = True And hometeamisoffense = False And homeplayeroffensestat(1) < awayplayerdefensestat(2) Then matchupshoot(32) = True Else
If matchup(8) = True And hometeamisoffense = False And homeplayeroffensestat(1) < awayplayerdefensestat(3) Then matchupshoot(33) = True Else
If matchup(9) = True And hometeamisoffense = False And homeplayeroffensestat(1) < awayplayerdefensestat(4) Then matchupshoot(34) = True Else
If matchup(10) = True And hometeamisoffense = False And homeplayeroffensestat(2) < awayplayerdefensestat(0) Then matchupshoot(35) = True Else
If matchup(11) = True And hometeamisoffense = False And homeplayeroffensestat(2) < awayplayerdefensestat(1) Then matchupshoot(36) = True Else
If matchup(12) = True And hometeamisoffense = False And homeplayeroffensestat(2) < awayplayerdefensestat(2) Then matchupshoot(37) = True Else
If matchup(13) = True And hometeamisoffense = False And homeplayeroffensestat(2) < awayplayerdefensestat(3) Then matchupshoot(38) = True Else
If matchup(14) = True And hometeamisoffense = False And homeplayeroffensestat(2) < awayplayerdefensestat(4) Then matchupshoot(39) = True Else
If matchup(15) = True And hometeamisoffense = False And homeplayeroffensestat(3) < awayplayerdefensestat(0) Then matchupshoot(40) = True Else
If matchup(16) = True And hometeamisoffense = False And homeplayeroffensestat(3) < awayplayerdefensestat(1) Then matchupshoot(41) = True Else
If matchup(17) = True And hometeamisoffense = False And homeplayeroffensestat(3) < awayplayerdefensestat(2) Then matchupshoot(42) = True Else
If matchup(18) = True And hometeamisoffense = False And homeplayeroffensestat(3) < awayplayerdefensestat(3) Then matchupshoot(43) = True Else
If matchup(19) = True And hometeamisoffense = False And homeplayeroffensestat(3) < awayplayerdefensestat(4) Then matchupshoot(44) = True Else
If matchup(20) = True And hometeamisoffense = False And homeplayeroffensestat(4) < awayplayerdefensestat(0) Then matchupshoot(45) = True Else
If matchup(21) = True And hometeamisoffense = False And homeplayeroffensestat(4) < awayplayerdefensestat(1) Then matchupshoot(46) = True Else
If matchup(22) = True And hometeamisoffense = False And homeplayeroffensestat(4) < awayplayerdefensestat(2) Then matchupshoot(47) = True Else
If matchup(23) = True And hometeamisoffense = False And homeplayeroffensestat(4) < awayplayerdefensestat(3) Then matchupshoot(48) = True Else
If matchup(24) = True And hometeamisoffense = False And homeplayeroffensestat(4) < awayplayerdefensestat(4) Then matchupshoot(49) = True
If matchupshoot(0) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(1) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(2) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(3) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(4) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(5) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(6) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(7) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(8) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(9) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(10) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(11) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(12) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(13) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(14) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(15) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(16) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(17) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(18) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(19) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(20) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(21) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(22) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(23) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(24) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(25) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(26) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(27) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(28) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(29) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(30) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(31) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(32) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(33) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(34) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(35) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(36) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(37) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(38) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(39) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(40) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(41) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(42) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(43) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(44) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(45) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(46) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(47) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(48) = True Then Label74.Text = "Offense takes a shot!" Else
If matchupshoot(49) = True Then Label74.Text = "Offense takes a shot!" Else
Label74.Text = "Offense does not get to shoot!"