Quantcast
Channel: Visual Studio General Questions forum
Viewing all articles
Browse latest Browse all 21115

Display list box selections in a message box

$
0
0

I have written a windows from that has three list boxes.

Two of which are multi selection boxes.

On ordering i want to produce a message box that has an itemized list.

Everything seems to work that i want however i can not get it to provide a list of all the items selected

E.g.
Item 1
item 2
Item 3

I have provided what i have compiled so far. Any help is appreciated. 

Option Explicit On

Public Class frmOrder

    ' String variable place holders
    Dim MeatSelection As String
    Dim CheeseSelection As String
    Dim VegetableSelection As String
    Dim DrinksChips As String

    ' Variables to store amounts of calculations necessary as double to allow for monetary conversion
    Dim TotalPrice As Double                ' Position holder for final cost calculated
    Dim VegetableCost As Double = 0         ' Position holder for the charge for extra veg' if any
    Dim CheeseCost As Double = 0            ' Position holder for the charge for extra Cheese if any
    Dim Extras As Double = 0                ' Position holder for the addition of drink, chips or both
    Dim CheeseCount As Integer              ' Position for the integer that is calculated by cheese selection 
    Dim VegetableCount As Integer           ' Position for the integer that is calculated by Veg' selection 


    ' Constant amounts are declared here
    Const Cost As Double = 3.5              ' cost of sandwich $3.50
    Const ExtraCheese As Double = 0.5       ' Cost of Extra Cheese $0.50 per extra selection
    Const ExtraVegetables As Double = 0.25  ' Cost of Extra Vegetable $0.25 per extra selection
    Const Chips As Double = 1.0             ' Cost of Chips $1.00
    Const Drink As Double = 1.5             ' Cost of a drink $1.50
    Const DiscountPrice As Double = 2.0     ' If drink and chips are chosen then the combined price is a discount at $2.00

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click

        ' Exit the form without saving
        Me.Close()

    End Sub

    Private Sub btnClearForm_Click(sender As Object, e As EventArgs) Handles btnClearForm.Click

        ' Clear the Form and start over 
        ClearForm()

    End Sub

    Private Sub btnOrder_Click(sender As Object, e As EventArgs) Handles btnOrder.Click


        ' Providing the initial count of items in chese and vegetables for selection
        CheeseCount = ListBoxCheeseSelection.SelectedItems.Count()
        VegetableCount = ListBoxVegatableSelection.SelectedItems.Count()

        ' Calculating the number of chossen items and calculating the extra cost by
        ' Subtracting total allowed choices from the selected choices and multiplying result by the Cost per extra choice
        CheeseCost = (CheeseCount - 1) * ExtraCheese
        VegetableCost = (VegetableCount - 3) * ExtraVegetables


        ' If both boxes are checked a discounted price is calculated and assigned to the variable "Extras"
        If chkChips.Checked And chkDrink.Checked Then
            Extras = DiscountPrice
        End If


        ' Depending on the selection of drink chips the string displayed will reflect the choice
        ' A simple statement using the predetermined variable assignment by the check boxes 
        If Extras = DiscountPrice Then
            DrinksChips = ("Combo Choice: ")
        ElseIf Extras = Drink Then
            DrinksChips = ("Drink Choice: ")
        ElseIf Extras = Chips Then
            DrinksChips = ("Chips Choice: ")
        End If


        ' This line is calculating the final cost of the purchase
        TotalPrice = Cost + Extras + (CheeseCost + VegetableCost)


        ' Provides a disocunt for a sandwich with no meat selection
        If ListBoxMeatSelection.Text = "Vegetarian" Then
            MsgBox("For Vegetarian sandwiches you receive $0.50 off the total")
            TotalPrice = TotalPrice - 0.5
        End If


        ' Displays a message box with itemised charges added
        MsgBox("Basic " & ListBoxMeatSelection.Text.ToString & " Sandwich: " & Cost.ToString("C") & vbCr _& "Cheese Selection: " _& CheeseCost.ToString("C") & vbCr _& ListBoxCheeseSelection.SelectedItems.Count.ToString & "Cheese selected" & vbCr _& "Vegatable selection: " _& VegetableCost.ToString("C") & vbCr _& ListBoxVegatableSelection.SelectedItems.Count.ToString & " Vegetables Selected" & vbCr _& DrinksChips.ToString & Extras.ToString("C") & vbCr _& vbCr & "The total price for your order is: " & TotalPrice.ToString("C"))


        ' This sub routine clears the from of stored information
        ClearForm()

    End Sub

    Private Sub chkChips_CheckedChanged(sender As Object, e As EventArgs) Handles chkChips.CheckedChanged

        ' Assisgns a variable Extras with content when Chips is selected

        If chkChips.Checked = True Then
            Extras = Chips
        End If

    End Sub

    Private Sub chkDrink_CheckedChanged(sender As Object, e As EventArgs) Handles chkDrink.CheckedChanged

        ' Assisgns a variable Extras with content when drink is selected

        If chkDrink.Checked = True Then
            Extras = Drink
        End If

    End Sub

    Private Sub ClearForm()

        ' This sub routine clears the from of stored information

        ListBoxCheeseSelection.ClearSelected()
        ListBoxMeatSelection.ClearSelected()
        ListBoxVegatableSelection.ClearSelected()
        chkChips.Checked = False
        chkDrink.Checked = False
    End Sub

End Class
The formatting is off as it is not VB net but VB 2012 win form.

Viewing all articles
Browse latest Browse all 21115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>