Public Class frmBachelorDeg Private Sub btnQuit_Click(sender As System.Object, e
ID: 3656842 • Letter: P
Question
Public Class frmBachelorDeg Private Sub btnQuit_Click(sender As System.Object, e As System.EventArgs) Handles btnQuit.Click 'This button closes the program Me.Close() End Sub Structure Degrees Dim fieldStudy As String Dim begYear As String Dim endYear As String Sub New(ByRef fieldStudy As String, ByRef begYear As String, ByRef endYear As String) 'This block of code initializes the structure of the first array, comparing degrees in 1981 versus 2006 Me.fieldStudy = fieldStudy Me.begYear = begYear Me.endYear = endYear End Sub End Structure Structure Change 'This block initializes the structure of the second array, showing the change in percent between 1981 and 2006 Dim fieldStudy As String Dim percentChange As String Sub New(ByRef fieldStudy As String, ByRef percentChange As String) Me.fieldStudy = fieldStudy Me.percentChange = percentChange End Sub End Structure Structure Histogram 'This block initializes the structure of the third array, showing a pictoral representation of the degrees in 2006 Dim fieldStudy As String Dim characters As String Dim numDegrees As String Sub New(ByRef fieldstudy As String, ByRef characters As String, ByRef numdegrees As String) Me.fieldStudy = fieldstudy Me.characters = characters Me.numDegrees = numdegrees End Sub End Structure Private Sub btnDegrees_Click(sender As System.Object, e As System.EventArgs) Handles btnDegrees.Click 'This part of the program displays the number of degrees in 1981 versus 2006 Dim listdeg As New ArrayList listdeg.Add(New Degrees("Field of Study", "1981", "2006")) listdeg.Add(New Degrees("Business", "200,521", "318,042")) listdeg.Add(New Degrees("Computer and info. science", "15,121", "47,480")) listdeg.Add(New Degrees("Education", "108,074", "107,238")) listdeg.Add(New Degrees("Engineering", "63,642", "67,045")) listdeg.Add(New Degrees("Social sciences and history", "100,513", "161,485")) dgvOutput.DataSource = listdeg dgvOutput.CurrentCell = Nothing dgvOutput.Columns("fieldStudy").HeaderText = "Field of Study" dgvOutput.Columns("begYear").HeaderText = "1981" dgvOutput.Columns("endYear").HeaderText = "2006" End Sub Private Sub btnChanges_Click(sender As System.Object, e As System.EventArgs) Handles btnPercent.Click 'This button accurately reflects the percentage increase/decrease of graduates pursuing degrees in each field between 1981-2006 Dim listcng As ArrayList = New ArrayList listcng.Add(New Change("Computer and Info. Science", "214.0%")) listcng.Add(New Change("Social Sciences and History", "60.7%")) listcng.Add(New Change("Business", "58.6%")) listcng.Add(New Change("Engineering", "5.3%")) listcng.Add(New Change("Education", "-0.8%")) dgvOutput.DataSource = listcng dgvOutput.DataSource = Nothing dgvOutput.Columns("fieldStudy").HeaderText = "Field of Study" dgvOutput.Columns("percentChange").HeaderText = "% Change(1981-2006)" End Sub Private Sub btnHistogram_Click(sender As System.Object, e As System.EventArgs) Handles btnHistogram.Click 'Displays a histogram of degrees conferred in specified fields Dim listhist As ArrayList = New ArrayList listhist.Add(New Histogram("Computer and Info. Science", Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149), "47,480")) listhist.Add(New Histogram("Engineering", Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149), "67,045")) listhist.Add(New Histogram("Education", Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149), "107,238")) listhist.Add(New Histogram("Social sciences and History", Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149), "161,485")) listhist.Add(New Histogram("Business", Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149) & Chr(149), "318,042")) dgvOutput.DataSource = listhist dgvOutput.DataSource = Nothing dgvOutput.Columns("fieldStudy").HeaderText = "Field of Study" dgvOutput.Columns("characters").HeaderText = " " dgvOutput.Columns("numDegrees").HeaderText = "Degrees in 2006" End Sub End ClassExplanation / Answer
try the below code... Imports System.IO Public Class frmBachelorDegrees Dim input As New DataTable 'setup new datatable named input, to store file Dim major As New ArrayList() 'setup array named major, to store majors Dim numDeg81 As New ArrayList() ' array, of number of degrees for this in 1981 Dim numDeg11 As New ArrayList() ' array, of number of degrees for this in 10`` Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click ' seach functions (exact search) For j As Integer = 0 To major.Count - 1 If major(j).ToString = txtStudy.Text Then ' loop through the array of names until the textbox exactly equals one of the majors in the array txtResult.Text = "The number of degrees conferred in " + major(j).ToString + " was " + numDeg81(j).ToString + " in 1981 and " + numDeg11(j).ToString + " in 2011" End If Next End Sub Private Sub btnTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTable.Click ' create a table using a textbox, creating a list with a string Dim stringText As String = "" stringText = "Bachelor Degrees Conferred in Certain Fields" + vbNewLine + vbNewLine + "Field of Study" + vbTab + vbTab + vbTab + vbTab + "1981" + vbTab + "2001" ' add 2 blank lines stringText += vbNewLine + vbNewLine ' loop through the majors, and add them to a string. A single string within the textbox For j As Integer = 0 To major.Count - 1 If major(j).ToString.Length > 11 Then ' if a major is longer than the word engineering, use only two tabs in the string stringText += major(j).ToString + vbTab + vbTab + numDeg81(j).ToString + vbTab + numDeg11(j).ToString + vbNewLine Else ' if a major is as short as the word 'engineering' or shorter, use two tabs within the text string stringText += major(j).ToString + vbTab + vbTab + vbTab + vbTab + numDeg81(j).ToString + vbTab + numDeg11(j).ToString + vbNewLine End If Next stringText += vbNewLine + "Source: U.S. National Center of Education Statistics" TextBox1.Text = stringText End Sub Private Sub btnPercent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPercent.Click Dim PerChange As Decimal Dim stringText As String = "" stringText = "Percentage Change in Bachelor Degrees Conferred" + vbNewLine + vbNewLine + "Field of Study" + vbTab + vbTab + vbTab + vbTab + "% Change (1981-2011)" stringText += vbNewLine + vbNewLine For j As Integer = 0 To major.Count - 1 PerChange = (CDec(numDeg11(j)) - CDec(numDeg81(j))) / (CDec(numDeg81(j))) If major(j).ToString.Length > 11 Then stringText += major(j).ToString + vbTab + vbTab + (PerChange).ToString + vbNewLine Else stringText += major(j).ToString + vbTab + vbTab + vbTab + vbTab + (PerChange).ToString + vbNewLine End If Next TextBox1.Text = stringText End Sub Private Sub btnHistogram_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHistogram.Click Dim stringText As String = "" stringText = "Percentage Change in Bachelor Degrees Conferred" + vbNewLine + vbNewLine For j As Integer = 0 To major.Count - 1 ' create integer numStar to find number of stars (degrees in each array element, divided by 10000 gives number of stars) Dim numStar As Integer = numDeg11(j) / 10000 If major(j).ToString.Length > 11 Then stringText += major(j).ToString + vbTab + vbTab For k As Integer = 0 To numStar - 1 stringText += "*" Next stringText += vbNewLine Else stringText += major(j).ToString + vbTab + vbTab + vbTab + vbTab For k As Integer = 0 To numStar - 1 stringText += "*" Next stringText += vbNewLine End If Next TextBox1.Text = stringText End Sub Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click ''Closes the program Application.Exit() End Sub Private Sub frmBachelorDegrees_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim input_csvPath = System.IO.Path.GetDirectory(System.Reflection.Assembly.GetExecutingAssembly.Location()) ' ************************************* you have the same code and new comments starting below Dim input_csvFile = "degrees.txt" Try Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + input_csvPath + ";Extended Properties='text;HDR=NO;FMT=Delimited'") Dim command As New OleDb.OleDbCommand("SELECT * FROM `" + input_csvFile + "`", conn) Dim da As New OleDb.OleDbDataAdapter(command) da.Fill(input) Catch ex As Exception Throw ex End Try Try For Each dr In input.Rows major.Add(dr(0)) numDeg81.Add(dr(1)) numDeg11.Add(dr(2)) Next Catch ex As Exception Throw ex End Try End Sub End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.