muffin shop - if, calculations etc. (muffins, muffins2) please use speaker notes for additional...
TRANSCRIPT
Muffin Shop - if, calculations etc.(muffins, muffins2)
Please use speaker notes for additional information!
MuffinsMuffins
In this example, option buttons are grouped by placement in a frame.
One check box is used to determine a discount.
MuffinsMuffins
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.
MuffinsMuffins
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.
MuffinsMuffins
Note that all option buttons have value set to false. I could have set one to true thereby establishing a default.
Calculate was done for each of the images shown. For the last image, after calculate was done summary was also done.
txtAmtDue.Text = Format(wrkAmountDue, "Currency")If wrkAmountDue > wrkHighestSale Then wrkHighestSale = wrkAmountDueEnd IfWrkTotal = WrkTotal + wrkAmountDuewrkAmountDue = 0wrkCustomerCount = 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.
Muffin2Muffin2
Note that you can not order a different quantity of each muffin.
Private Sub cmdCalc_Click()Const ConstNum As String = "Please enter a number!"If Not IsNumeric(txtQuan.Text) Then MsgBox ConstNum, vbOKOnly, "ERROR"End IfIf IsNumeric(txtQuan.Text) And chkCorn.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.85 * Val(txtQuan.Text)End IfIf IsNumeric(txtQuan.Text) And chkBran.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.75 * Val(txtQuan.Text)End IfIf IsNumeric(txtQuan.Text) And chkPoppy.Value = Checked Then wrkAmountDue = wrkAmountDue + 1 * Val(txtQuan.Text)End IfIf IsNumeric(txtQuan.Text) And chkBlue.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.9 * Val(txtQuan.Text)End IfIf IsNumeric(txtQuan.Text) And chkCran.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.9 * Val(txtQuan.Text)End IfIf optDozen.Value = True Then wrkAmountDue = wrkAmountDue * cDiscEnd IftxtAmtDue.Text = Format(wrkAmountDue, "Currency")
Muffin2Muffin2
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.
Const cDisc As Currency = 0.95Dim wrkAmountDue As Currency, WrkTotal As CurrencyDim wrkHighestSale As Currency, wrkCustomerCount As IntegerOption Explicit
Private Sub cmdCalc_Click()Const ConstNum As String = "Please enter a number!"If Not IsNumeric(txtQuan.Text) Then MsgBox ConstNum, vbOKOnly, "ERROR"End IfIf IsNumeric(txtQuan.Text) And chkCorn.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.85 * Val(txtQuan.Text)End IfIf IsNumeric(txtQuan.Text) And chkBran.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.75 * Val(txtQuan.Text)End IfIf IsNumeric(txtQuan.Text) And chkPoppy.Value = Checked Then wrkAmountDue = wrkAmountDue + 1 * Val(txtQuan.Text)End IfIf IsNumeric(txtQuan.Text) And chkBlue.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.9 * Val(txtQuan.Text)End IfIf IsNumeric(txtQuan.Text) And chkCran.Value = Checked Then wrkAmountDue = wrkAmountDue + 0.9 * Val(txtQuan.Text)End IfIf optDozen.Value = True Then wrkAmountDue = wrkAmountDue * cDiscEnd IftxtAmtDue.Text = Format(wrkAmountDue, "Currency")
Muffin2 - code page 1
Muffin2 - code page 1
If wrkAmountDue > wrkHighestSale Then wrkHighestSale = wrkAmountDueEnd IfWrkTotal = WrkTotal + wrkAmountDuewrkAmountDue = 0wrkCustomerCount = wrkCustomerCount + 1txtQuan.SetFocusEnd 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 = UncheckedEnd Sub
Private Sub cmdExit_Click() EndEnd Sub
Muffin2 - code page 2
Muffin2 - code page 2
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
Muffin 2 - code page3