More on If statements (Calculate, Calculate1, Calculate2)

Slides:



Advertisements
Similar presentations
CS0004: Introduction to Programming Select Case Statements and Selection Input.
Advertisements

1.
30/04/ Selection Nested If structures & Complex Multiple Conditions.
ABNIAC The following slide presentation is to acquaint the student with ABNIAC. The version used for presentation is the Java version, which can be found.
Microsoft Visual Basic: Reloaded Chapter Five More on the Selection Structure.
Selection Logic Building decision-making into programs.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!
InvEasy (Project1) Please use speaker notes for additional information!
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Flowcharts! January 13, 2005 These are today’s notes! Do you think we will get more snow?
For Loops (ProjFor1, ProjFor2, ProjFor3, ProjFor4, textbox, textbox1) Please use speaker notes for additional information!
Changing Color, Using Text Objects, and Random Selection in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
New Project in Visual Basic Please use speaker notes for additional information!
By Melissa Dalis Professor Susan Rodger Duke University June 2011 Multiplication Table.
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
JavaScript, Fourth Edition
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
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!
Lesson 1. Security At the menu bar at the top you will see the word Tools. Click your mouse on Tools scroll down to Macro. Move the Mouse over and down.
31/01/ Selection If selection construct.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
Loop Blocks Chapter 6 Part A. Program Blocks 1.Actions- commands, messages, methods 2.Branches- decisions to be made 3.Loops- actions to be repeated.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
Excel Functions. Part 1. Introduction 2 An Excel function is a formula or a procedure that is performed in the Visual Basic environment, outside the.
IF Statements flowcharts and pseudocode Please open the speaker notes - they contain additional information!
Visual Basic - Break Processing
Chapter 4 MATLAB Programming
CHAPTER FIVE Decision Structures.
Chapter 4: The Selection Structure
Changing Color, Using Text Objects, and Random Selection in Alice
Starter Write a program that asks the user if it is raining today.
Please use speaker notes for additional information!
CHAPTER FIVE Decision Structures.
And the text with form..
More Selections BIS1523 – Lecture 9.
When I want to execute the subroutine I just give the command Write()
Making Decisions in a Program
Advanced Microsoft Excel
MODULE 7 Microsoft Access 2010
Department Array in Visual Basic
Conditions and Ifs BIS1523 – Lecture 8.
Please use speaker notes for additional information!
Qualtrics Survey Kenyon
Please use speaker notes for additional information!
text box. I brought this up by double clicking on the command button.
Items, Group Boxes, Check Boxes & Radio Buttons
Where to Access TE Items
Messages and Input boxes
Programming in JavaScript
Report using ADO connection
We are starting JavaScript. Here are a set of examples
If statements (Inven1, Inven2, Inven2a, Inven3, Inven3a)
Using screens and adding two numbers - addda.cbl
Variables & getting info from the user
Programming in JavaScript
Process Exchange Transactions Activity
Programming in JavaScript
Guidelines for Microsoft® Office 2013
Basic Lessons 5 & 6 Mr. Kalmes.
Basic Mr. Husch.
Category 1 Category 2 Category 3 Category 4 Category
This is an introduction to JavaScript using the examples found at the CIS17 website. In previous examples I specified language = Javascript, instead of.
2.2 – Activity Packages Create a new Process in UiPath Studio
Presentation transcript:

More on If statements (Calculate, Calculate1, Calculate2) Please use speaker notes for additional information! This Visual Basic project deals with IF statements and message boxes.

Calculate This uses the If..Else structure to test for the value that was entered in txtDiscCode on the form.

Calculate Discount Code = A N Y Discount Code = B N Y Result = Amt * .8 Discount Code = C Result = Amt * .85 N Y Discount Code = D Result = Amt * .9 N Y Messge Enter code A, B, C, or D Result = Amt * .95 This is the logic flowchart for the IF code in the Visual Basic. This is an OR structure with 4 different possibilities. If the code is neither A, B, C, or D then the message is displayed. Notice that the last IF is ended first with a circle that would be coded as an End If. Then the next to the last IF is ended with a circle and the this pattern continues until the top IF is ended with its own End IF.

Calculate The user entered a discount code of A so the processing multiplied the value entered by the user by 0.8 and stored the answer in txtRslt which is the result field on the form. Note that I did not use work areas in this code. The results of the calculation are but directly in the text box on the form.

Calculate In this case, the code is B, so the amount that is entered by the user is multiplied by 0.85.

Calculate If the code is not A, it is checked to see if it is B. If the code is not B it is checked to see if it is C. In this example, the code was entered as C so the amount that was entered as 100 is multiplied by .9 and the answer is put into the Result text box on the form.

Calculate In this case checking found that the code was not A, was not B and was not C. However, it was D so the amount of 100 that was entered was multiplied by .95 and the stored in the txtRslt text box on the form.

MsgBox "Enter code A, B, C, or D", vbOKOnly, "Error" Calculate The MsgBox uses several parameters in this example. The parameters are separated by commas. The first parameter is the message itself. The second parameter is the type of message box. In this case it is showing only the OK button. The third parameter is the title for the message box. Please note that the message box was dragged to this location so that everything could be seen. When I clicked the Calculate button the message box came up over the form. Note also in this structure that since there were 4 IF statements there are 4 End If statements. See the circles on the flowchart for clarification. MsgBox "Enter code A, B, C, or D", vbOKOnly, "Error"

Calculate1 This is an alternate approach to the same logic using the ElseIf statement. This code uses the ElseIf instead of the IF statement with separate ELSE statements. The last ELSE is simply Else. The logic and the results are the same as the previous examples.

Calculate2 The Case structure can also be used to determine the contents of txtDiscCode. In this case, I first give the command Select Case and name the field that is to be tested. Next I code the Case for each possibility using the structure Case “A” etc, Finally, Case Else gives the code for the MsgBox which is to be displayed if none of the Case statements evaluated as TRUE. This alternative uses the Case structure to determine the processing that needs to be done.