34
The Selection Structure The if…then…Else and Select Case Statement Paramet Damchoo , lecturer Business computer Department Management science Faculty Surattani ratjabhat University สสสสสสสสสส สสสสสสสสสส สส มมมมมมมมมมมมมมมมมมมม มมมม

If statemet1

  • Upload
    sup11

  • View
    705

  • Download
    1

Embed Size (px)

Citation preview

  • 1. The Selection Structure The ifthenElse andSelect Case Statement Paramet Damchoo , lecturerBusiness computer Department Management science FacultySurattani ratjabhat University

2. The Selection Structure

  • You use the selection structure , also called the decision structure, when you want a program to make a decision or comparison and then, based on the result of that decision or comparison, to select one of two paths. You will need to use the selection structure to complete the Math application.

3. Figure 1-1: Decisions you might need to make today 4. Coding the Selection Structure in Visual Basic

  • You usethe if then Else statement to code the selection structure in Visual Basic. The syntax ofthe IfThenElse statement is shown in figure 1-2

5. Figure 1-2: Syntax of IfThenElseStatement

  • IfConditionThen
  • [instructions when the condition is true]
  • Else
  • [instructions when the condition is false]
  • End If

6. Figure1-3: lists the relational operators you can use in the IfThen..Else statement s condition Relational Operator Meaning = Equal to > Greater than >= Greater than orequal to < Less than=20000 Salary=20000 THEN

  • Tax = Salary *15%
  • ELSE
  • Tax = Salary *10%
  • IF Salary = 20000
    • =x 15%
    • =x 10%
    • 4.
    • 5.

14. Flowchart

    • > = 20000
    • =x 15%
    • =x 10%
    • 4.
    • 5.

START INPUT Salary Salary >=20000 =x 15% =x 10% OUTPUT Salary STOP 15. Pseudo code

  • BEGIN
  • InputSalary
  • IF Salary >=20000THEN
  • Tax =Salary*(15/100)
  • ELSE
  • Tax =Salary*(10/100)
  • END IF
  • DISPLAY Tax
  • END

16. Message Box Message Box 3. Title 2. Control Msgbox 2.Icon 1. Promt 17. Syntax MessageBox

  • MsgboxPromt , Icon+Control+Default,Title

18. Icon VbCritical VbExclamation VbInformation Vbquestion 19. VbOKOnly VbokCancel VbYesNo VbYesNoCancel VbAbortRetryIgnore VbRetryCancel 20. coding Msgbox ,VbInformation+ VbYesnoCancel+ VbDefault2, MSGBOX 21. Net IF statement

  • 2 IF (True/False)

22. Syntax

  • IFCondition-1THEN
  • [instruction when condition istrue ]
  • ELSEIFCondition-2THEN
  • [instruction when condition istrue ]
  • ELSE
  • [instruction when condition isfalse ]
  • END IF

23. Example-1

  • 1 Freshman
  • 2 Sophomore
  • 3 Junior
  • 4 Senior
  • Not is student

24. Condition

  • IFClass = 1 THEN
  • OUTPUT Freshman
  • ELSEIF Class = 2 THEN
  • OUTPUT Sophomore
  • ELSEIF Class = 3 THEN
  • OUTPUT Junior
  • ELSEIF Class = 4 THEN
  • OUTPUT Senior
  • ELSE
  • OUTPUTNot is Student

25. Problem Definition

  • INPUT
    • Class( ) Integer
  • PROCESS
    • ( condition )
  • OUTPUT

26. 27. 28. 29. Example-2

  • (Book Shop)2 (News paper) (Magazine) 5% Not Sale 1News paper 2Magazine Textbox

30. 31. 32. 33. 34.