Someone please help with VB.net

ice

New member
I need help with this airline seating program. All I need it to do for now is take the data from the second form (radio box), put it in the text box on the first form, and at the same time, have it update the listbox on that first form. Here is a screen of what the program looks like:

http://i21.photobucket.com/albums/b251/jfindon/program-1.jpg

And here is my code for the first form. I just can't get the listbox to update, I can get the textboxes filled with the data just fine.

Code:
 Dim secondForm As New Form2

    Private Sub lstSeats_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstSeats.SelectedIndexChanged



        Dim row As String = CStr(lstSeats.SelectedItem)



        txtA.Text = row.Chars(0)
        txtB.Text = row.Chars(1)
        txtC.Text = row.Chars(2)
        txtD.Text = row.Chars(4)
        txtE.Text = row.Chars(5)
        txtF.Text = row.Chars(6)

        txtRow.Text = lstSeats.SelectedIndex + 1





    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With lstSeats.Items


            For rowNumber As Integer = 1 To 15
                .Add("... ...")

            Next rowNumber

        End With

        With lstStats.Items
            .Add("Seats filled:")
            .Add("Windows avail:")
            .Add("Regular meals:")
            .Add("LowCal meals:")
            .Add("Veget meal:")
        End With


    End Sub

    Private Sub txtA_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtA.Click

        Dim row As String = CStr(lstSeats.SelectedItem)

        secondForm.ShowDialog()

        txtA.Text = secondForm.status = row

        lstSeats.Items(lstSeats.SelectedIndex) = txtA.Text


    End Sub

    Private Sub txtB_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtB.Click
        secondForm.ShowDialog()

        txtB.Text = secondForm.status
    End Sub

    Private Sub txtC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtC.Click
        secondForm.ShowDialog()
        txtC.Text = secondForm.status

    End Sub

    Private Sub txtD_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtD.Click
        secondForm.ShowDialog()
        txtD.Text = secondForm.status
    End Sub

    Private Sub txtE_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtE.Click
        secondForm.ShowDialog()
        txtE.Text = secondForm.status
    End Sub

    Private Sub txtF_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtF.Click
        secondForm.ShowDialog()
        txtF.Text = secondForm.status

    End Sub

    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        lstStats.Visible = True
    End Sub
 
I am not sure why you need to make a "secondform" You could just put all your option buttons in a GroupBox on the same form instead. Right now when you call ShowDialog on secondform your code is going to stop executing in the original form until secondform is closed. So the first time you click a TextBox you are done. You could call Show instead of ShowDialog in each click event to get around the problem. But, I think the 2 form approach is very kludgy to begin with and should be dumped.

Don't they teach you to build objects in this class? You really should have code that uses more objects. This exercise is a perfect case to use OO programming. Here's some examples (Not real code):

Code:
For Each Row In Airplane.Rows
  lstSeats.Item.Add Row
Next


Public Class Airplane

  Public ReadOnly Property Rows as List(Of Row)
  ...
  End Property

End Class

Public Class Row

  Public ReadOnly Property Seats as List(Of Seat)
  ...
  End Property

End Class

Public Class Seat

  Public Property IsOpen As Boolean
  ...
  End Property

  Public Enum MealTypes
      Regular = 0
      Lo_Cal = 1
      Veggie = 2
  End Enum

  Public Property MealSelection as MealTypes
  ....
  End Sub

End Class

And, when you really get good you could start doing fun things like:

Code:
Public Class Boeing747
  Inherits Airplane

  ...
End Class
 
Eh, the book wants me to use the two form way. I'll take a look at your suggestions though, maybe I can figure something else out.
 
Eh, the book wants me to use the two form way. I'll take a look at your suggestions though, maybe I can figure something else out.


If you do decide to use more objects, try overriding the ToString function on any object to get whatever you want to show up in any user control you may add them to. Every object in .NET derives from the base Class" "Object". The ToString function on the Object class is called by user controls to display the contents of any object you add to it. For Example: Your Row.ToString function could return the special string of characters you have defined for each seat assignment.
 
I'm probably just being dim here but if the seats are just a list, how is it specifying a single seat (as opposed to a row) to assign a meal choice to?

Seems like you'd need more mouse pointer detection and string handling if you want to set it on an individual seat basis.

Personally, I'd feel dirty writing this without more OO.
 
I'm probably just being dim here but if the seats are just a list, how is it specifying a single seat (as opposed to a row) to assign a meal choice to?

Code:
Dim SelectedRow as Row = Airplane.Rows.Item(RowSelected)
Dim SelectedSeat as Seat = SelectedRow.Seats.Item(SeatSelected)
SelectedSeat.MealSelection = MySelection

Note: You should add some bounds checking to this code.
 
Back
Top