Here is my code for programming a program that reads from a file called RESORT.TXT
Containing the text:
Barb Allen
604 777 1234
2008/12/01
2
3
1
3
D
Eric Meyer
604 527 9123
2008/12/18
4
3
2
1
B
Victor Choong
604 525 3123
2008/11/18
2
2
1
2
N
Gilbert Tsui
604 521 1123
2008/12/28
5
1
0
4
D
Eric Meyer
604 527 3123
2009/01/08
1
2
1
3
D
Here is my source code::
CODE
Public Class frmResort
Structure resortStructure
Dim customerName As String
Dim phoneNumber As String
Dim checkInDate As Date
Dim daysToStay As Integer
Dim numberOfAdults As Integer
Dim numberOfKids As Integer
Dim mealPlan As Char
Dim memberLetter As String
End Structure
Dim guestlist(4) As resortStructure
Private Sub frmResort_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim sr As IO.StreamReader = IO.File.OpenText("RESORT.TXT")
For i As Integer = 0 To 4
guestlist(i).customerName = sr.ReadLine
guestlist(i).phoneNumber = sr.ReadLine
guestlist(i).checkInDate = CDate(sr.ReadLine)
guestlist(i).daysToStay = CInt(sr.ReadLine)
guestlist(i).numberOfAdults = CInt(sr.ReadLine)
guestlist(i).numberOfKids = CInt(sr.ReadLine)
guestlist(i).mealPlan = CChar(sr.ReadLine)
guestlist(i).memberLetter = sr.ReadLine
Next
sr.Close()
For i As Integer = 0 To 4
cmbGuestSearch.Items.Add(guestlist(i).customerName & " " & guestlist(i).phoneNumber)
Next
End Sub
Sub ProcessData()
lstInvoice.Items.Clear()
End Sub
Sub ProcessInvoice()
Dim fmtStr As String = "{0, -4} {1, 10}"
For i As Integer = 0 To 4
lstInvoice.Items.Add(guestlist(i).customerName)
lstInvoice.Items.Add(guestlist(i).phoneNumber)
lstInvoice.Items.Add(guestlist(i).checkInDate)
lstInvoice.Items.Add(guestlist(i).daysToStay)
lstInvoice.Items.Add(guestlist(i).numberOfAdults)
lstInvoice.Items.Add(guestlist(i).numberOfKids)
lstInvoice.Items.Add(guestlist(i).mealPlan)
lstInvoice.Items.Add(guestlist(i).memberLetter)
Next
End Sub
Private Sub btnPrepareInvoice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrepareInvoice.Click
ProcessData()
ProcessInvoice()
End Sub
Private Sub cmbGuestSearch_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbGuestSearch.SelectedIndexChanged
For i As Integer = 0 To 4
txtGuestName.Text = guestlist(i).customerName
Next
End Sub
End Class
I have also included a screenshot of the program.

I have a problem when I use the SelectedIndexChanged to get the index using: txtGuestName.Text = guestlist(i).customerName using the for loop.
I am so puzzled because everytime I change the index, it shows the same thing. For example, when I click Victor Choong, it still displays Eric Meyers.
Can anyone help here? Thanks.
- Nathe
This post has been edited by antitru5t: 1 Jul, 2009 - 09:58 AM