Create+New+Class+(VB)

Public Class Person Public strFirstName As String Public strLastName As String Public strStreetAddress As String Public strCity As String Public strPostalCode As String Public strEmail As String Public strPhone As String Public strCell As String
 * This is the beginning of a new class. It specifies all of the components that the class will possess. In this case, the new class is a class for a "Person". Here, the person will have characteristics/properties (such as a first name and a phone number!).**

Public Sub ShowAll MsgBox(strFirstName & "," & strLastName & "," & strStreetAddress & "," & strCity & "," & strPostalCode & "," & strEmail & "," & strPhone & "," & strCell & ",")

End Sub

End Class

P ublic Class Form1 Dim lstPeople As New List(Of Person) Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click Dim objPerson As New Person

objPerson.strFirstName = txtFirstName.Text objPerson.strLastName = txtLastName.Text objPerson.strStreetAddress = txtStreet.Text objPerson.strCity = txtCity.Text objPerson.strPostalCode = txtPostalCode.Text objPerson.strEmail = txtEmail.Text objPerson.strPhone = txtPhoneNumber.Text objPerson.strCell = txtCell.Text
 * Here we assign values to each of the properties of the person object, such as first name and phone number.**

lstPeople.Add(objPerson) cbList.Items.Add(txtFirstName.Text)
 * Adding the object person to the list of people.**

txtFirstName.Clear txtCity.Clear txtCell.Clear txtEmail.Clear txtLastName.Clear txtPhoneNumber.Clear txtPostalCode.Clear txtStreet.Clear

Dim sWrite As IO.StreamWriter = New IO.StreamWriter("G:\Addresses.doc", True) sWrite.WriteLine("First Name: " & objPerson.strFirstName) sWrite.WriteLine("Last Name: " & objPerson.strLastName) sWrite.WriteLine("Street Address: " & objPerson.strStreetAddress) sWrite.WriteLine("City: " & objPerson.strCity) sWrite.WriteLine("Postal Code: " & objPerson.strPostalCode) sWrite.WriteLine("Email: " & objPerson.strEmail) sWrite.WriteLine("Phone Number: " & objPerson.strPhone) sWrite.WriteLine("Cell Number: " & objPerson.strCell)
 * Writing the info to a text file.**

sWrite.Close MsgBox("Entry Stored!!") End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click For Each Person In lstPeople Person.ShowAll Next End Sub
 * Showing the list.**

Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click For Each Person In lstPeople If Person.strFirstName = cbList.SelectedItem Then lstPeople.Remove(Person) Exit For End If Next
 * Deleting components from the list.**

End Sub

Private Sub cmdShowAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShowAll.Click Dim sRead As IO.StreamReader = New IO.StreamReader("G:\Addresses.doc") Dim strAllFile As String = ""

Do While sRead.Peek <> -1 strAllFile = strAllFile & sRead.ReadLine & vbNewLine Loop

MsgBox(strAllFile) sRead.Close End Sub End Class