If statements (Inven1, Inven2, Inven2a, Inven3, Inven3a)

Slides:



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

Working with Intrinsic Controls and ActiveX Controls
30/04/ Selection Nested If structures & Complex Multiple Conditions.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
© English Language Testing Ltd Taking the Password Knowledge with Reading and Writing Test.
Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
05/09/ Introducing Visual Basic Sequence Programming.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
InvEasy (Project1) Please use speaker notes for additional information!
EDT 608 Unit 3 Using Microsoft Excel Under “Start”, go to “Programs” and select “Microsoft Excel”. Go the next slide to see the Excel Screen template.
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.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
For Loops (ProjFor1, ProjFor2, ProjFor3, ProjFor4, textbox, textbox1) Please use speaker notes for additional information!
Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.
New Project in Visual Basic Please use speaker notes for additional information!
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
Learning PowerPoint Part One: Working With Words Directions: Click the slide icon in the section at the right to move on to the next slide.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
1 Advanced Computer Programming Lab Calculator Project.
Class 2 Remote Instruction Review of Working with Buttons EDU 556 Programming for Instruction Dr. Steve Broskoske This is an audio PowerCast. Make sure.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
VB Objects & Events (Exercises) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 3, Friday 1/31/2003)
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!
Maximum Profit Please use speaker notes for additional information!
Sorry, the pen lost control. Anyway, you need to download both the.vbp and the.frm for each project. I looked at PrCalc, I did not look at inventory.
Visual Basic A Quick Tutorial VB Review for ACS 367.
I am using Visual Basic 6 for this class. If you want to use a different version, please contact me. Thanks!
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
Visual Basic/ Visual Studio Brandon Large. Connecting to prior knowledge In your notes write down what the two main parts of the computer are. The “software”
Multiple forms - SDI & MDI Please use speaker notes for additional information!
Computer Science Up Down Controls, Decisions and Random Numbers.
IF Statements flowcharts and pseudocode Please open the speaker notes - they contain additional information!
Visual Basic.NET Windows Programming
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Chapter Topics 15.1 Graphical User Interfaces
Chapter 8: Writing Graphical User Interfaces
Review Ch. 9 – Reports and Outlines
Computer Programming I
3.01 Apply Controls Associated With Visual Studio Form
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Standard Controls.
Please use speaker notes for additional information!
Microsoft Visual Basic 2005 BASICS
And the text with form..
More Selections BIS1523 – Lecture 9.
Department Array in Visual Basic
Please use speaker notes for additional information!
Star Math PreTest Instructions For iPad users with the STAR app
Please use speaker notes for additional information!
INTERMEDIATE PROGRAMMING LESSON
Items, Group Boxes, Check Boxes & Radio Buttons
Building an Application in the Visual Basic .NET Environment
CIS 16 Application Development Programming with Visual Basic
Introduction to Problem Solving and Control Statements
INTERMEDIATE PROGRAMMING LESSON
Chapter 5: Control Structure
Binary Search A binary search algorithm finds the position of a specified value within a sorted array. Binary search is a technique for searching an ordered.
Please use speaker notes for additional information!
Chapter 15: GUI Applications & Event-Driven Programming
Chapter 3: Selection Structures: Making Decisions
Using screens and adding two numbers - addda.cbl
Introduction to Programming
Chapter 3: Selection Structures: Making Decisions
More on If statements (Calculate, Calculate1, Calculate2)
Presentation transcript:

If statements (Inven1, Inven2, Inven2a, Inven3, Inven3a) Please use speaker notes for additional information! This is a series of programs that use the IF statement. The programs are Inven1, Inven2, Inven2a, Inven3 and Inven3a.

Inven1 This form was designed with a series of labels, text boxes and command buttons. There is a command button to calculate, a command button to clear the data that has been entered and a command button to end processing. Note that the buttons are called cmdClear, cmdCalc and cmdEnd with the first three letters that indicate that this is a command button in lower case.

Inven1 I entered in the data for Item Number, Item Name, On Hand and On Order. I then clicked Calculate. The message Need to Order appeared in the box that I had set up to receive the message. The code for this is shown on the next slide. As you will see the on hand field is checked and if it is less than 20, the Need to Order message is displayed. On later slides I will show how the color and font size were set for this display.

Inven1 There are three events shown here. The cmdCalc click event, the cmdClear click event and the cmdEnd click event. The cmdCalc click even contains an IF statement with no ELSE. The cmdClear simply moves a single space to all of the text boxes on the form. The cmdEnd contains the single command End which ends the processing.

If txtOnHand.Text < 20 Then txtMsg.Text = "Need to Order” End If Inven1 On hand < 20 N Y Need to Order to txtMsg VISUAL BASIC CODE: If txtOnHand.Text < 20 Then txtMsg.Text = "Need to Order” End If Logic flowchart for If statement. Note that the circle at the bottom is showing the End IF.

Private Sub cmdCalc_Click() If txtOnHand.Text < 20 Then Inven1 If the entry in txtOnHand is less than 20, the message Need to Order will be displayed in the text box called txtMsg. If it is not less than 20 nothing will happen. Private Sub cmdCalc_Click() If txtOnHand.Text < 20 Then txtMsg.Text = "Need to Order" End If End Sub Private Sub cmdClear_Click() txtItemNum.Text = " " txtItemName.Text = " " txtOnHand.Text = " " txtOnOrder.Text = " " txtMsg.Text = " " Private Sub cmdEnd_Click() End All of the text box fields are being set to a single space to clear out the entries. End will stop the processing and you will see the design form back on the screen. The default property on the text box fields is .Text. I have used it here, but frequently I will not since it is the default property.

Inven1 Note that the txtMsg text box has had the font size set to 12 and the font style set to Bold. In addition the ForeColor is red. That is why you see the message in Red and in larger, bold letters.

If txtOnHand.Text < 20 Then If txtOnOrder.Text < 20 Then Inven2 On hand < 20 N Y On order < 20 N Y Need to Order to txtMsg Logic for Inven2 where two things must be true to process. If either of the conditions is false, no processing is done. VISUAL BASIC CODE: If txtOnHand.Text < 20 Then If txtOnOrder.Text < 20 Then txtMsg.Text = "Need to Order" End If

Inven2 In this example, both on hand and on order need to be less than 20 for the message to display. This code is written with an IF within an IF. If the first condition is true, then the second condition is checked. If the second condition is true the message is displayed. If the first condition is not true the second condition is not checked. Note that both ifs are closed with their own End If. IF condition 1 THEN IF condition 2 THEN action to be taken if both conditions are true END IF

If txtOnHand.Text < 20 Then If txtOnOrder.Text < 20 Then Inven2a On hand < 20 N Y On order < 20 Okay to txtMsg N Y Low on hand to txtMsg Need to Order to txtMsg VISUAL BASIC CODE: If txtOnHand.Text < 20 Then If txtOnOrder.Text < 20 Then txtMsg.Text = "Need to Order" Else txtMsg.Text = "Low on hand" End If txtMsg.Text = "Okay" The three possible outputs are shown on the next three slides. If the first condition of on hand less than 20 is true then the second condition of on order less than 20 is checked. If the second condition is also true, Need to Order is displayed. If the second condition is not true, Low on hand is displayed. Back to the first condition. Note that if the first condition is not true, the second condition is not checked. The message Okay is displayed.

Inven2a Since on hand is less than 20 and on hand is less than 20, the Need to Order message is displayed.

Inven2a The on hand is less than 20. When on order is tested to see if it is less than 20 it is discovered that it is not. Therefore the else is executed. Note that because on hand is less that 20, the second question is asked. If it were not less than 20, the second question would not be asked. The second question is whether on order is less than 20. It is not so the else is executed. Low on hand is displayed and the if is ended.

Inven2a On hand is not less than 20 so the inner question or condition is never asked. The else that goes with the outer If is executed and Okay is moved to the message.

If txtOnHand.Text < 20 Then txtMsg.Text = "Need to Order" Else Inven3 On hand < 20 N Y Need to Order to txtMsg On order < 20 N Y Need to Order to txtMsg VISUAL BASIC CODE: If txtOnHand.Text < 20 Then txtMsg.Text = "Need to Order" Else If txtOnOrder.Text < 20 Then End If OR code: Either condition 1 or condition 2 must be true to process. In other words either on hand must be less than 20 or on order must be less than 20.

Inven3 Notice that if the first condition which tests if on hand is less than 20 is true the Need to Order message is displayed. If the first condition is not true, then the else asks the second condition which is if on order is less than 20. If the second condition is true then Need to Order is displayed. If the second condition is not true, there are no more chances and nothing is displayed. This is a classic OR example. If either condition 1 or condition 2 is true the message is displayed. If neither condition is true then no processing is done.

Inven3 In this example, the on hand is not less than 20, but the on order is so the message Need to Order is displayed.

Inven3 In this slide neither on hand no on order was less than 20 so no processing is done. This slide also shows the importance of the clear. If the numbers were entered before the message was clear, the message would remain after the button to calculate was clicked.

VISUAL BASIC CODE: Inven3a On hand < 20 N Y Need to Order to txtMsg On order < 20 N Y Okay to txtMsg Need to Order to txtMsg VISUAL BASIC CODE: If txtOnHand.Text < 20 Then txtMsg.Text = "Need to Order" Else If txtOnOrder.Text < 20 Then txtMsg.Text = "Okay" End If If you get a no to both conditions in the OR, then Okay is displayed.

Inven3a This is similar to Inven3. The difference is that now processing will be done if the answer to both conditions is false.