Hey guys, I have an application that will display the last names, first names, and the first and last name in a listbox. Can anybody debug my code? It always crashes everytime I click the buttons.
Code:Private names(4) As PersonName Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' fills array with data names(0).first = "Mary" names(0).last = "Jones" names(1).first = "Susan" names(1).last = "Washington" names(2).first = "Carol" names(2).last = "O'Brien" names(3).first = "Jacob" names(3).last = "Harper" names(4).first = "Sue" names(4).last = "Chen" End Sub Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click Me.Close() End Sub Private Sub lastButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lastButton.Click ' displays the last names in a list box ' clear then list box, then display the last names namesListBox.Items.Clear() For row As Integer = 1 To names.Length namesListBox.Items.Add(names(row).last) Next row End Sub Private Sub firstButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles firstButton.Click ' displays the first names in a list box ' clear the list box, then display the first names namesListBox.Items.Clear() For row As Integer = 1 To names.Length namesListBox.Items.Add(names(row).first) Next row End Sub Private Sub fullButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles fullButton.Click ' displays the first and last names in a list box ' clear the list box, then display the first and last names namesListBox.Items.Clear() For row As Integer = 1 To names.Length namesListBox.Items.Add(names(row).first _ & " " & names(row).last) Next row End Sub




Reply With Quote