Presentation is loading. Please wait.

Presentation is loading. Please wait.

Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!

Similar presentations


Presentation on theme: "Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!"— Presentation transcript:

1 Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!

2 Muffins In this example, option buttons are grouped by placement in a frame. One check box is used to determine a discount.

3 Muffins cDisc has been declared as a constant of type currency. This means it will always be.95. Again note that multiple variables can be declared within one Dim statement and that in fact the variables can be of different types.

4 Muffins wrkHighestSale will contain the highest sale for this run of the program. If the amount just calculated in wrkAmountDue is greater than the amount in wrkHighestSale then this is the new highest sale and wrkAmountDue is moved to wrkHighestSale to give a new high sale to compare against. See comments on side and in speaker notes.

5 Muffins Note that all option buttons have value set to false. I could have set one to true thereby establishing a default.

6 Calculate was done for each of the images shown. For the last image, after calculate was done summary was also done.

7 txtAmtDue.Text = Format(wrkAmountDue, "Currency") If wrkAmountDue > wrkHighestSale Then wrkHighestSale = wrkAmountDue End If WrkTotal = WrkTotal + wrkAmountDue wrkAmountDue = 0 wrkCustomerCount = wrkCustomerCount + 1 In cmdCalc, the wrkHighestSale was determine and the totals were accumulated for total sales and total number of customers. The average is calculated only if there have been customers.

8 Muffin2 Note that you can not order a different quantity of each muffin.

9 Private Sub cmdCalc_Click() Const ConstNum As String = "Please enter a number!" If Not IsNumeric(txtQuan.Text) Then MsgBox ConstNum, vbOKOnly, "ERROR" End If If IsNumeric(txtQuan.Text) And chkCorn.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.85 * Val(txtQuan.Text) End If If IsNumeric(txtQuan.Text) And chkBran.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.75 * Val(txtQuan.Text) End If If IsNumeric(txtQuan.Text) And chkPoppy.Value = Checked Then wrkAmountDue = wrkAmountDue + 1 * Val(txtQuan.Text) End If If IsNumeric(txtQuan.Text) And chkBlue.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.9 * Val(txtQuan.Text) End If If IsNumeric(txtQuan.Text) And chkCran.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.9 * Val(txtQuan.Text) End If If optDozen.Value = True Then wrkAmountDue = wrkAmountDue * cDisc End If txtAmtDue.Text = Format(wrkAmountDue, "Currency") Muffin2 Since Cornmeal is checked,.85 is multiplied by the quantity of 2 and added to wrkAmountDue making it 1.70. Bran is not checked. Since Poppyseed is checked, 1.00 is multiplied by the quantity of 2 and added to wrkAmountDue making it 3.70. Blueberry is not checked Since Cranberry is checked,.90 is multiplied by the quantity of 2 and is added to wrkAmountDue making 5.50.

10 Const cDisc As Currency = 0.95 Dim wrkAmountDue As Currency, WrkTotal As Currency Dim wrkHighestSale As Currency, wrkCustomerCount As Integer Option Explicit Private Sub cmdCalc_Click() Const ConstNum As String = "Please enter a number!" If Not IsNumeric(txtQuan.Text) Then MsgBox ConstNum, vbOKOnly, "ERROR" End If If IsNumeric(txtQuan.Text) And chkCorn.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.85 * Val(txtQuan.Text) End If If IsNumeric(txtQuan.Text) And chkBran.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.75 * Val(txtQuan.Text) End If If IsNumeric(txtQuan.Text) And chkPoppy.Value = Checked Then wrkAmountDue = wrkAmountDue + 1 * Val(txtQuan.Text) End If If IsNumeric(txtQuan.Text) And chkBlue.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.9 * Val(txtQuan.Text) End If If IsNumeric(txtQuan.Text) And chkCran.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.9 * Val(txtQuan.Text) End If If optDozen.Value = True Then wrkAmountDue = wrkAmountDue * cDisc End If txtAmtDue.Text = Format(wrkAmountDue, "Currency") Muffin2 - code page 1

11 If wrkAmountDue > wrkHighestSale Then wrkHighestSale = wrkAmountDue End If WrkTotal = WrkTotal + wrkAmountDue wrkAmountDue = 0 wrkCustomerCount = wrkCustomerCount + 1 txtQuan.SetFocus End Sub Private Sub cmdClear_Click() txtQuan.Text = "" txtAmtDue.Text = "" optDozen.Value = False chkCorn.Value = Unchecked chkBran.Value = Unchecked chkPoppy.Value = Unchecked chkBlue.Value = Unchecked chkCran.Value = Unchecked End Sub Private Sub cmdExit_Click() End End Sub Muffin2 - code page 2

12 Private Sub cmdSum_Click() Dim wrkNewLine As String Dim wrkAverage As Currency Dim wrkMsgStr As String Dim fmtwrkHighestSale As String, fmtwrkAverage As String fmtwrkHighestSale = Format(wrkHighestSale, "Currency") wrkNewLine = Chr(10) If wrkCustomerCount > 0 Then wrkAverage = WrkTotal / wrkCustomerCount fmtwrkAverage = Format(wrkAverage, "Currency") wrkMsgStr = "Highest Sale " & _ fmtwrkHighestSale & wrkNewLine & _ "Average Sale " & fmtwrkAverage MsgBox wrkMsgStr, vbOKOnly, "SUMMARY" Else MsgBox "No data to summarize!" End If End Sub Muffin 2 - code page3


Download ppt "Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!"

Similar presentations


Ads by Google