Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 1 Unit 7 Decisions (Cont.) and Message Boxes Chapter.

Similar presentations


Presentation on theme: "© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 1 Unit 7 Decisions (Cont.) and Message Boxes Chapter."— Presentation transcript:

1 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 1 Unit 7 Decisions (Cont.) and Message Boxes Chapter 4 Making Decisions and Working with Strings

2 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 2 The Message Box Sometimes You Need a Convenient Way to Display a Message to the User This Section Introduces the Messagebox.Show Method, Which Allows You to Display a Message in a Dialog Box

3 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 3 Message Box Arguments Message - text to display within the box Caption - title for the top bar of the box Buttons - indicates which buttons to display Icon - indicates icon to display DefaultButton - indicates which button corresponds to the Return Key Arguments are optional bottom to top

4 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 4 Buttons Argument Value - Description MessageBoxButtons.AbortRetryIgnore - Displays Abort, Retry, and Ignore buttons. MessageBoxButtons.OK - Displays only an OK button. MessageBoxButtons.OKCancel - Displays OK and Cancel buttons. MessageBoxButtons.RetryCancel - Display Retry and Cancel buttons. MessageBoxButtons.YesNo- -Displays Yes and No buttons. MessageBoxButtons.YesNoCancel - Displays Yes, No, and Cancel buttons.

5 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 5 Example Message Box MessageBox.Show("Do you wish to continue?", _ "Please Confirm", _ MessageBoxButtons.YesNo)

6 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 6 Which Button Was Clicked, I MessageBox returns a value indicating which button the user clicked:  DialogResult.Abort  DialogResult.Cancel  DialogResult.Ignore  DialogResult.No  DialogResult.OK  DialogResult.Retry  DialogResult.Yes

7 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 7 Which Button Was Clicked, II Dim result As Integer result = MessageBox.Show("Do you wish to continue?", _ "Please Confirm", MessageBoxButtons.YesNo) If result = DialogResult.Yes Then ' Perform an action here ElseIf result = DialogResult.No Then ' Perform another action here End If

8 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 8 The Select Case Statement In a Select Case Statement, One of Several Possible Actions Is Taken, Depending on the Value of an Expression

9 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 9 Select Case Statement Example, I Select Case Val(txtInput.Text) Case 1 MessageBox.Show("Day 1 is Monday.") Case 2 MessageBox.Show("Day 2 is Tuesday.") Case 3 MessageBox.Show("Day 3 is Wednesday.") Case 4 MessageBox.Show("Day 4 is Thursday.") Case 5 MessageBox.Show("Day 5 is Friday.") Case 6 MessageBox.Show("Day 6 is Saturday.") Case 7 MessageBox.Show("Day 7 is Sunday.") Case Else MessageBox.Show("That value is invalid.") End Select

10 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 10 Select Case Statement Example, II Select Case animal Case "Dogs", "Cats" MessageBox.Show ("House Pets") Case "Cows", "Pigs", "Goats" MessageBox.Show ("Farm Animals") Case "Lions", "Tigers", "Bears" MessageBox.Show ("Oh My!") End Select

11 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 11 Input Validation Input Validation Is the Process of Inspecting Input Values and Determining Whether They Are Valid

12 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 12 Validation Example ' Validate the input to ensure that ' no negative numbers were entered. If sales < 0 Or advance < 0 Then MessageBox.Show("Please enter positive numbers for " & _ " sales and/or advance pay.") EndIf

13 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 13 Radio Buttons and Check Boxes Radio Buttons Appear in Groups of Two or More, and Allow the User to Select One of Several Possible Options Check Boxes, Which May Appear Alone or in Groups, Allow the User to Make Yes/no or On/off Selections

14 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 14 Checking Radio Buttons in Code If radChoice1.Checked = True Then MessageBox.Show("You selected Choice 1") ElseIf radChoice2.Checked = True Then MessageBox.Show("You selected Choice 2") ElseIf radChoice3.Checked = True Then MessageBox.Show("You selected Choice 3") End If

15 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 15 Checking Check Boxes in Code If chkChoice4.Checked = True Then message = message & " and Choice 4" End If

16 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 16 Class-level Variables Class-level Variables Are Not Local to Any Procedure In a Form File They Are Declared Outside of Any Procedure, and May Be Accessed by Statements in Any Procedure in the Same Form

17 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 17 Advantages of Class-level Variables The scope of class-level variables include all of the procedures below the declaration in the file Hence, with the use of class-level variables, communication of information between modules is very easy

18 © 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 18 Disadvantages of Class-level Variables Class-level variables should be used sparingly - only when really needed Why? In larger programs, the uses of these variables will be more difficult to keep track of and hence tend to introduce bugs into the procedures


Download ppt "© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 7: Chapter 4: Slide 1 Unit 7 Decisions (Cont.) and Message Boxes Chapter."

Similar presentations


Ads by Google