Hello,
I am very very new at VB 2008 and Coding. I need to create a Basketball simulator that has two teams of five players each. Each player has an offensive, defensive and shooting percentage. whih are randomly generated and the uses can randomly generate them until he is happy with the team. I was able to code this part.
However, this is the part I'm having difficulty with . The player then press a simulate butoon which will trigger match-up between the two teams in this manner one team is defense and the other is offense . The defensive rank of the defensive plyer is compared to the offensive rank of the offensive player. If the offensive rank is higher then the offensive player gets to shoot. A random number from 1 - 100 is generated if this is below the scoring percentage of the offensive player that team scores 2 points. Each match up last 24 second there are 4 quarters 12 minutes long total of 120 march up. My problem is I cannot figure out how to display the randks shooting percetage and attempts per quarter in the score holders. Please someone , please help. Thank you so much for taking time to review this. Here are my codes so far

Option Explicit On
Option Strict On
Public Class mainForm


    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        totalScoreBoard.Show()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles homeButton.Click

        Dim number As Integer
        Dim randomGenerator As New Random

        number = randomGenerator.Next((8), 11)
        TextBox1.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox2.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox3.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox4.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox5.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox6.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox7.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox8.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox9.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox10.Text = Convert.ToString(number)
        'generate and display radom number 55 - 80
        number = randomGenerator.Next(55, 81)
        TextBox11.Text = Convert.ToString(number)
        number = randomGenerator.Next(55, 81)
        TextBox12.Text = Convert.ToString(number)
        number = randomGenerator.Next(55, 81)
        TextBox13.Text = Convert.ToString(number)
        number = randomGenerator.Next(55, 81)
        TextBox14.Text = Convert.ToString(number)
        number = randomGenerator.Next(55, 81)
        TextBox15.Text = Convert.ToString(number)
        number = randomGenerator.Next(55, 81)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles visitorButton.Click
        Dim number As Integer
        Dim randomGenerator As New Random

        number = randomGenerator.Next((8), 11)
        TextBox90.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox89.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox88.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox87.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox151.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)

        TextBox86.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox85.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox84.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox83.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox82.Text = Convert.ToString(number)
        number = randomGenerator.Next((8), 11)
        TextBox81.Text = Convert.ToString(number)

        'generate and display radom number 55 - 80
        number = randomGenerator.Next(55, 81)
        TextBox80.Text = Convert.ToString(number)
        number = randomGenerator.Next(55, 81)
        TextBox79.Text = Convert.ToString(number)
        number = randomGenerator.Next(55, 81)
        TextBox78.Text = Convert.ToString(number)
        number = randomGenerator.Next(55, 81)
        TextBox77.Text = Convert.ToString(number)
        number = randomGenerator.Next(55, 81)
        TextBox76.Text = Convert.ToString(number)
        number = randomGenerator.Next(55, 81)

    End Sub

    Private Sub playButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles playButton.Click
        Dim homeOffRank(4) As Integer
        Dim HomeDefRank(4) As Integer
        Dim VisitorOffRank(4) As Integer
        Dim VisitorDefRank(4) As Integer
        Dim player As Integer
        Dim HomeShotRank(4) As Integer
        Dim VisitorShotRank(4) As Integer
        Dim RandomGenerator As New Random
        Dim isConverted As Boolean
        Dim I As Integer = 0
        'generate random player from Home and Visitor
        player = RandomGenerator.Next(1, 11)
        Label84.Text = CStr(RandomGenerator.Next(1, 101))

        Dim offense As Integer
        Dim randomgenerator2 As New Random
        offense = randomgenerator2.Next(0, 2)
        If offense = 0 Then Label1.Text = "Home Team Offense"
        If offense = 0 Then Label2.Text = "Visitor Team Defense"
        If offense = 1 Then Label1.Text = "Home Team Defense"
        If offense = 1 Then Label2.Text = "Visitor Team Offense"

        'compare the offensive rank of the offensive player to the defensive
        'rank of the defensive player. 
        Dim HomeTeam(4) As Boolean
        Dim VisitorTeam(4) As Boolean
        Dim HomeTeamOff As Boolean
        Dim VisitorTeamOff As Boolean


        If Label1.Text = "Offense" Then
            HomeTeamOff = True
        ElseIf Label1.Text = "Defense" Then
            VisitorTeamOff = True
        End If

        If HomeTeamOff = True AndAlso Label1.Text = "Home Player #1" Then
            HomeTeam(0) = True 
        ElseIf HomeTeamOff = True AndAlso Label1.Text = "Home Player #2" Then
            HomeTeam(1) = True
        ElseIf HomeTeamOff = True AndAlso Label1.Text = "Home Player #3" Then
            HomeTeam(2) = True
        ElseIf HomeTeamOff = True AndAlso Label1.Text = "Home Player #4" Then
            HomeTeam(3) = True
        ElseIf HomeTeamOff = True AndAlso Label1.Text = "Home Player #5" Then
            HomeTeam(4) = True
        End If
        If VisitorTeamOff = True AndAlso Label2.Text = "Visitor Player #1" Then
            VisitorTeam(0) = True
        ElseIf VisitorTeamOff = True AndAlso Label2.Text = "Visitor Player #2" Then
            VisitorTeam(1) = True
        ElseIf VisitorTeamOff = True AndAlso Label2.Text = "Visitor Player #3" Then
            VisitorTeam(2) = True
        ElseIf VisitorTeamOff = True AndAlso Label2.Text = "Visitor Player #4" Then
            VisitorTeam(3) = True
        ElseIf VisitorTeamOff = True AndAlso Label2.Text = "Visitor Player #5" Then
            VisitorTeam(4) = True
        End If




    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gameTimer.Tick
        gameTimer.Enabled = True

    End Sub



    Private Sub Panel3_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)

    End Sub

    Private Sub TextBox39_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub TextBox40_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Label21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Label22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub TextBox44_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub TextBox43_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub TextBox42_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub TextBox41_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub TextBox45_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub Label84_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label84.Click

    End Sub

    Private Sub exitButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton1.Click
        Me.Close()

    End Sub
End Class
Comments
Good Job With Code Tags!

Well, I'm not sure exactly what you are trying to do, but I do have a few comments.

I noticed this block of code in the playButton_Click subroutine:

If Label1.Text = "Home Team Offense" Then
            HomeTeamOff = True
        ElseIf Label1.Text = "Home Team Defense" Then
            VisitorTeamOff = True
        End If

HomeTeamOff and VisitorTeamOff with always be false because label1.Text is always either "Home Team Defense" or "Home Team Offense"

Secondly, I noticed this block of code:

If HomeTeamOff = True AndAlso Label1.Text = "Home Player #1" Then
            HomeTeam(0) = True
        ElseIf HomeTeamOff = True AndAlso Label1.Text = "Home Player #2" Then
            HomeTeam(1) = True
        ElseIf HomeTeamOff = True AndAlso Label1.Text = "Home Player #3" Then
            HomeTeam(2) = True
        ElseIf HomeTeamOff = True AndAlso Label1.Text = "Home Player #4" Then
            HomeTeam(3) = True
        ElseIf HomeTeamOff = True AndAlso Label1.Text = "Home Player #5" Then
            HomeTeam(4) = True
        End If
        If VisitorTeamOff = True AndAlso Label2.Text = "Visitor Player #1" Then
            VisitorTeam(0) = True
        ElseIf VisitorTeamOff = True AndAlso Label2.Text = "Visitor Player #2" Then
            VisitorTeam(1) = True
        ElseIf VisitorTeamOff = True AndAlso Label2.Text = "Visitor Player #3" Then
            VisitorTeam(2) = True
        ElseIf VisitorTeamOff = True AndAlso Label2.Text = "Visitor Player #4" Then
            VisitorTeam(3) = True
        ElseIf VisitorTeamOff = True AndAlso Label2.Text = "Visitor Player #5" Then
            VisitorTeam(4) = True
        End If

None of these conditions will ever be true for two reasons:
(1) HomeTeamOff and VisitorTeamOff will always be false for the reason I mentioned above.
(2) Label2.Text is always either "Visitor Team offense" or "Visitor Team defense" and never Visitor Player #1, #2, etc.

I see where you generate the random number between 0 and 100; however, I don't know what you are trying to do with it. What is the scoring percentage that you mention?

Just a general comment; I see that you store a lot of values in textboxes. I recommend that you store value in arrays and classes and only display the output in the textboxes; that will make things a lot easier to understand and follow, especially for other people reading your code.

Dear Timothy,
Thank you for taking the time to go through my codes. I appreciated it so much. In answer to your question of the random number from 1 to 100 the number generated is to be compared to the scoring percentage of the offensive player. If the random number is below the offensive player percentage then the team scores 2 points. I'm now following your suggestion of storing values in arrays and classes. Once again thank you.

Okay... I think I'm understanding this a little better, but I still have a few questions

(1) Is SHTS% the scoring percentage you are talking about?
(2) You mention the scoring percentage of the Offensive Player... who is the Offensive Player? Is see the following line in the playButton_Click subroutine:

player = RandomGenerator.Next(1, 11)

Is this meant to select the offensive player?
(3) What is the purpose of the following code?

offense = randomgenerator2.Next(0, 2)
If offense = 0 Then Label1.Text = "Home Team Offense"
If offense = 0 Then Label2.Text = "Visitor Team Defense"
If offense = 1 Then Label1.Text = "Home Team Defense"
If offense = 1 Then Label2.Text = "Visitor Team Offense"

Is it meant to select which team is offense and which team is defense?

If I am correct about the purpose of items 2 and 3 above, then I would recommend that you have the program determine which team is offense and defense before you select an offensive player. Once you know which team is offense, you only need a random number from 1 to 5. Knowing which team is offensive and the random number between 1 and 5, you can determine the offensive player is. Once you know who the offensive player is, you can either add code to look up the SHTS% for that player by looking at the textboxes, which I don't recommend, or look up the SHTS% in an array and/or class, which would make things a lot easier to understand and modify in the future.

Let me know how things go and I can continue to assist you.

This article has been dead for over six months. Start a new discussion instead.