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

Visual Basic program: How do you code and compute in three separate counts the n

ID: 3719199 • Letter: V

Question

Visual Basic program: How do you code and compute in three separate counts the number of team members who are 12, 13, or 14 years old? Find attached my program for your perusal.

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 = 0

        Dim twelveCount As Integer = 0

        Dim thirteenCount As Integer = 0

        Dim fourteenCount As Integer = 0

        Dim total As Integer = 0

        Dim avg As Integer = 0

        odaTeam.Fill(datValue)

        odaTeam.Dispose()

        For intCount = 0 To datValue.Rows.Count - 1

            decTotalValue = datValue.Rows.Count

            total += datValue.Rows(intCount)("Age")

        Next

        avg = total / decTotalValue

        lblResult.Visible = True

        lblResult.Text = "The total number of team members who are 12, 13, or 14 years old is " & decTotalValue.ToString("") & (" and ") &

            "the average age of the team is " & avg

    End Sub

End Class

Explanation / Answer

Imports System

Imports System.Collections.Generic

Imports System.Linq

Imports System.Text.RegularExpressions

imports System.Data.OleDb

imports System.Data

Namespace Rextester

Public Module Program

public class Application

Private Sub btnAges_Click(sender As Object, e As EventArgs) Handles btnAges.Click

'Get the Team table data where age 12

Dim str12_Sql As String = "SELECT * FROM Team where age=12"

'Get the Team table data where age 13

Dim str13_Sql As String = "SELECT * FROM Team where age=13"

'Get the Team table data where age 14

Dim str14_Sql As String = "SELECT * FROM Team where age=14"

Dim strPath As String = "Provider=Microsoft.ACE.OLEDB.12.0 ;" & "Data Source=f:LittleLeague.accdb"

Dim odaTeam As New OleDb.OleDbDataAdapter(str12_Sql, strPath)

Dim odaTeam1 As New OleDb.OleDbDataAdapter(str13_Sql, strPath)

Dim odaTeam2 As New OleDb.OleDbDataAdapter(str14_Sql, strPath)

Dim datValue As New DataTable

Dim datValue1 As New DataTable

Dim datValue2 As New DataTable

Dim intCount As Integer

Dim decTotalValue As Integer = 0

Dim twelveCount As Integer = 0

Dim thirteenCount As Integer = 0

Dim fourteenCount As Integer = 0

Dim total As Integer = 0

Dim avg_12 As Integer = 0

Dim avg_13 As Integer = 0

Dim avg_14 As Integer = 0

odaTeam.Fill(datValue)

odaTeam1.Fill(datValue1)

odaTeam2.Fill(datValue2)

odaTeam.Dispose()

odaTeam1.Dispose()

odaTeam2.Dispose()

'Calculating the total and average of person whose age is 12

For intCount = 0 To datValue.Rows.Count - 1

twelveCount = datValue.Rows.Count

total += datValue.Rows(intCount)("Age")

Next

avg_12 = total / decTotalValue

'Calculating the total and average of person whose age is 13

total=0

For intCount = 0 To datValue1.Rows.Count - 1

thirteenCount = datValue1.Rows.Count

total += datValue1.Rows(intCount)("Age")

Next

avg_13 = total / decTotalValue

'Calculating the total and average of person whose age is 14

total=0

For intCount = 0 To datValue2.Rows.Count - 1

fourteenCount = datValue2.Rows.Count

total += datValue2.Rows(intCount)("Age")

Next

avg_14 = total / decTotalValue

  

'Please take 3 labels name for libResult1,libResult2 and libResult3

lblResult.Visible = True

lblResult.Text = "The total number of team members who are 12 years old is " & twelveCount.ToString("") & (" and ") &

"the average age of the team is " & avg_12

lblResult1.Visible = True

lblResult1.Text = "The total number of team members who are 13 years old is " & thirteenCount.ToString("") & (" and ") &

"the average age of the team is " & avg_13

lblResult2.Visible = True

lblResult2.Text = "The total number of team members who are 14 years old is " & fourteenCount.ToString("") & (" and ") &

"the average age of the team is " & avg_14

End Sub

End Class

End Module