VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,358 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,901 people online right now. Registration is fast and FREE... Join Now!




SelectIndexChanged Problem

 

SelectIndexChanged Problem

antitru5t

2 Jul, 2009 - 11:36 AM
Post #1

New D.I.C Head
*

Joined: 19 Jan, 2009
Posts: 27


My Contributions
Hi Visual Basic people,

I have problems figuring out how to seperate a single person to display on my listbox.

I am currently working on an assignment called "Douglas Resort Reservation" and we are supposed to select a query from the combo box Guest Search. For example, when I select Barb Allen, I get the info to display properly, which is good. But, I still have a problem.

IPB Image


When I try to click my button 'Prepare Invoice', I want Barb Allen's info to be displayed in my listbox 'Invoice'. But, now I don't have that complete. I have a whole list of items generated when I load my whole thing from my Form Load event from the textfile RESORT.TXT. I get a whole list of items instead of individualized items.

My question for you is: "How can I get just ONE name and person's information to show up?" when I press the button 'Prepare Invoice'.

and display information like this:

Barb Allen 604 777 1234
# of Adults 3
# of kids 1
Check In 2008-12-01
Check Out 2008-12-03
Meal Plan Breakfast and Dinner
Membership Douglas Club

Here's my source code if you want to view it; this might help. wink2.gif

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
        Array.Sort(guestlist, New Comparer)

    End Sub

    Sub ClearData()
        lstInvoice.Items.Clear()
    End Sub

    Sub ProcessInvoice()
        ClearData()
        For i As Integer = 0 To 4
            lstInvoice.Items.Add(guestlist(i).customerName & "       " & guestlist(i).phoneNumber)
            lstInvoice.Items.Add("# of Adults" & "      " & guestlist(i).numberOfAdults)
            lstInvoice.Items.Add("# of kids" & "        " & guestlist(i).numberOfKids)
            lstInvoice.Items.Add("Check In" & "         " & guestlist(i).checkInDate.ToString("yyyy-MM-dd"))
            lstInvoice.Items.Add("Check Out" & "        " & guestlist(i).checkInDate.AddDays(guestlist(i).daysToStay).ToString("yyyy-MM-dd"))
            If guestlist(i).mealPlan = "1" Then
                lstInvoice.Items.Add("Meal Plan" & "        " & "Breakfast")
            ElseIf guestlist(i).mealPlan = "2" Then
                lstInvoice.Items.Add("Meal Plan" & "        " & "Dinner")
            ElseIf guestlist(i).mealPlan = "3" Then
                lstInvoice.Items.Add("Meal Plan" & "        " & "Breakfast and Dinner")
            ElseIf guestlist(i).mealPlan = "4" Then
                lstInvoice.Items.Add("Meal Plan" & "        " & "No Meal Plan Ordered")
            End If

            If guestlist(i).memberLetter = "B" Then
                lstInvoice.Items.Add("Membership" & "       " & "BCAA")
            ElseIf guestlist(i).memberLetter = "D" Then
                lstInvoice.Items.Add("Membership" & "       " & "Douglas Club")
            ElseIf guestlist(i).memberLetter = "N" Then
                lstInvoice.Items.Add("Membership" & "        " & "N/A")
            End If
        Next
    End Sub

    Private Sub btnPrepareInvoice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrepareInvoice.Click
        ClearData()
        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(cmbGuestSearch.SelectedIndex).customerName
            txtCheckInDate.Text = guestlist(cmbGuestSearch.SelectedIndex).checkInDate.ToString("yyyy-MM-dd")
            txtNoOfAdults.Text = guestlist(cmbGuestSearch.SelectedIndex).numberOfAdults.ToString()
            txtNoOfKids.Text = guestlist(cmbGuestSearch.SelectedIndex).numberOfKids.ToString()
            txtGuestPhone.Text = guestlist(cmbGuestSearch.SelectedIndex).phoneNumber
            txtNoDaysToStay.Text = guestlist(cmbGuestSearch.SelectedIndex).daysToStay.ToString()
            If guestlist(cmbGuestSearch.SelectedIndex).mealPlan = "1" Then
                chkBreakfast.Checked = True
            ElseIf guestlist(cmbGuestSearch.SelectedIndex).mealPlan = "2" Then
                chkDinner.Checked = True
            ElseIf guestlist(cmbGuestSearch.SelectedIndex).mealPlan = "3" Then
                chkDinner.Checked = True
                chkBreakfast.Checked = True
            ElseIf guestlist(cmbGuestSearch.SelectedIndex).mealPlan = "4" Then
                chkBreakfast.Checked = False
                chkDinner.Checked = False
            End If

            If guestlist(cmbGuestSearch.SelectedIndex).memberLetter = "B" Then
                radBCAA.Checked = True
            ElseIf guestlist(cmbGuestSearch.SelectedIndex).memberLetter = "D" Then
                radDouglasClub.Checked = True
            ElseIf guestlist(cmbGuestSearch.SelectedIndex).memberLetter = "N" Then
                radNA.Checked = True
            End If

        Next
    End Sub
End Class

Public Class comparer
    Implements IComparer(Of frmResort.resortStructure)

    Public Function Compare(ByVal x As frmResort.resortStructure, ByVal y As frmResort.resortStructure) As Integer Implements System.Collections.Generic.IComparer(Of frmResort.resortStructure).Compare
        Return x.customerName.CompareTo(y.customerName)
    End Function

End Class


I'm desperate for help,

- Nathe






User is offlineProfile CardPM
+Quote Post


bflosabre91

RE: SelectIndexChanged Problem

2 Jul, 2009 - 11:52 AM
Post #2

go sabres
****

Joined: 22 Feb, 2008
Posts: 658



Thanked: 12 times
My Contributions
your still looping through 0 to 4 in your for loop. that will never work no matter what. this sounds like a good application to create a new class. go into the Solution Explorer and add new item. Click the class template, and name it whatever you want. Ill just use the default Class1.vb. that class will look like this, but add the fields you need

CODE

Public Class Class1
    Private _Field1As String

    Public Sub New(ByVal Field1 As String)
        _Field1= Field1
    End Sub

    Public Property Field1() As String
        Get
            Return _Field1
        End Get
        Set(ByVal value As String)
            _Field1= value
        End Set
    End Property


then to fill that bad boy you need to create a new instance of it, and then fill it with something.ill just hard code default values
CODE

Private ClassObj as new Dictionary(Of Int16,Class1)
ClassObj(0) = New Class1("TextValue1")


something along those lines but you need to fill in all the data you need. i hope this might point you in the right direction.

This post has been edited by bflosabre91: 2 Jul, 2009 - 11:52 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 07:38PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month