Question: Private Sub btnDisplay _ Click ( sender As Object, e As EventArgs ) Handles btnDisplay.Click ' Read the states from the file Dim lines (

Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
' Read the states from the file
Dim lines() As String = IO.File.ReadAllLines("USStates.txt")
' Create a query to calculate the total land area
Dim totalAreaQuery =
From line In lines
Let parts = line.Split(","c)
Let area = Integer.Parse(parts(2))
Select area
Dim totalArea As Integer = totalAreaQuery.Sum()
' Create a query to order the states by land area and calculate the percentage of the total area
Dim statesQuery =
From line In lines
Let parts = line.Split(","c)
Let name = parts(0)
Let area = Integer.Parse(parts(2))
Let percent =(area / totalArea)*100
Order By area Descending
Select name, percent.ToString("F2") & "%"
' Display the results in the data grid view
dgvOutput.DataSource = statesQuery.ToList()
dgvOutput.Columns(0).HeaderText = "State"
dgvOutput.Columns(1).HeaderText = "Percentage of Total Area"
End Sub

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!