Hi Everybody,
I have been working on this assignment for quite a long time and now seeking help. I need to create a visual basic application where an organization needs to save each respondent's information (political party and age) to a sequential access file. The application also should calculate and display the number of voters in each political party (Democratic, Republican, and Independent).
Please see below code. When I tried to run, I'm getting the "System.Windows.Forms.ListBox+ObjectCollection" in my text file. Can you please provide me guidance what I'm doing wrong? Many thanks for your help!!!!
[/HIGHLIGHT]
I have been working on this assignment for quite a long time and now seeking help. I need to create a visual basic application where an organization needs to save each respondent's information (political party and age) to a sequential access file. The application also should calculate and display the number of voters in each political party (Democratic, Republican, and Independent).
Please see below code. When I tried to run, I'm getting the "System.Windows.Forms.ListBox+ObjectCollection" in my text file. Can you please provide me guidance what I'm doing wrong? Many thanks for your help!!!!
vb.net Code:
[HIGHLIGHT]Public Class frmMain Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() End Sub Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' fill the list box with values lstParty.Items.Add("Democrats") lstParty.Items.Add("Republicans") lstParty.Items.Add("Independents") End Sub Private Sub txtAge_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAge.KeyPress ' allows the text box to accept only numbers, the period, and the Backspace key If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then ' cancel the key e.Handled = True End If End Sub Private Sub btnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite.Click ' writes a political party to a sequential access file ' declare a StreamWriter variable Dim outFile As IO.StreamWriter Dim intnum As Integer ' open the file for append ' write the name on a separate line in the file outFile.WriteLine(lstParty.Items) ' Loop through the items in the listbox For intnum = 0 To lstParty.Items.Count - 1 ' write the name on a separate line in the file outFile.WriteLine(lstParty.Items) Next ' close the file outFile.Close() ' set focus txtAge.Focus() End Sub Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click ' reads political party from a sequential access file ' and displays them in the interface ' declare variables Dim inFile As IO.StreamReader ' determine whether the file exists 'open the file for input inFile.Close() Else MessageBox.Show("Can't find the file", "Political Party", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End Sub Private Sub txtAge_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtAge.Enter txtAge.SelectAll() End Sub End Class