Hello everyone, here i am again, asking for help .... please bear with me, I am a newbie of VB .... ahmmmm I just wanna ask if what codes is appropriate in holding the value that the user choose or select after clicking the ENTER Button? the scenario is this: I have 5 buttons, namely: A1, A2, A3, A4, A5 and when a user Select any of the buttons, a MsgBox("The Seat number you select is" _____, "Do You want to Continue", vbYesNo + vbQuestion) will appear after Clicking the Enter Button .... the codes i have done so far is:

Private Sub ENTER_Click(sender As Object, e As EventArgs) Handles ENTER.Click
        con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\laptop\Documents\Trial\Sample.accdb")
        con.Open()
        Dim Buttons As New List(Of Button) From {A1, A2, A3, A4, A5}
        For Each btn As Button In Buttons
            If btn.BackColor = Color.Red Then
                cmd.CommandType = CommandType.Text
                cmd.CommandText = "Update RegularPassenger Set Filled=@StFld Where SeatNo=@StNo"
                cmd.Parameters.Add("@StFld", OleDb.OleDbType.VarChar, 10).Value = "RESERVED"
                cmd.Parameters("@StFld").Direction = ParameterDirection.Input
                cmd.Parameters.Add("@StNo", OleDb.OleDbType.VarChar, 10).Value = btn.Name
                cmd.Connection = con
                cmd.ExecuteNonQuery()
                cmd.Parameters.Clear()
                cmd.Dispose()
                Exit For
            End If
        Next
        con.Close()
        con.Dispose()
        If MsgBox("You Select the Seat Number "            "Do You want to continue?", vbYesNo + vbQuestion, _
               "Philippine Sweet Airline") = vbYes Then
            Me.Close()
        End If
    End Sub

    Private Sub A3_Click(sender As Object, e As EventArgs) Handles A1.Click, A2.Click, A3.Click, A4.Click, A5.Click

        Dim BSender As Button = CType(sender, Control)
        If BSender.BackColor = Color.Red Then
            BSender.BackColor = Color.WhiteSmoke
            Return
        End If
        Dim Buttons As New List(Of Button) From {A1, A2, A3, A4, A5} 'Buttons you want to check
        Dim BError As Boolean = False
        For i = 0 To Buttons.Count - 1
            If Buttons(i).BackColor = Color.Red Then
                BError = True
            End If
        Next
        If BError = False Then
            sender.BackColor = Color.Red
        Else
            MsgBox("You can only select one seat for every Process", vbInformation, _
                   "Philippine Sweet Airline")
        End If
    End Sub

What code is appropriate for the Condition? I will really appreciate any HELP ..... Thank You so MUCH!!!:'(

Recommended Answers

All 3 Replies

Simply apply MessageBox.
I am posting here the new one for your ENTER Button Click Event.

Private Sub ENTER_Click(sender As System.Object, e As System.EventArgs) Handles ENTER.Click
        Dim btnNm As String = ""

        con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\laptop\Documents\Trial\Sample.accdb")
        con.Open()
        Dim Buttons As New List(Of Button) From {A1, A2, A3, A4, A5}
        For Each btn As Button In Buttons
            If btn.BackColor = Color.Red Then

                btnNm = btn.Name

                cmd.CommandType = CommandType.Text
                cmd.CommandText = "Update RegularPassenger Set Filled=@StFld Where SeatNo=@StNo"
                cmd.Parameters.Add("@StFld", OleDb.OleDbType.VarChar, 10).Value = "RESERVED"
                cmd.Parameters("@StFld").Direction = ParameterDirection.Input
                cmd.Parameters.Add("@StNo", OleDb.OleDbType.VarChar, 10).Value = btn.Name
                cmd.Connection = con
                cmd.ExecuteNonQuery()
                cmd.Parameters.Clear()
                cmd.Dispose()
                Exit For

            End If
        Next
        con.Close()
        con.Dispose()

        Dim xStr As String = String.Format("You Select the Seat Number {0}.{1}Do You want to continue?", btnNm, vbCrLf)
        Select Case MessageBox.Show(xStr, "Philippine Sweet Airline", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
            Case Windows.Forms.DialogResult.Yes
                Return
            Case Windows.Forms.DialogResult.No
                Me.Close()
        End Select
    End Sub

This could be help you.

I am trying here to describe how to manage reservation for your reservation projects. How you can Reserve a Seat or Cancel the Reservation.

The code is as follows.
Change the Database Name(with path), Table Name and Fields also as you desire.

'Importing the system references

Imports System
Imports System.Data.OleDb

Public Class Form1
    'Declaration of varibles
    Dim BError As Boolean = False
    Dim NwBtn As New Button


    Dim con As New System.Data.OleDb.OleDbConnection
    Dim cmd As New System.Data.OleDb.OleDbCommand

    Dim CntRw As Integer

    Private Function CheckReservation(ByVal StNo As String) As Boolean
        'Checking the seat No whether reserved or not.

        'Checking Connection is opened or not
        ' If opened Close the Connection.
        If con.State = ConnectionState.Open Then con.Close()


        'Set the ConnectionString and Open it
        con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Philippine Sweet Airline Seats Reservation.accdb")
        con.Open()

        'Preparing the Command Object to retrive the row numbers
        'if the condition is satisfied.
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "Select Count(*) From SeatReserve Where SeatNo=@StNo And Filled=@StFld"
        cmd.Parameters.Add("@StNo", OleDb.OleDbType.VarChar, 10).Value = StNo
        cmd.Parameters.Add("@StFld", OleDb.OleDbType.VarChar, 10).Value = "RESERVED"
        cmd.Connection = con
        CntRw = cmd.ExecuteScalar()
        cmd.Parameters.Clear()
        cmd.Dispose()
        con.Close()
        con.Dispose()

        'If Row No is greater than 0 then pass True else pass false
        Return IIf(CntRw > 0, True, False)

    End Function

    Private Sub CancelReservation(ByVal StNo As String)
        'Cancelling the Reservation

        'Checking Connection is opened or not
        ' If opened Close the Connection.
        If con.State = ConnectionState.Open Then con.Close()


        'Set the ConnectionString and Open it
        con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Philippine Sweet Airline Seats Reservation.accdb")
        con.Open()

        'Preparing the Command Object to cancel the reservation
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "Update SeatReserve Set Filled=@StFld Where SeatNo=@StNo"
        cmd.Parameters.Add("@StFld", OleDb.OleDbType.VarChar, 10).Value = ""
        cmd.Parameters("@StFld").Direction = ParameterDirection.Input
        cmd.Parameters.Add("@StNo", OleDb.OleDbType.VarChar, 10).Value = StNo
        cmd.Connection = con
        cmd.ExecuteNonQuery()
        cmd.Parameters.Clear()
        cmd.Dispose()

        con.Close()
        con.Dispose()



    End Sub

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

        'At form Level check the Buttons for reserved or not
        'If it is Reserved Seat then attach the word "Reserved" in its text
        Dim Buttons As New List(Of Button) From {A3, A4, A5, A6, A7, B3, B4, B5, B6, B7}
        For Each btn As Button In Buttons
            If Me.CheckReservation(btn.Name) Then
                btn.Text &= vbCrLf & "Reserved"
            End If
        Next

        ButtonEnter.Enabled = False

    End Sub

    Private Sub A3_Click(sender As Object, e As EventArgs) Handles A3.Click, A4.Click, A5.Click, A6.Click, A7.Click, B3.Click, B4.Click, B5.Click, B6.Click, B7.Click
        Dim BSender As Button = CType(sender, Control)


        Dim Buttons As New List(Of Button) From {A3, A4, A5, A6, A7, B3, B4, B5, B6, B7} 'Buttons you want to check

        For Each btn As Button In Buttons
            If BError = False Then

                If (btn Is BSender) Then

                    'Checking the seat No reserved or not.
                    'If True then Prompt to Cancel the reservation.
                    If Me.CheckReservation(btn.Name) Then

                        'Prompt to cancel the reservation
                        Dim xstr As String = String.Format("The seat {0} is already reserved.{1}Do you sure to cancel the reservation?{2}If so, Click 'Ok'.", btn.Name, vbCrLf, vbCrLf)
                        Select Case MessageBox.Show(xstr, _
                                                    "Reservation.....", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
                            Case Windows.Forms.DialogResult.OK
                                Me.CancelReservation(btn.Name)
                                ButtonEnter.Enabled = False

                                'Confirm the cancellation
                                MsgBox("Reservation is canceled.")

                                btn.Text = btn.Name
                                Return

                            Case Else

                                Return

                        End Select

                    End If


                    NwBtn = BSender
                    BError = True

                    ButtonEnter.Enabled = True
                    Exit For

                End If

            Else

                If BSender Is NwBtn Then
                    BError = False

                    NwBtn = Nothing
                    ButtonEnter.Enabled = False
                    Exit For

                Else
                    'Prompt if already a button is selected for reservation.
                    MsgBox("You can only select one seat for every Process", vbInformation, _
                      "Philippine Sweet Airline")
                    NwBtn.Focus()
                    Exit For

                End If

            End If
        Next


    End Sub

    Private Sub ButtonEnter_Click(sender As System.Object, e As System.EventArgs) Handles ButtonEnter.Click
        'Checking Connection is opened or not
        ' If opened Close the Connection.
        If con.State = ConnectionState.Open Then con.Close()


        'Set the ConnectionString and Open it
        con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Philippine Sweet Airline Seats Reservation.accdb")
        con.Open()

        'Preparing the Command Object to reserve the seat no
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "Update SeatReserve Set Filled=@StFld Where SeatNo=@StNo"
        cmd.Parameters.Add("@StFld", OleDb.OleDbType.VarChar, 10).Value = "RESERVED"
        cmd.Parameters("@StFld").Direction = ParameterDirection.Input
        cmd.Parameters.Add("@StNo", OleDb.OleDbType.VarChar, 10).Value = NwBtn.Name
        cmd.Connection = con
        cmd.ExecuteNonQuery()
        cmd.Parameters.Clear()
        cmd.Dispose()

        con.Close()
        con.Dispose()




        ButtonEnter.Enabled = False

        'After reservation alter the text of the reserved seat
        NwBtn.Text &= vbCrLf & "Reserved"


        'Prompt the user whether it runs or not
        Dim xStr As String = String.Format("You Select the Seat Number {0}.{1}Do You want to continue?", NwBtn.Name, vbCrLf)
        Select Case MessageBox.Show(xStr, "Philippine Sweet Airline", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
            Case Windows.Forms.DialogResult.Yes
                BError = False
                Return
            Case Windows.Forms.DialogResult.No
                Me.Close()
        End Select
    End Sub



End Class

Hope, it could be ssolve yur probs.

Hello Sir Santanu Das, Thank You so so so much Sir .... I really appreciate your help sir ... The Problem i got of Holding The Values that a User Selected is now solved ... Thank You so so so much Sir Santanu Das .... God Bless ^_^

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.