# Assistance with trying to complete a event procedure using VB 8 (VB.NET)



## tigerfansince84 (Feb 3, 2007)

I've written a program that calculates a t-shirt order and stores the summary. The person selects the various shirt sizes through radio buttons. Now I am trying to go back and write an event procedure using the case function, but I'm having issues. I've posted my code as is. I'm having trouble trying to have the event procedure store the correct result as a decimal (shirt price). 


```
Option Strict On

Public Class BoardsForm

    'Declare the module-level variables and constants
    Const SMLMEDLARGE_Decimal As Decimal = 10D
    Const EXTRA_LARGE_Decimal As Decimal = 11D
    Const XX_LARGE_Decimal As Decimal = 12D
    Const MONOGRAM_Decimal As Decimal = 2D
    Const POCKET_Decimal As Decimal = 1D
    Private QuantityShirtsInteger, NumberOrdersInteger As Integer
    Private TotalDecimal, TotalAllOrdersDecimal As Decimal


    Private Sub AddToOrderToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddToOrderToolStripMenuItem.Click
        'Add a shirt to the order
        Dim ShirtPriceDecimal As Decimal
        Dim QuantityInteger As Integer
        Dim MessageString As String

        'Validate that a Customer name was entered
        If NameTextBox.Text <> "" Then

            'Validate that an Order number was entered
            If OrderNumberTextBox.Text <> "" Then

                Try
                    'Convert quantity
                    QuantityInteger = Integer.Parse(QuantityTextBox.Text)

                    'Only accept values greater than zero
                    If QuantityInteger > 0 Then
                        If SmallRadioButton.Checked Or MediumRadioButton.Checked _
                            Or LargeRadioButton.Checked Or ExtraLargeRadioButton.Checked _
                            Or XXLRadioButton.Checked Then

                            NameTextBox.Enabled = False
                            OrderNumberTextBox.Enabled = False
                            OrderCompleteToolStripMenuItem.Enabled = True

                            'Call the function
                            ShirtPriceDecimal = ShirtPrice(QuantityInteger)

                            'Calculate totals for the summary
                            TotalDecimal += ShirtPriceDecimal
                            QuantityShirtsInteger += QuantityInteger
                            TotalAllOrdersDecimal += ShirtPriceDecimal

                            'Display the shirt price and total for this customer
                            ShirtPriceTextBox.Text = ShirtPriceDecimal.ToString("C")
                            OrderTotalTextBox.Text = TotalDecimal.ToString("C")
                        Else
                            MessageString = "Please select a shirt size."
                            MessageBox.Show(MessageString, "Selection Required", MessageBoxButtons.OK, MessageBoxIcon.Error)
                        End If
                    Else
                        MessageString = "Please enter a number greater than zero."
                        MessageBox.Show(MessageString, "Input Quantity", MessageBoxButtons.OK, MessageBoxIcon.Error)
                        With QuantityTextBox
                            .Focus()
                            .SelectAll()
                        End With
                    End If
                Catch QuantityException As FormatException
                    MessageString = "Please enter the number of shirts."
                    MessageBox.Show(MessageString, "Input Needed", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    With QuantityTextBox
                        .Focus()
                        .SelectAll()
                    End With
                Catch AnyException As Exception
                    MessageBox.Show("Error: " & AnyException.Message)
                End Try
            Else
                MessageString = "Please enter an order number"
                MessageBox.Show(MessageString, "Input Needed", MessageBoxButtons.OK, MessageBoxIcon.Error)
                OrderNumberTextBox.Focus()
            End If
        Else
            MessageString = "Please enter a name"
            MessageBox.Show(MessageString, "Input Needed", MessageBoxButtons.OK, MessageBoxIcon.Error)
            NameTextBox.Focus()
        End If
    End Sub

    Private Function ShirtPrice(ByVal QuantityInteger As Integer) As Decimal
        'Calculates the shirt price

        Dim ShirtDecimal, PriceDecimal, MonogramDecimal, PocketDecimal As Decimal



        'Call the ShirtDecimal from the event procedure
                        

                    'Calculate the price of one shirt
                            PriceDecimal = ShirtDecimal + PocketDecimal + MonogramDecimal

                    'Calculate the extended price by multiplying the price of 1 shirt times the quantity
                            Return PriceDecimal * QuantityInteger

    End Function

    Private Sub RadioButtons_CheckedChanged(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles SmallRadioButton.CheckedChanged, _
     MediumRadioButton.CheckedChanged, LargeRadioButton.CheckedChanged, _
     ExtraLargeRadioButton.CheckedChanged, XXLRadioButton.CheckedChanged

        Dim SelectedRadiobutton As RadioButton

        SelectedRadiobutton = CType(sender, Decimal)

        Select Case SelectedRadiobutton.Name

            Case "SmallRadioButton"
                SmallRadioButton.Checked = True
                ShirtDecimal = SMLMEDLARGE_Decimal
            Case "MediumRadioButton"
                MediumRadioButton.Checked = True
                ShirtDecimal = SMLMEDLARGE_Decimal
            Case "LargeRadioButton"
                LargeRadioButton.Checked = True
                ShirtDecimal = SMLMEDLARGE_Decimal
            Case "ExtraLargeRadioButton"
                ExtraLargeRadioButton.Checked = True
                ShirtDecimal = EXTRA_LARGE_Decimal
            Case "XXLRadioButton"
                XXLRadioButton.Checked = True
                ShirtDecimal = XX_LARGE_Decimal

        End Select

    End Sub
    Private Sub ClearThisItemToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearThisItemToolStripMenuItem.Click
        'Clear the form

        ShirtPriceTextBox.Clear()
        SmallRadioButton.Checked = False
        MediumRadioButton.Checked = False
        LargeRadioButton.Checked = False
        ExtraLargeRadioButton.Checked = False
        XXLRadioButton.Checked = False
        MonogramCheckBox.Checked = False
        PocketCheckBox.Checked = False
        With QuantityTextBox
            .Clear()
            .Focus()
        End With
    End Sub

    Private Sub OrderCompleteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrderCompleteToolStripMenuItem.Click
        'Clear this customer and begin a new order
        Dim ReplyDialogResult As DialogResult
        Dim MessageString As String

        MessageString = "Do you wish to complete this order?"
        ReplyDialogResult = MessageBox.Show(MessageString, "Confirmation Required", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
        If ReplyDialogResult = DialogResult.Yes Then
            NameTextBox.Clear()
            OrderNumberTextBox.Clear()
            QuantityTextBox.Clear()
            ShirtPriceTextBox.Clear()
            OrderTotalTextBox.Clear()
            SmallRadioButton.Checked = False
            MediumRadioButton.Checked = False
            LargeRadioButton.Checked = False
            ExtraLargeRadioButton.Checked = False
            XXLRadioButton.Checked = False
            MonogramCheckBox.Checked = False
            PocketCheckBox.Checked = False

            TotalDecimal = 0
            NumberOrdersInteger += 1

            NameTextBox.Enabled = True
            OrderNumberTextBox.Enabled = True
            OrderCompleteToolStripMenuItem.Enabled = False
            SummaryToolStripMenuItem.Enabled = True
            NameTextBox.Focus()
        End If
    End Sub

    Private Sub SummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryToolStripMenuItem.Click
        'Display the summary of all orders
        Dim MessageString As String

        If TotalDecimal > 0 Then
            MessageString = "The current order is not included in the summary."
            MessageBox.Show(MessageString, "Please complete the order!", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageString = _
                "Total Shirts Ordered:   " & QuantityShirtsInteger _
                & Environment.NewLine & _
                "Number of Orders:       " & NumberOrdersInteger _
                & Environment.NewLine & _
                "Total of All Orders: " & TotalAllOrdersDecimal.ToString("C")
            MessageBox.Show(MessageString, "Summary", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.NameTextBox.Focus()
        End If
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        'Terminate the program

        Me.Close()
    End Sub

    Private Sub SloganToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SloganToolStripMenuItem.Click
        'Makes Slogan Visible/Invisible

        With Me
            If .SloganToolStripMenuItem.Checked Then
                .SloganToolStripMenuItem.Checked = False
                .SloganLabel.Visible = False
            Else
                .SloganToolStripMenuItem.Checked = True
                .SloganLabel.Visible = True
            End If
        End With
    End Sub

    Private Sub LogoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LogoToolStripMenuItem.Click
        'Makes Logo visible/invisible

        With Me
            If .LogoToolStripMenuItem.Checked Then
                .LogoToolStripMenuItem.Checked = False
                .PictureBox1.Visible = False
            Else
                .LogoToolStripMenuItem.Checked = True
                .PictureBox1.Visible = True
            End If
        End With
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        'Dispalys About Message.
        Dim MessageString As String

        MessageString = "Very Very Boards" & Environment.NewLine _
           & Environment.NewLine & "Programmed by: Robert Sutherland"
        MessageBox.Show(MessageString, "About Very Very Boards", MessageBoxButtons.OK, MessageBoxIcon.Information)

    End Sub

    Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
        'Change the font of the slogan.

        With FontDialog1
            .Font = SloganLabel.Font
            .ShowDialog()
            SloganLabel.Font = .Font
        End With

    End Sub

    Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
        'Changes color of slogan.

        With ColorDialog1
            .Color = SloganLabel.ForeColor
            .ShowDialog()
            SloganLabel.ForeColor = .Color

        End With
    End Sub
End Class
```


----------

