Download presentation
Presentation is loading. Please wait.
Published byNeil Morton Modified over 8 years ago
1
CSC 162 Visual Basic I Programming
2
Selection Structures If/Then (single selection) If/Then/Else (double selection) If/Then/ElseIf (multiple selection) Select Case (multiple selection)
3
Select Case Select Case Selector Case Label 1 Statements 1 Case Label 2 Statements 2. Case Else Statements n End Select
4
Select Case The Selector can be of any data type. The Label can take on several formats: –A single value: Case 65 –An inclusive range: Case 70 To 80 ' includes 70 and 80 –A range: Case Is >= 90 –A set of values: Case 2, 4, 6, 8 –A combination: Case 25, 30 To 40, 75 The Case Else is optional. There can be one or more statements under each Case.
5
Example 1 Select Case sngGrade Case Is > 90 txtGrade.Text = "A" Case Is > 80 txtGrade.Text = "B" Case Is > 70 txtGrade.Text = "C" Case Is > 65 txtGrade.Text = "D" Case Else txtGrade.Text = "F" End Select
6
Example 2 intUserChoice = MsgBox("Would you like fries with that?", _ vbYesNoCancel, "Mickey D's") Select Case intUserChoice Case vbYes sngCost = sngCost + FRIES Print "Fries -- YES" Case vbNo Print "Fries -- NO" Case Else Print "Fries -- No response" End Select
7
Visual Basic Data Types Refer to previous handout for a full list of types and naming conventions. The Variant data type automatically changes its type to reflect its data. Do not use this type. It is poor programming practice, since you should know what type of data a variable will receive. Instead of declaring ( dim -ing) all your variables, Visual Basic supports type declaration suffixes. However, this too should be avoided. Instead, explicitly declare your variables. Data TypeSuffixExample Currency@ (At sign) Total@ = 7.95 Double# (Pound sign) Length# = 0.02437653762374 Integer% (Percent sign) Counter% = 45 Long& (Ampersand) Population& = 5543217869614 Single! (Exclamation Point) TaxRate! = 0.0725 String$ (Dollar Sign) Name$ = "Smith, John"
8
.Cls Method To clear printed output from a form, use the.Cls method. A method is what Visual Basic calls an object’s command—it affects what the object does. This is different from a property, which affects what an object is. Example: frmOutput.Cls The above statement clears everything that has been printed onto the form frmOutput.
9
Homework Read Chapter 5 (Pages 129 – 176) Exercises Pages 172 – 176 #5.6, 5.10 – 5.14 Lab Assignment Page 175 #5.16
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.