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

Slides:



Advertisements
Similar presentations
Ch. 3 Variables VB.Net Programming. Data Types Boolean – True or False values Short – Small integers (+/- 32,767) Integer – Medium-size integers (+/-
Advertisements

30/04/ Selection Nested If structures & Complex Multiple Conditions.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Decision making in VBA. Current Event Occurs: When a form is opened When the focus leaves one record and moves to another Before the first or next record.
1 Loops zDo While Loop: yRepeats a block of code WHILE a condition remains TRUE Do While condition Code to execute Loop.
Val Function A Function performs an action and returns a value The expression to operate upon, known as the argument, (or multiple arguments), must be.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
© 1999, by Que Education and Training, Chapter 5, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
InvEasy (Project1) Please use speaker notes for additional information!
Break Processing Please use speaker notes for additional information!
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Chapter 4: The Selection Process in Visual Basic.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Programming Test #1 Solutions. Multiple Choice 1. B) the grammar of the coding language 2. C) String 3. A) Single 4. C) 2Burgers4Me 5. B) Design Time.
Do Loop with Interest Please see speaker notes for additional information!
Arrays Code: Arrays Controls: Control Arrays, PictureBox, Timer.
New Project in Visual Basic Please use speaker notes for additional information!
1 Flow Control II Code: Select-Case and For-Next Controls: Frames and OptionButtons.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
Visual Basic Programming Making Decisions: Loops & Decision Structures ©Copyright by Ronald P. Kessler, Ph.D.
Random Files Please see speaker notes for additional information!
University of Sunderland CIF 104 Fundamentals of DatabasesUnit 16 SESSION 16 VBA example.
Arrays1 From time to time an object (a variable, a picture, a label or a command) does not serve as well as a set of objects of a similar kind addressed.
Delivery and other DO Examples Please use speaker notes for additional information!
22/11/ Selection If selection construct.
Two Forms Please use speaker notes for additional information!
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
ME 142 Engineering Computation I Using Subroutines Effectively.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
VAT Calculator program Controls Properties Code Results.
Pay Example (PFirst98) Please use speaker notes for additional information!
Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!
Programming with Microsoft Visual Basic th Edition
Maximum Profit Please use speaker notes for additional information!
CECS 5020 Computers in Education Visual Basic Variables and Constants.
31/01/ Selection If selection construct.
CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.
Controlling Program Flow with Decision Structures.
Using a Database Access97 Please use speaker notes for additional information!
Adding Code to the Option Button. Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
1 4.2 Selection Logical Operators. 2 Learning Objectives Explain how the logical operator AND Boolean statements works. Directly testing if text boxes.
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
Making Interactive Programs with Visual Basic .NET
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Multiple forms - SDI & MDI Please use speaker notes for additional information!
Visual Basic - Break Processing
This presentation demonstrates online order process on Biznet Tradelink.
Processing multiple files
IE 8580 Module 4: DIY Monte Carlo Simulation
A variable is a name for a value stored in memory.
Please use speaker notes for additional information!
Department Array in Visual Basic
البرمجة بلغة فيجول بيسك ستوديو
If selection construct
If statements (Inven1, Inven2, Inven2a, Inven3, Inven3a)
Active-X Calendar Control
Visual Basic Programming
More on If statements (Calculate, Calculate1, Calculate2)
Repetition - Counting and Accumulating
Introduction to Computer Programming IT-104
Presentation transcript:

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

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

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.

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.

Muffins 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 = 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.

Muffin2 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 If If IsNumeric(txtQuan.Text) And chkCorn.Value = Checked Then wrkAmountDue = wrkAmountDue * Val(txtQuan.Text) End If If IsNumeric(txtQuan.Text) And chkBran.Value = Checked Then wrkAmountDue = wrkAmountDue * 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 * Val(txtQuan.Text) End If If IsNumeric(txtQuan.Text) And chkCran.Value = Checked Then wrkAmountDue = wrkAmountDue * 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 Bran is not checked. Since Poppyseed is checked, 1.00 is multiplied by the quantity of 2 and added to wrkAmountDue making it 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.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 * Val(txtQuan.Text) End If If IsNumeric(txtQuan.Text) And chkBran.Value = Checked Then wrkAmountDue = wrkAmountDue * 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 * Val(txtQuan.Text) End If If IsNumeric(txtQuan.Text) And chkCran.Value = Checked Then wrkAmountDue = wrkAmountDue * Val(txtQuan.Text) End If If optDozen.Value = True Then wrkAmountDue = wrkAmountDue * cDisc End If txtAmtDue.Text = Format(wrkAmountDue, "Currency") Muffin2 - code page 1

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

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