I'm writing a windows app to display population increase within the next 5 years depending on the city selection. There will be two forms, the second form being a display of the cities with the population if the user clicks on the menu button.
text file: e:0\references\cities.txt
New York City
8214316
Los Angeles
3849378
Chicago
2886251
Houston
2144834
Philadelphia
1492231
Phoenix
1371960
San Diego
1269532
Dallas
1211467
San Antonio
1194222
Detroit
925051
The code should read the text then insert the info into a combo box. Depending on the combobox selection, code will calculate for the next 5 years the population increase by 3%each year and display the results in a listbox / lstDisplay .I've been on this for 3 days and can't seem to get the calcualtions correct. Please help.
Public Class Population
Private _List As Integer = 5
Public Shared _cityArray() As String
Public Shared _cityPopulationArray() As Decimal
Private Sub Population_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objReader As IO.StreamReader
' Dim strwriter As IO.StreamWriter
Dim intCount As Integer = 0
Dim intFill As Integer
Dim strErrorMsg As String = " Error reading file, try again!"
IO.File.Exists("e:0\references\cities.txt") Then
objReader = IO.File.OpenText("e:0\references\cities.txt")
'OPENS TEXT FILE
If
'READS TEXT FILE
Do While objReader.Peek <> -1
_cityArray(intCount) = Convert.ToString(objReader.ReadLine()) 'assigns 1st element
_cityPopulationArray(intCount) = Convert.ToInt32(objReader.ReadLine()) 'assigns 2nd element
intCount += 1 ' repeat until no more data
Loop
objReader.Close()
'inserts array into combo box
For intFill = 0 To (_cityArray.Length - 1)
Me.cboCities.Items.Add(_cityArray(intFill))
Next
Else
MsgBox(strErrorMsg, , "Error")
Me.Close()
End If
'ACCESSING
Dim popIncrease(9) As Single '= _cityPopulationArray(intCount)
Dim citySelection(9) As String '= _cityArray(intCount)
End Sub
Private Sub mnuDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDisplay.Click
'displays new window form for list of largest cities
Dim largestCityList As New frmDisplayCity
'display 2nd form window until closed b4 access to 1st window code
Me.Hide()
largestCityList.ShowDialog()
End Sub
Private Sub mnuClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClear.Click
cboCities.SelectedItem = (0)
End Sub
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
Me.Close()
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim citySelectedItem As Integer
Dim intSelectedItemId As Integer
Dim populationIncrease As Single
Dim popIncrease As Decimal
If Me.cboCities.SelectedIndex = 0 Then
populationIncrease = CSng(popIncrease * 0.3)
End If
lstDisplay.Text = populationIncrease.ToString
End Sub
End Class
text file: e:0\references\cities.txt
New York City
8214316
Los Angeles
3849378
Chicago
2886251
Houston
2144834
Philadelphia
1492231
Phoenix
1371960
San Diego
1269532
Dallas
1211467
San Antonio
1194222
Detroit
925051
The code should read the text then insert the info into a combo box. Depending on the combobox selection, code will calculate for the next 5 years the population increase by 3%each year and display the results in a listbox / lstDisplay .I've been on this for 3 days and can't seem to get the calcualtions correct. Please help.
Public Class Population
Private _List As Integer = 5
Public Shared _cityArray() As String
Public Shared _cityPopulationArray() As Decimal
Private Sub Population_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objReader As IO.StreamReader
' Dim strwriter As IO.StreamWriter
Dim intCount As Integer = 0
Dim intFill As Integer
Dim strErrorMsg As String = " Error reading file, try again!"
IO.File.Exists("e:0\references\cities.txt") Then
objReader = IO.File.OpenText("e:0\references\cities.txt")
'OPENS TEXT FILE
If
'READS TEXT FILE
Do While objReader.Peek <> -1
_cityArray(intCount) = Convert.ToString(objReader.ReadLine()) 'assigns 1st element
_cityPopulationArray(intCount) = Convert.ToInt32(objReader.ReadLine()) 'assigns 2nd element
intCount += 1 ' repeat until no more data
Loop
objReader.Close()
'inserts array into combo box
For intFill = 0 To (_cityArray.Length - 1)
Me.cboCities.Items.Add(_cityArray(intFill))
Next
Else
MsgBox(strErrorMsg, , "Error")
Me.Close()
End If
'ACCESSING
Dim popIncrease(9) As Single '= _cityPopulationArray(intCount)
Dim citySelection(9) As String '= _cityArray(intCount)
End Sub
Private Sub mnuDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDisplay.Click
'displays new window form for list of largest cities
Dim largestCityList As New frmDisplayCity
'display 2nd form window until closed b4 access to 1st window code
Me.Hide()
largestCityList.ShowDialog()
End Sub
Private Sub mnuClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClear.Click
cboCities.SelectedItem = (0)
End Sub
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
Me.Close()
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim citySelectedItem As Integer
Dim intSelectedItemId As Integer
Dim populationIncrease As Single
Dim popIncrease As Decimal
If Me.cboCities.SelectedIndex = 0 Then
populationIncrease = CSng(popIncrease * 0.3)
End If
lstDisplay.Text = populationIncrease.ToString
End Sub
End Class