Hey all. I am trying to make a program that consists of two list boxes. The first list box contains the names of several employees of a given company, and the second is to display the name, department, ID number, and phone number of the person when the name is double clicked in the first list box. The file I have been given to carry this out with reads as follows.

[TEX]Jill Anders, MIS, 14759, 555-1279
Henry Cosworth, Sales, 45878, 555-5478
Hans Denton, Marketing, 55562, 555-1115
Susan Fowler, Accounting, 70078, 555-8897
Geri Garrison, Research, 72145, 555-8845
Jean Honton, Administration, 56411, 555-6565
Kevin Lang, Clerical, 39947, 555-1478
Amber Wu, Research, 65432, 555-1254
Joe Hazelton, Accounting, 87321, 555-0032
Sun Chong, MIS, 98211, 555-0054
Julio Garcia, Sales, 89543, 555-9812
Stan SchingIman, Research, 54123, 555-0199
Jared Simmons, MIS, 87231, 555-0112
Bilal Hadad, Accounting, 89321, 555-0155
Debra Breamer, MIS, 32098, 555-0049
Myra Blake, Administration, 98001, 555-0011
Carl Fulton, Clerical, 34009, 555-0095
Gail Bradley, MIS, 87112, 555-0099
Stella Williams, Sales, 76006, 555-0780
Lindsay Schafer, Consulting, 87012, 555-0008
Gary Caldwell, Sales, 13213, 555-0032
Glen Carlson, Sales, 67123, 555-0167
Sean McDonald, MIS, 45321, 555-0187
Kavi Chander, Sales, 34211, 555-0010
Luis Torres, Marketing, 34441, 555-0013
Marta Winslow, Administration, 78781, 555-0122
Tran Truc, Research, 90902, 555-0935
Amy Jakebowski, MIS, 88901, 555-0132
Ambor Chang, Research, 89892, 555-8999
James Wei, MIS, 87651, 555-1456[/TEX]

I have no idea what I am doing. I know that I have to use the system imports streamwriter and streamreader, but I really am lost as to how. I don't even know where to begin really. Could somebody please help me out and explain this to me?

Recommended Answers

All 3 Replies

Please Look at this.

then Look at this.

Read them and see what you figure out.

Ask Questions and present your theories.

Peace.

Will do. Thanks.

This is what I came up with. Is there any way I can get rid of the extraneous spaces from the .txt file which make the output columns uneven? Is there anything else you would have done differently? If so, please explain.

Imports System.IO
Public Class Form1
    Dim Database(0 To 29, 0 To 3) As String
    Public Sub StoreData()

        Dim Employee() As String
        Dim sr As StreamReader = File.OpenText("EmployeeData.txt")

        For i = 0 To 29
            Employee = Split(sr.ReadLine, ",")
            Database(i, 0) = Employee(0)
            Database(i, 1) = Employee(1)
            Database(i, 2) = Employee(2)
            Database(i, 3) = Employee(3)
        Next
    End Sub

    Private Sub ListBoxEmployee_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBoxEmployee.MouseDoubleClick
        Dim fmtstr As String = "{0, -20}{1, -20}{2, -20}{3, -20}"
        Dim i As Integer
        Call StoreData()
        i = ListBoxEmployee.SelectedIndex
        ListBoxDisplay.Items.Clear()
        ListBoxDisplay.Items.Add(String.Format(fmtstr, "Employee Name", "Department", "ID Number", "Telephone"))
        ListBoxDisplay.Items.Add(String.Format(fmtstr, "", "", "", ""))
        ListBoxDisplay.Items.Add(String.Format(fmtstr, "", "", "", ""))
        ListBoxDisplay.Items.Add(String.Format(fmtstr, Database(i, 0), Database(i, 1), Database(i, 2), Database(i, 3)))
    End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.