Thanks for the quick responce
I'll try to clarify with code.
I open the file and read in a txt file with the following comma delimited data:
Joe Green,1045 Green Street,Las Vegas Nevada 87465,485-876-3344
Diana Estep,5968 Howard Drive,Houston Texas 23498,298-989-2354
Roberta Rosenberger,876 West Jefferson,Maderia Beach Florida 48765,576-349-8738
Randy Raney,198 Jackson Drive,St Louis Missouri 34875,314-564-9923
VB Code:
Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
Dim objStreamReader As System.IO.StreamReader
Dim strLineofData As String
Dim strFields(1) As String
Dim intCtr As Integer
Dim chrDelimiter() As Char = {System.Convert.ToChar(",")}
With dlgOpenFileDialog
.Filter = "text(*.txt) |*.txt"
.FileName = "Sales.txt"
.InitialDirectory = Application.StartupPath & ("\..\")
.ShowDialog()
End With
objStreamReader = System.IO.File.OpenText(dlgOpenFileDialog.FileName)
Do While objStreamReader.Peek <> -1
strLineofData = objStreamReader.ReadLine
strFields = strLineofData.Split(chrDelimiter)
lstAddress.Items.Add(strFields(0))
mstrAddressArray(intCtr) = strFields(1)
mstrCityArray(intCtr) = strFields(2)
mstrPhoneArray(intCtr) = strFields(3)
intCtr += 1
Loop
objStreamReader.Close()
mnuShow.Enabled = True
mnuModify.Enabled = True
End Sub
A list box is loaded with name of the contacts. When I highlite a name and click Show it displays the Contact Details on another form.
VB Code:
Private Sub mnuShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuShow.Click
Dim objDetailsForm As New frmDetails
Dim strAddress, strCity, strPhone As String
If lstAddress.SelectedIndex = -1 Then
MessageBox.Show("No entry was selected to view", "View Error", MessageBoxButtons.OK)
End If
'Exit Sub
strAddress = mstrAddressArray(lstAddress.SelectedIndex)
strCity = mstrCityArray(lstAddress.SelectedIndex)
strPhone = mstrPhoneArray(lstAddress.SelectedIndex)
objDetailsForm.lblDetails.Text &= strAddress & ControlChars.NewLine
objDetailsForm.lblDetails.Text &= strCity & ControlChars.NewLine
objDetailsForm.lblDetails.Text &= strPhone & ControlChars.NewLine
objDetailsForm.Show()
End Sub
Now when I want to add a New Contact to the list.
VB Code:
Private Sub mnuAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAdd.Click
Dim objNewContactForm As New frmNewContact
mstrNewContact = InputBox("Enter the name of the new contact", "Add Contact")
lstAddress.Items.Add(mstrNewContact)
objNewContactForm.lblContact.Text = "Contact information for " & mstrNewContact
objNewContactForm.Show()
End Sub
Which open an inputbox and then a third form to add the New Contact details.
VB Code:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
ReDim Preserve mstrAddressArray(UBound(mstrAddressArray) + 1)
mstrAddressArray(UBound(mstrAddressArray) - 1) = txtAddress.Text
ReDim Preserve mstrCityArray(UBound(mstrCityArray) + 1)
mstrCityArray(UBound(mstrCityArray) - 1) = txtCityStateZip.Text
ReDim Preserve mstrPhoneArray(UBound(mstrPhoneArray) + 1)
mstrPhoneArray(UBound(mstrPhoneArray) - 1) = txtPhoneNumber.Text
'Me.Close()
End Sub
I need to add new names and details for the contact to the arrays, and also be able to delete names from the listbox and array and then sort the index (which I havn't started yet, just trying to get the names and details to add to the array first)
My first 8 project for this .NET class went by with no problems. It is these damn arrays where I am getting stuck.
This is project 9 of 10 (almost finished) :D