Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27078

Sum of a listbox

$
0
0
First and foremost, I am terrible at this. I've been working on this project for the last 3 days. I've gone back and forth trying to get things to work and I think I'm close. I have a feeling I'm doing it wrong but I decided to just go with what I have since I have to turn it in tomorrow. The project is to A) Write a conditional statement(s) to handle the order of coffee B) Put the conditional statement(s) in a loop so that a customer can order several cups of coffee if they desire.

Here is what I have so far. Again, I feel I might be doing this wrong but I'm not looking for that to be corrected I just want to be able to add the items in the listbox once the "No" button is clicked on the MsgBox.

Code:

Private Sub btnTotal_Click(sender As System.Object, e As System.EventArgs) Handles btnTotal.Click

        Dim decTotalCostOfCoffee As Decimal
        Dim decSubTotal As Decimal
        Dim decRegularCoffee As Decimal = 1.25D
        Dim decCappuccino As Decimal = 2D
        Dim decCafeAuLait As Decimal = 1.75D
        Dim intItemsToAdd As Integer

        If radRegCoffee.Checked Or radCappuccino.Checked Or radCafeAuLait.Checked Then

            Do

                If radRegCoffee.Checked = True Then
                    decSubTotal = decRegularCoffee
                ElseIf radCappuccino.Checked = True Then
                    decSubTotal = decCappuccino
                ElseIf radCafeAuLait.Checked = True Then
                    decSubTotal = decCafeAuLait
                End If

                lstCoffee.Items.Add(decSubTotal)

                If MsgBox("Would you like to add another coffee?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Coffee") = MsgBoxResult.Yes Then

                    decTotalCostOfCoffee += decSubTotal
                    radRegCoffee.Checked = False
                    radCafeAuLait.Checked = False
                    radCappuccino.Checked = False
                    lblTotalCostOfCoffee.Text = "Your total is: " & decTotalCostOfCoffee.ToString("C")

                Else

                    intItemsToAdd = 0
                    btnTotal.Enabled = False
                    lblTotalCostOfCoffee.Text = "Your total is: " & decTotalCostOfCoffee.ToString("C")

                End If
            Loop Until intItemsToAdd = 0
        Else
            MsgBox("Please select a coffee type", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Item Missing")

        End If


    End Sub


Viewing all articles
Browse latest Browse all 27078

Trending Articles



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