Visual Basic program: How do you code the below data using the visual basic prog
ID: 3718611 • Letter: V
Question
Visual Basic program: How do you code the below data using the visual basic program in OleDb?
1. The user can tap or click the Ages Button object to compute the total number of team members who are 12, 13, or, 14 years old.
2. Computes in three separate counts the number of team members who are 12, 13, or 14 years old.
3. Compute the average age of the team.
Access data
Name Age
Alyssa 13
Alana 13
Aaron 12
Claire 14
Lalo 14
Braden 14
Lauren 13
Ethan 12
Tristan 14
Alexis 12
Dai Rai 13
Ariana 14
Tyler 14
Riley 13
Devin 14
Savanna 14
Adrian 14
Jaden 14
Brandon 14
Logan 12
Gabriel 13
Ashton 13
Here is my code:
Private Sub btnAges_Click(sender As Object, e As EventArgs) Handles btnAges.Click
Dim strSql As String = "SELECT * FROM Team"
Dim strPath As String = "Provider=Microsoft.ACE.OLEDB.12.0 ;" & "Data Source=f:LittleLeague.accdb"
Dim odaTeam As New OleDb.OleDbDataAdapter(strSql, strPath)
Dim datValue As New DataTable
Dim intCount As Integer
Dim decTotalValue As Integer = 0D
Dim twelveCount As Integer = 0
Dim thirteenCount As Integer = 0
Dim fourteenCount As Integer = 0
Dim total As Integer = 0
Dim avg As Double = 0
odaTeam.Fill(datValue)
odaTeam.Dispose()
For intCount = 0 To datValue.Rows.Count - 1
decTotalValue += datValue.Rows(intCount)("Age")
Next
lblResult.Visible = True
lblResult.Text = "Total number of team members who are 12, 13, or 14 years old: " & decTotalValue.ToString("")
End Sub
End Class
Output:
Note: The number of team members I got is 293 instead of 22. How do you code the number of rows to become 22?
Little Leagues Baseball Team Database Little Leagues Baseball Team Database Player Number 2 Cty: Memphis First Name: Alyssa State TN Last Name: Johnson Zp Code: 35612 Parent Name(s Michael and Reaga Telephone Number: 555-2545 Address 635 Watts Rd Age: 13 Ages Total number of team members who are 12. 13, or 14 years old: 293 ExitExplanation / Answer
There are many ways to achieve that and sharing few of them here.
Code To Be Replaced:
New Code:
2. if you want to do it inside the forloop, Replace the following inside the for loop
Code To Be Replaced:
New Code:
From the above you can use either one of them,
Hope this helps.
decTotalValue += datValue.Rows(intCount)("Age")Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.