Ppt lesson 08


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Ppt lesson 08

  1. 1. Microsoft Visual Basic 2005 BASICS Lesson 8 If Statements
  2. 2. Objectives <ul><li>Explain how decisions are made in a computer. </li></ul><ul><li>Use the conditional operators. </li></ul><ul><li>Use If statements to make decisions in programs. </li></ul><ul><li>Create and read basic flowcharts. </li></ul>
  3. 3. Objectives (cont.) <ul><li>Use If…Else statements. </li></ul><ul><li>Use check box controls. </li></ul><ul><li>Use the logical operators. </li></ul>
  4. 4. The Building Blocks of Decision Making <ul><li>Programs are limited without the ability to make decisions. </li></ul><ul><li>Programs must have a means to make decisions. </li></ul><ul><li>Decision making in computers </li></ul><ul><ul><li>Generally done in terms of a comparison that returns a True or False response </li></ul></ul>
  5. 5. The Building Blocks of Decision Making (cont.)
  6. 6. Using the Conditional Operators <ul><li>The first step to making a decision in a program is to make a comparison. </li></ul><ul><li>Comparisons are made using the conditional operators. </li></ul><ul><li>Boolean variables </li></ul><ul><ul><li>Can be used to store the results of a conditional expression </li></ul></ul>
  7. 7. Using the Conditional Operators (cont.)
  8. 8. Using the Conditional Operators (cont.)
  9. 9. Using If Statements <ul><li>If statement </li></ul><ul><ul><li>Allows you to execute specified code when the result of a conditional expression is True </li></ul></ul><ul><li>The End If statement marks the end of the If statement. </li></ul>
  10. 10. Using If Statements (cont.) <ul><li>Code in between the If statement and End If statement is executed if the conditions specified in the If statement are true. </li></ul><ul><ul><li>Otherwise, the code is skipped. </li></ul></ul>
  11. 11. Creating and Reading Flowcharts <ul><li>Flowcharts </li></ul><ul><ul><li>Help you to plan and document program code </li></ul></ul><ul><li>There are many symbols used in creating flowcharts. </li></ul><ul><ul><li>The rectangle represents processing data. </li></ul></ul><ul><ul><li>Use the diamond for making decisions. </li></ul></ul><ul><ul><li>Use the parallelogram to represent input and output. </li></ul></ul>
  12. 12. Creating and Reading Flowcharts (cont.)
  13. 13. Creating and Reading Flowcharts (cont.)
  14. 14. Using If…Else Statements <ul><li>A one-way selection structure </li></ul><ul><ul><li>Program structure in which the decision is to go “one way” </li></ul></ul><ul><li>The If…Else statement </li></ul><ul><ul><li>Allows you to choose between two paths </li></ul></ul>
  15. 15. Using If…Else Statements (cont.) <ul><li>In an If…Else statement </li></ul><ul><ul><li>One block of code is executed if the result of an expression is True. </li></ul></ul><ul><ul><li>Another block is executed if the result is False. </li></ul></ul>
  16. 16. Using If…Else Statements (cont.)
  17. 17. Using If…Else Statements (cont.)
  18. 18. Using Check Boxes <ul><li>Check boxes are an important part of the Windows interface. </li></ul><ul><li>Check boxes allow the programmer to </li></ul><ul><ul><li>Ask the user a Yes or No question </li></ul></ul><ul><ul><li>Turn an option on or off </li></ul></ul>
  19. 19. Using Check Boxes (cont.)
  20. 20. Checked Property <ul><li>Each check box has a Checked property. </li></ul><ul><ul><li>Set to True if the box is checked </li></ul></ul><ul><ul><li>Set to False if the box is not checked </li></ul></ul><ul><li>A check box has an integrated label. </li></ul><ul><ul><li>Appears beside it </li></ul></ul><ul><ul><li>Text property specifies its label </li></ul></ul>
  21. 21. Checked Property (cont.)
  22. 22. Setting the Default Checked Property <ul><li>Check boxes can be set to be either checked or unchecked by default. </li></ul><ul><ul><li>Use the Checked property </li></ul></ul>
  23. 23. Setting the Checked Property with Code <ul><li>The Checked property can be set and/or read from code. </li></ul><ul><li>Example </li></ul><ul><ul><li>chkHeart.Checked = True </li></ul></ul>
  24. 24. Setting the Checked Property with Code (cont.)
  25. 25. Using the Logical Operators <ul><li>Logical operators </li></ul><ul><ul><li>Can be used to combine several comparisons into one statement </li></ul></ul><ul><ul><li>Used with True and False values </li></ul></ul>
  26. 26. Using the Logical Operators (cont.)
  27. 27. Order of Logical Operators <ul><li>Logical operators </li></ul><ul><ul><li>Processed after the mathematical and conditional operators </li></ul></ul><ul><li>Logical operators are processed in this order </li></ul><ul><ul><li>Not </li></ul></ul><ul><ul><li>And </li></ul></ul><ul><ul><li>Or </li></ul></ul>
  28. 28. Order of Logical Operators (cont.)
  29. 29. Summary <ul><li>Decisions are reached by making comparisons. Comparisons in a computer generally return either a True or False value. </li></ul><ul><li>The conditional operators compare two values and return either True of False, depending on whether the expression is True or False. </li></ul>
  30. 30. Summary (cont.) <ul><li>A Boolean variable can be used to store the results of an expression that includes conditional operators. </li></ul><ul><li>The If statement is the most common way to make a decision in a program, and it is a one-way selection structure. The code between the If and the End If is executed if the conditions in the If statement are met. </li></ul>
  31. 31. Summary (cont.) <ul><li>Flowcharts allow programmers to plan and document program code using symbols connected by lines. </li></ul><ul><li>An If…Else statement makes a decision between two paths, and it is a two-way selection structure. </li></ul>
  32. 32. Summary (cont.) <ul><li>Check boxes allow your program to ask the user Yes or No questions or to turn an option on or off. The Checked property of a check box is set to True when the check box is checked and False when the check box is not checked. A check box can be set to be checked or unchecked by default. </li></ul>
  33. 33. Summary (cont.) <ul><li>Logical operators can be used to combine several comparisons into one statement. They are used with True and False values. </li></ul><ul><li>The Not operator reverses the value of a Boolean variable or expression. </li></ul><ul><li>The And operator returns True if the values connected by the And operator are both True. </li></ul>
  34. 34. Summary (cont.) <ul><li>The Or operator returns True if either value connected by the Or operator is True. </li></ul><ul><li>The logical operators are last in the order of operations. Of the logical operators, Not comes first, then And, then Or. </li></ul>