Translate To Preferred Language

Search Obioku's Thoughts

Please Read Today's Featured Post

Things I Would Like To Happen Soon

For all those who believe in speaking ideas into existence and prayer in the universe will return to a person.  I simply want to write a lis...

Template for Application to Select a Vacation in Visual Basic (some bugs may occur)

Option Strict On

Public Class frmTours

    'Class Variables
    Private intHours As Integer
    Private decTotalCost As Decimal
    Private strActivity As String

    Private Sub cbLocation_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbLocation.SelectedIndexChanged
        'Change list box collection to be specific to combobox choice
        Dim intChoice = cbLocation.SelectedIndex
        lstTours.Items.Clear()
        Select Case intChoice
            Case 0
                Aruba()
            Case 1
                Jamaica()
            Case 2
                KeyWest()
        End Select

        'Show textbox, listbox and buttons
        lblParty.Visible = True
        tbAmount.Visible = True
        lstTours.Visible = True
        btnClear.Visible = True
        btnSelection.Visible = True

        'Place user focus on textbox
        tbAmount.Focus()

    End Sub

    Private Sub frmTours_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'Set timer for splash screen
        Threading.Thread.Sleep(2000)
    End Sub

    Private Sub Aruba()
        'Listbox displays options for Aruba tour location
        Dim strDeepSea As String = "Deep Sea Fishing"
        Dim strKayak As String = "Kayaking"
        Dim strScuba As String = "Scuba Diving"
        Dim strSnorkel As String = "Snorkeling"

        'Add strings to listbox
        lstTours.Items.Add(strDeepSea)
        lstTours.Items.Add(strKayak)
        lstTours.Items.Add(strScuba)
        lstTours.Items.Add(strSnorkel)
    End Sub

    Private Sub Jamaica()
        'Listbox display options for Jamaica tour location
        Dim strParasailing As String = "Parasailing"
        Dim strJetSki As String = "Jetskiing"
        Dim strSnorkel As String = "Snorkeling"

        'Add strings to listbox
        lstTours.Items.Add(strJetSki)
        lstTours.Items.Add(strParasailing)
        lstTours.Items.Add(strSnorkel)
    End Sub

    Private Sub KeyWest()
        'Listbox displays options for KeyWest tour location
        Dim strCruise As String = "Moonlit Cruise"
        Dim strSwim As String = "Swim Lessons"
        Dim strSnorkel As String = "Snorkeling"

        'Add strings to listbox
        lstTours.Items.Add(strCruise)
        lstTours.Items.Add(strSnorkel)
        lstTours.Items.Add(strSwim)
    End Sub

    Private Sub btnSelection_Click(sender As Object, e As EventArgs) Handles btnSelection.Click

        'Declare variables
        Dim intParty As Integer
        Dim blnValid As Boolean = False
        Dim blnSelected As Boolean = False
        Dim intTour As Integer
        Dim strTour As String
        Dim intIsland As Integer
        Dim intLength As Integer
        Dim decTotal As Decimal

        'Create function to validate data
        blnValid = ValidateParty()
        intTour = ValidateTour(blnSelected, strTour)

        'if both variables are true, accept user entry
        If blnSelected And blnValid Then
            intParty = Convert.ToInt32(tbAmount.Text)

            'Use function specific to user selection
            intIsland = cbLocation.SelectedIndex
            Select Case intIsland
                Case 0
                    decTotal = ArubaCost(intTour, intParty, intLength)
                Case 1
                    decTotal = JamaicaCost(intTour, intParty, intLength)
                Case 2
                    decTotal = KeyWestCost(intTour, intParty, intLength)
            End Select

            decTotalCost += decTotal
            intHours += intLength
            strActivity = cbLocation.Text & " Tour " & strTour

            'Display user selection
            lblType.Text = strActivity.ToString()
            lblType.Visible = True
            lblCost.Text = "Cost " & decTotal.ToString("C")
            lblCost.Visible = True
            lblDuration.Text = "Tour is scheduled for " & intLength.ToString("N") & " hours"
            lblDuration.Visible = True

        End If

    End Sub

    Private Function ValidateParty() As Boolean

        'Declare Variables
        Dim intParty As Integer
        Dim blnValid As Boolean = False

        'Create try-catch block for user entry of party amount
        Try
            intParty = Convert.ToInt32(tbAmount.Text)

            If intParty > 0 And intParty < 100 Then
                blnValid = True
            Else
                MsgBox("Please enter a number between 1 and 99 for your party", , "Invalid Number Entry")
                tbAmount.Focus()
                tbAmount.Clear()
            End If
        Catch ex As FormatException
            MsgBox("Please enter a number between 1 and 99 for your party", , "Invalid Number Entry")
            tbAmount.Focus()
            tbAmount.Clear()
        Catch ex As OverflowException
            MsgBox("Please enter a number between 1 and 99 for your party", , "Invalid Number Entry")
            tbAmount.Focus()
            tbAmount.Clear()
        Catch ex As SystemException
            MsgBox("Please enter a number between 1 and 99 for your party", , "Invalid Number Entry")
            tbAmount.Focus()
            tbAmount.Clear()
        End Try

        'Return true only if number is between 1 and 99
        Return blnValid

    End Function

    Private Function ValidateTour(ByRef blnTour As Boolean, ByRef strTour As String) As Integer

        'Declare variables
        Dim intTour As Integer
        Try
            intTour = Convert.ToInt32(lstTours.SelectedIndex)
            strTour = lstTours.SelectedItem.ToString()
            blnTour = True
        Catch ex As SystemException
            MsgBox("Please select an event to participate in", , "Missing Input")
            blnTour = False
        End Try

        Return intTour
    End Function

    Private Function ArubaCost(ByVal intTour As Integer, ByVal intParty As Integer, ByRef intDuration As Integer) As Decimal

        'Declare Variables
        Dim decCost As Decimal
        Dim decTotal As Decimal
        Dim decDeep As Decimal = 199D
        Dim decKayak As Decimal = 89D
        Dim decScuba As Decimal = 119D
        Dim decSnork As Decimal = 95D

        'Calculate activate and duration from user selection
        Select Case intTour
            Case 0
                decCost = decDeep
                intDuration = 8I
            Case 1
                decCost = decKayak
                intDuration = 2I
            Case 2
                decCost = decScuba
                intDuration = 3I
            Case 3
                decCost = decSnork
                intDuration = 4I
        End Select

        'Find total and return
        decTotal = decCost * intParty
        Return decTotal

    End Function

    Private Function JamaicaCost(ByVal intTour As Integer, ByVal intParty As Integer, ByRef intDuration As Integer) As Decimal

        'Declare Variables
        Dim decCost As Decimal
        Dim decTotal As Decimal
        Dim decPara As Decimal = 129D
        Dim decJet As Decimal = 59D
        Dim decSnork As Decimal = 95D

        'Calculate activate and duration from user selection
        Select intTour
            Case 0
                decCost = decJet
                intDuration = 3I
            Case 1
                decCost = decPara
                intDuration = 2I
            Case 2
                decCost = decSnork
                intDuration = 3I
        End Select

        'Find total and return
        decTotal = decCost * intParty
        Return decTotal

    End Function

    Private Function KeyWestCost(ByVal intTour As Integer, ByVal intParty As Integer, ByRef intDuration As Integer) As Decimal

        'Declare Variables
        Dim decCost As Decimal
        Dim decTotal As Decimal
        Dim decCruise As Decimal = 299D
        Dim decSwim As Decimal = 39D
        Dim decSnork As Decimal = 95D

        'Calculate activate and duration from user selection
        Select Case intTour
            Case 0
                decCost = decCruise
                intDuration = 8I
            Case 1
                decCost = decSwim
                intDuration = 2I
            Case 2
                decCost = decSnork
                intDuration = 3I
        End Select

        'Find total and return
        decTotal = decCost * intParty
        Return decTotal

    End Function


    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        'Resets application to Tour Location selection
        cbLocation.Text = "Select Island Location"
        tbAmount.Clear()
        lstTours.Items.Clear()
        lblType.Text = String.Empty
        lblCost.Text = String.Empty
        lblDuration.Text = String.Empty
        lblParty.Visible = False
        tbAmount.Visible = False
        lblType.Visible = False
        lblCost.Visible = False
        lblDuration.Visible = False
        btnClear.Visible = False
        btnSelection.Visible = False
        lstTours.Visible = False

    End Sub

    Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
        'Create an option for user to close application
        Close()
    End Sub

    Private Sub ClearToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClearToolStripMenuItem.Click
        'Menu option does the same and click event
        cbLocation.Text = "Select Island Location"
        tbAmount.Clear()
        lstTours.Items.Clear()
        lblType.Text = String.Empty
        lblCost.Text = String.Empty
        lblDuration.Text = String.Empty
        lblParty.Visible = False
        tbAmount.Visible = False
        lblType.Visible = False
        lblCost.Visible = False
        lblDuration.Visible = False
        btnClear.Visible = False
        btnSelection.Visible = False
        lstTours.Visible = False
    End Sub
End Class

No comments:

Post a Comment

Thank you very much for viewing this entry and I hope you are able to return soon to continue to enjoy more of the site.
Please share your thoughts in the comment section.
Be blessed and enjoy life!