CSC 162 Visual Basic I Programming. Selection Structures If/Then (single selection) If/Then/Else (double selection) If/Then/ElseIf (multiple selection)

Slides:



Advertisements
Similar presentations
Ch. 3 Variables VB.Net Programming. Data Types Boolean – True or False values Short – Small integers (+/- 32,767) Integer – Medium-size integers (+/-
Advertisements

1 PHP  Introduction to PHP  Basic Syntax of PHP Variables, Constant, Data Type, Type Casting  Getting Data From Client  PHP Database Manipulation.
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Data-types, Variables, Operators & Functions.
Chapter 2 Basic Elements of Fortan
VBA Programming Session #2. Things to Review  Variables  Procedures: Subs & Functions  If…Then  For…Next.
Chapter 31 Fundamentals of Programming in VB(Continue I) Numbers Arithmetic Operations Variables Incrementing the Value of a Variable.
VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Information Processing: Data-types, Variables, Operators & Functions.
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
CS0004: Introduction to Programming Input and Output.
Chapter 4 The If…Then Statement
CHAPTER THREE Representing Data: Constants and Variables.
1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.
CSC 162 Visual Basic I Programming. Randomizing and Formatting Randomizing Formatting –User-Defined Formats –Named Numeric Formats.
Chapter 4: The Selection Process in Visual Basic.
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
ENGR 112 Decision Structures.
Access VBA Programming for Beginners - Class 2 - by Patrick Lasu
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1B) UTPA – Fall 2011.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
Visual Basic Programming
Arrays1 From time to time an object (a variable, a picture, a label or a command) does not serve as well as a set of objects of a similar kind addressed.
CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort.
Chapter 3 P. 1 Data - Variables and Constants Definition A variable is a value which can change during program execution. A constant is a value which can.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
CSIT 208, Section Instructor: P eter C hen Introduction to Programming with QBasic to Visual Basic Lecture 9.
Visual Basic Programming I 56:150 Information System Design.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Data And Variables Chapter Names vs. Values Michael Jordan name (the letter sequence used to refer to something) value (the thing itself)
Chapter 3 - Visual Basic Schneider Numeric Variables Used to store numbers Value is assigned by a statement of the form: numVar = expression The variable.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Slide 1 Controls v Control naming convention –Label: lblName –Command Button: cmdName –Text Box: txtName.
VB.NET 2008 Introduction to Variables Part 1. Overview.NET Languages –Source Code –Compiler –MSIL –CLR & Windows Variables –Data Types –Converting.
Controlling Program Flow with Decision Structures.
BMTRY 789 Lecture 6: Proc Sort, Random Number Generators, and Do Loops Readings – Chapters 5 & 6 Lab Problem - Brain Teaser Homework Due – HW 2 Homework.
Adding Code to the Option Button. Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
CSC 162 Visual Basic I Programming. Storage Classes Determines the “lifetime” of an identifier Types: –Automatic Default Memory is allocated for the variable.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.
More Visual Basic Code: if-then-else, for loops Controls: Multiple forms, List Boxes, Radio buttons, frames,
Making Interactive Programs with Visual Basic .NET
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Lesson 4: Introduction to Control Statements 4.1 Additional Operators Extended Assignment Operators –The assignment operator can be combined with the.
TUTORIAL 4 Visual Basic 6.0 Mr. Crone. Pseudocode Pseudocode is written language that is part-code part- English and helps a programmer to plan the layout.
CSIT 108 Review Visual Basic.NET Programming: From Problem Analysis to Program Design.
Visual Basic I Programming
IE 8580 Module 4: DIY Monte Carlo Simulation
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Chapter 5- Control Structures: Part 2
Visual Basic 6 (VB6) Data Types, And Operators
2. Understanding VB Variables
OPERATORS (2) CSC 111.
البرمجة بلغة فيجول بيسك ستوديو
Chapter 3: Introduction to Problem Solving and Control Statements
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 1/15/2019.
Data Types List Box Combo Box Checkbox Option Box Visual Basic 6.0
CHAPTER FOUR VARIABLES AND CONSTANTS
B065: PROGRAMMING Variables 2.
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 7/9/2019.
Presentation transcript:

CSC 162 Visual Basic I Programming

Selection Structures If/Then (single selection) If/Then/Else (double selection) If/Then/ElseIf (multiple selection) Select Case (multiple selection)

Select Case Select Case Selector Case Label 1 Statements 1 Case Label 2 Statements 2. Case Else Statements n End Select

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.

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

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

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 (At sign) = 7.95 Double# (Pound sign) Length# = Integer% (Percent sign) Counter% = 45 Long& (Ampersand) Population& = Single! (Exclamation Point) TaxRate! = String$ (Dollar Sign) Name$ = "Smith, John"

.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.

Homework Read Chapter 5 (Pages 129 – 176) Exercises Pages 172 – 176 #5.6, 5.10 – 5.14 Lab Assignment Page 175 #5.16