Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In a multiform VB app I have the below code. In the bold section below I also ne

ID: 3847780 • Letter: I

Question

In a multiform VB app I have the below code. In the bold section below I also need the player's score to transfer to the "goals" column on form 1. The name transfers fine but all of the code I use to transfer the score results in an error. Any suggestions? My forms look like this when in use...(also if you can tell me how to change the color on the list headers I would appreciate it!)

Public Class Form2
Public Sub form2_activate()
Dim loadcount As Integer = 0
For loadcount = 0 To (Form1.strPlayers.Length - 1)
cboChoosePlayer.Items.Add(Form1.strPlayers(loadcount))
Next
End Sub

Private Sub btnReturn_Click(sender As Object, e As EventArgs) Handles btnReturn.Click
Me.Close()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnAddPlayer.Click
Dim strPlayerInput As String = ""

'tells user to enter player name, adjusts form 1 as needed
strPlayerInput = InputBox("Enter Player Name")

If Form1.strPlayers IsNot Nothing Then
Array.Resize(Form1.strPlayers, Form1.strPlayers.Length + 1)
Array.Resize(Form1.intscore, Form1.intscore.Length + 1)
Form1.strPlayers(Form1.strPlayers.Length - 1) = strPlayerInput
Form1.intscore(Form1.strPlayers.Length - 1) = 0
Else
ReDim Form1.strPlayers(0)
ReDim Form1.intscore(0)
Form1.strPlayers(0) = strPlayerInput
Form1.intscore(0) = 0

End If

'display player name in combo box
cboChoosePlayer.Items.Add(Form1.strPlayers(Form1.strPlayers.Length - 1))


End Sub

Private Sub cboPlayer_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboChoosePlayer.SelectedIndexChanged
Form1.intPlayerScoreConnector = 0

'On selecting a player, updates score text box with current score for player.
Dim intcount As Integer = 0
For intcount = 0 To Form1.strPlayers.Length - 1
If Form1.strPlayers(intcount) Is cboChoosePlayer.SelectedItem Then
Form1.intPlayerScoreConnector = cboChoosePlayer.SelectedIndex

txtGoals.Text = CStr(Form1.intscore(cboChoosePlayer.SelectedIndex))
End If
Next


End Sub

Private Sub txtPoints_TextChanged(sender As Object, e As EventArgs) Handles txtGoals.TextChanged

End Sub

Private Sub btnUpdatePoints_Click(sender As Object, e As EventArgs) Handles btnUpdatePoints.Click

Dim intTest As Integer

'Confirm player has been selected
If cboChoosePlayer.SelectedIndex = -1 Then
MessageBox.Show("Choose a player")
Else
If Integer.TryParse(txtGoals.Text, intTest) Then 'Check to see if numerical
If intTest < 0 Then 'verify positive number
MessageBox.Show("Please enter a positive number")
Exit Sub
End If

'add player name and points to form1 list
Form1.intscore(cboChoosePlayer.SelectedIndex) = CInt(txtGoals.Text)

Else
MessageBox.Show("Please enter a number")

End If
End If

'Display info in form1 list
Dim IntTotal As Integer
Dim IntCount As Integer
If Form1.strPlayers IsNot Nothing Then
Form1.lstvPlayerScores.Clear()

For IntCount = 0 To (Form1.intscore.Length - 1)
IntTotal += Form1.intscore(IntCount)
Next
Form1.lblTotal.Text = CStr(IntTotal)

Form1.lstvPlayerScores.View = View.Details
Form1.lstvPlayerScores.Columns.Add("Player Name")
Form1.lstvPlayerScores.Columns.Add("Goals")

For IntCount = 0 To (Form1.strPlayers.Length - 1)
Form1.lstvPlayerScores.Items.Add(Form1.strPlayers(IntCount))

Next
Else
End If
For intlstvSize As Integer = 0 To Form1.lstvPlayerScores.Columns.Count - 1
Form1.lstvPlayerScores.Columns(intlstvSize).Width = -2
Next

End Sub

Private Sub btnRemove_Click(sender As Object, e As EventArgs)

End Sub

Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

End Sub
End Class

B Form1 Score Keeper Player Name Goals Game Total Add Players and Goals Exit Form2 Players Add Player hg Select a player, enter points, and push Goal! to add points. close window Goal!

Explanation / Answer

Public Class Form2
Public Sub form2_activate()
Dim loadcount As Integer = 0
For loadcount = 0 To (Form1.strPlayers.Length - 1)
cboChoosePlayer.Items.Add(Form1.strPlayers(loadcount))
Next
End Sub

Private Sub btnReturn_Click(sender As Object, e As EventArgs) Handles btnReturn.Click
Me.Close()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnAddPlayer.Click
Dim strPlayerInput As String = ""

'tells user to enter player name, adjusts form 1 as needed
strPlayerInput = InputBox("Enter Player Name")

If Form1.strPlayers IsNot Nothing Then
Array.Resize(Form1.strPlayers, Form1.strPlayers.Length + 1)
Array.Resize(Form1.intscore, Form1.intscore.Length + 1)
Form1.strPlayers(Form1.strPlayers.Length - 1) = strPlayerInput
Form1.intscore(Form1.strPlayers.Length - 1) = 0
Else
ReDim Form1.strPlayers(0)
ReDim Form1.intscore(0)
Form1.strPlayers(0) = strPlayerInput
Form1.intscore(0) = 0

End If

'display player name in combo box
cboChoosePlayer.Items.Add(Form1.strPlayers(Form1.strPlayers.Length - 1))


End Sub

Private Sub cboPlayer_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboChoosePlayer.SelectedIndexChanged
Form1.intPlayerScoreConnector = 0

'On selecting a player, updates score text box with current score for player.
Dim intcount As Integer = 0
For intcount = 0 To Form1.strPlayers.Length - 1
If Form1.strPlayers(intcount) Is cboChoosePlayer.SelectedItem Then
Form1.intPlayerScoreConnector = cboChoosePlayer.SelectedIndex

txtGoals.Text = CStr(Form1.intscore(cboChoosePlayer.SelectedIndex))
End If
Next


End Sub

Private Sub txtPoints_TextChanged(sender As Object, e As EventArgs) Handles txtGoals.TextChanged

End Sub

Private Sub btnUpdatePoints_Click(sender As Object, e As EventArgs) Handles btnUpdatePoints.Click

Dim intTest As Integer

'Confirm player has been selected
If cboChoosePlayer.SelectedIndex = -1 Then
MessageBox.Show("Choose a player")
Else
If Integer.TryParse(txtGoals.Text, intTest) Then 'Check to see if numerical
If intTest < 0 Then 'verify positive number
MessageBox.Show("Please enter a positive number")
Exit Sub
End If

'add player name and points to form1 list
Form1.intscore(cboChoosePlayer.SelectedIndex) = CInt(txtGoals.Text)

Else
MessageBox.Show("Please enter a number")

End If
End If

  'Display info in form1 list
Dim IntTotal As Integer
Dim IntCount As Integer
If Form1.strPlayers IsNot Nothing Then
Form1.lstvPlayerScores.Clear()

For IntCount = 0 To (Form1.intscore.Length - 1)
IntTotal += Form1.intscore(IntCount)
Next
Form1.lblTotal.Text = CStr(IntTotal)

Form1.lstvPlayerScores.View = View.Details
Form1.lstvPlayerScores.Columns.Add("Player Name")
Form1.lstvPlayerScores.Columns.Add("Goals")

For IntCount = 0 To (Form1.strPlayers.Length - 1)
Form1.lstvPlayerScores.Items.Add(Form1.strPlayers(IntCount))

Next
Else
End If
For intlstvSize As Integer = 0 To Form1.lstvPlayerScores.Columns.Count - 1
Form1.lstvPlayerScores.Columns(intlstvSize).Width = -2
Next

End Sub

Private Sub btnRemove_Click(sender As Object, e As EventArgs)

End Sub

Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

End Sub
End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote