Hello,
My name is Josh I am in college and I am taking Intermediate VB.Net 2008 and I have been doing ok until now. I have been working on this problem for 2 weeks and still can not get it to do what it is suppose to do and it was suppose to be turned in last week. I do have a way to make it work but it doesn`t follow the guidelines and I would really like to learn what I am doing wrong here. So if anyone could help me it would be greatly appreciated it.
Here is the problem. I have a text file (MEMBERPHONES.TXT) the names and phone numbers from this text file should be read into an array of structures, and the names should be displayed in a list box when the form is loaded. There is a lot more instructions for this program that I already have figured out but this part has me stumped. Here is what I have so far PLEASE HELP and thank you in advance for looking at it.
Structure phone
Dim name As String
Dim phoneNum As Integer
End Structure
Dim phone1() As phone
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sw As IO.StreamWriter = IO.File.CreateText("MEMBERPHONES.TXT")
sw.WriteLine("Langley, Judy")
sw.WriteLine("321-1111")
sw.WriteLine("Morgan,Fred")
sw.WriteLine("222-2222")
sw.WriteLine("Nixon, Mike")
sw.WriteLine("333-3333")
sw.WriteLine("Norton, Herbert")
sw.WriteLine("444-4444")
sw.WriteLine("Preiss, Carol")
sw.WriteLine("555-5555")
sw.WriteLine("Ree, Alice")
sw.WriteLine("666-6666")
sw.WriteLine("Sanchez, Carlos")
sw.WriteLine("777-7777")
sw.WriteLine("Smith, John")
sw.WriteLine("888-8888")
sw.Close()
Dim numRecords As Integer
numRecords = NumberOfRecords("MEMBERPHONES.TXT")
Dim sr As IO.StreamReader = IO.File.OpenText("MEMBERPHONES.TXT")
For index As Integer = 0 To numRecords - 1
phone1(index).name = sr.ReadLine
phone1(index).phoneNum = CInt(sr.ReadLine)
Next
sr.Close()
Do While (sr.Peek <> -1)
Dim i As Integer = 0
ListBox1.Items.Add(phone1(i).name)
i += 1
Loop
End Sub
Function NumberOfRecords(ByVal MEMBERPHONES As String) As Integer
Dim name As String
Dim phoneNum As Integer
Dim n As Integer = 0
Dim sr As IO.StreamReader = IO.File.OpenText("MEMBERPHONES.TXT")
Do While (sr.Peek <> -1)
name = sr.ReadLine
phoneNum = CInt(sr.ReadLine)
n += 1
Loop
sr.Close()
Return n
End Function
End Class
Thanks again,
Josh