Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.

Slides:



Advertisements
Similar presentations
Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
Advertisements

Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Slide 1 VB Program Flow Control. Slide 2 Making Decisions v Decision Statement: control the execution of parts of the program based on conditions. v The.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Chapter 2: Introduction to C++.
Introduction to C Programming
VB .NET Programming Fundamentals
CPS120: Introduction to Computer Science Lecture 8.
Variables and Constants
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
A Review of Programming and C++
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1A) UTPA – Fall 2011.
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
2440: 211 Interactive Web Programming Expressions & Operators.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Lecture #5 Introduction to C++
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
CPS120: Introduction to Computer Science Operations Lecture 9.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Chapter 2 Variables.
Computing and Statistical Data Analysis Lecture 2 Glen Cowan RHUL Physics Computing and Statistical Data Analysis Variables, types: int, float, double,
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Data And Variables Chapter Names vs. Values Michael Jordan name (the letter sequence used to refer to something) value (the thing itself)
CIVIL AND GEOMATIC ENGINEERING FT Okyere. CIV 257- COMPUTER PROGRAMMING Lecture 3.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 2 Variables.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Visual Basic Variables
Chapter 2 - Introduction to C Programming
Visual Basic 6 (VB6) Data Types, And Operators
ITEC113 Algorithms and Programming Techniques
Revision Lecture
Multiple variables can be created in one declaration
The Selection Structure
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 8 JavaScript: Control Statements, Part 2
Chapter 2 - Introduction to C Programming
Chapter 2 Variables.
T. Jumana Abu Shmais – AOU - Riyadh
CSI 101 Elements of Computing Spring 2009
Chapter 2 - Introduction to C Programming
Fundamentals of visual basic
Chapter 2 - Introduction to C Programming
Primitive Types and Expressions
Chapter 2 Variables.
Introduction to C Programming
Presentation transcript:

Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals

Comment Comment is a line in a program which is ignored by the compiler (i.e. it is not translated by the compiler) Comment is a line in a program which is ignored by the compiler (i.e. it is not translated by the compiler) In VB, a comment starts with ‘ (Single Quotation) In VB, a comment starts with ‘ (Single Quotation)

Keyword Every language has some reserved words that conveys some special meaning to the compiler, such words are called keywords Every language has some reserved words that conveys some special meaning to the compiler, such words are called keywords E.g. dim, if, end, … are keywords in VB E.g. dim, if, end, … are keywords in VB

Storing information in variables The first line of code is a Dim, or Dimension, statement, used for dimensioning (or declaring) variables. The first line of code is a Dim, or Dimension, statement, used for dimensioning (or declaring) variables. Example: Dim Num As Integer Dim Name As String Dim Price As Single

Naming Convention for variables The name must start with a letter, not a number or other character. The name must start with a letter, not a number or other character. The remainder of the name can contain letters, numbers, and/or underscore characters. No spaces, periods, or other punctuation characters are allowed. The remainder of the name can contain letters, numbers, and/or underscore characters. No spaces, periods, or other punctuation characters are allowed. The name must be unique within the variable's scope. (Scope refers to the context in which the variable is defined) The name must be unique within the variable's scope. (Scope refers to the context in which the variable is defined) The name cannot be one of Visual Basic's reserved words. The name cannot be one of Visual Basic's reserved words.

Examples Valid variable names: Valid variable names: a, test, a_test, a3798test89, absd_s3_ew Invalid variable names: Invalid variable names: a.test, a test, 3589a, dim, decimal

Changes to the Dim Statement Multiple declarations of the same type are now easier, as in the following example: Multiple declarations of the same type are now easier, as in the following example: Dim x, y As Integer Dim x, y As Integer The ability to initialize a variable within the Dim statement. The ability to initialize a variable within the Dim statement. Dim No_of_Cars As Integer = 10 Dim No_of_Cars As Integer = 10 ** Initialization only works for one-variable Dim statements.

Understanding Data Types Visual Basic.NET Data Type Values Stored Example BooleanTrue/FalseTrue Char Single Character “A” Date Dates and Times 12/21/ :00 PM Decimal Decimal or Whole 19.95D, Double Decimal Numbers 1.23E-10 Integer Whole Numbers 6753 Long Single Decimal Numbers Short Whole Numbers StringCharacters“HELLO”

Understanding Data Types Data Type Size (B) Range Boolean2 True or False Date8 January 1,100 to December 31,9999 short2 -32,768 to 32,767 Integer4 -2,147,483,648 to 2,147,483,647 Long8 19 digits Single4 -ve no: E38 to E-45 +ve no: E-45 to E38 Double8 -ve no: E308 to E-324 +ve no: E-324 to E308 Decimal16 Up to 28 digits to the left or right of.

Using Math Operations OperationOperator Addition+ Subtraction- Multiplication* Division/ Integer division \ ModulusMod Exponentiation^

Addition and Subtraction Using the Addition Operator Using the Addition Operator result = number1 + number2[+ number3] result = number1 + number2[+ number3] result = result = Using the Subtraction Operator Using the Subtraction Operator result = number1 - number2[- number3] result = number1 - number2[- number3] result = result =

Multiplication and Division Using the Multiplication Operator Using the Multiplication Operator result = number1* number2 [* number3] Using the Division Operators Using the Division Operators result = number1 / number2 [/ number3] result = 4/3 ‘will return result = number1 \ number2 [\ number3] result = 4\3 ‘will return 1

Modulus and Exponentiation Using the Modulus Operator Using the Modulus Operator result = number1 mod number2 result = 20 mod 3 ‘will return 2 Using the Exponentiation Operator Using the Exponentiation Operator answer = number1 ^ exponent answer = 3 ^ 2 ‘will return 9

Incrementing the Value of a Variable One frequent use of variables is a counter, where the same variable can be updated with the result of an equation. One frequent use of variables is a counter, where the same variable can be updated with the result of an equation. intNumber = intNumber + 1 (Shortcut: intNumber += 1) intNumber = intNumber – 1 (Shortcut: intNumber -= 1)

Operator Precedence Exponentiation (^) Exponentiation (^) Negation (-) Negation (-) Multiplication and division (*, /) Multiplication and division (*, /) Integer division (\) Integer division (\) Modulus arithmetic (Mod) Modulus arithmetic (Mod) Addition and subtraction (+, -) Addition and subtraction (+, -) Important Note: You can override normal operator precedence by using parentheses to group sub-expressions that you want to be evaluated first.

Controlling the Flow of Your Program Control statements: Control statements: Without control statements, your program would start at the first line of code and proceed line by line until the last line was reached, at which point the program would stop. Without control statements, your program would start at the first line of code and proceed line by line until the last line was reached, at which point the program would stop. Two types: Two types: Decision statement Decision statement Loop Loop

Control statements Decision statement: Decision statement: This statement is used to control the execution of parts of your program, based on conditions that exist at the time the statement is encountered. This statement is used to control the execution of parts of your program, based on conditions that exist at the time the statement is encountered. Two basic types of decision statements are :- If statement and Select Case statement

Control statements Loops: Loops: Loops are used to perform repetitive tasks in a program. Loops are used to perform repetitive tasks in a program. Three main types of loops are :- Counter Loops (For loop) Counter Loops (For loop) Conditional Loops (Do loop) Conditional Loops (Do loop) Enumerator loops (For Each loop) Enumerator loops (For Each loop)

Loops Counter, or For, loops perform a task a set number of times. Counter, or For, loops perform a task a set number of times. Conditional, or Do, loops perform a task while a specified condition exists or until a specified condition exists. Conditional, or Do, loops perform a task while a specified condition exists or until a specified condition exists. Enumerator loops are used to perform an action on each item in a group of objects. Enumerator loops are used to perform an action on each item in a group of objects.

Understanding If Statements Syntax: If condition Then command Example: 'Single-Line IF If x > 5 then x = 0 'Multiple-Line IF If x > 5 Then x = 0 End If

Understanding If Statements Using Multiple Commands within an If Block Using Multiple Commands within an If Block Example: If DepositAmt > 0 Then TotalPaid = TotalPaid + DepositAmt TotalPaid = TotalPaid + DepositAmt DepositAmt = 0 DepositAmt = 0 End If End If

Understanding If Statements Working with the False Condition Working with the False ConditionSyntax: If condition Then statements to process when condition is True statements to process when condition is TrueElse statements to process when condition is False statements to process when condition is False End If

Understanding If Statements Working with Multiple If Statements Working with Multiple If Statements The ElseIf statement enables you to specify another condition to evaluate when the first condition is False. The ElseIf statement enables you to specify another condition to evaluate when the first condition is False.Example: If TestValue < 0 Then lblResult.Text = "Negative" lblResult.Text = "Negative" ElseIf TestValue = 0 Then lblResult.Text = "Zero" lblResult.Text = "Zero"Else lblResult.Text = "Positive" lblResult.Text = "Positive" End If

Using Boolean Logic in If Conditions The logical operators used with True/False conditions are as follows: The logical operators used with True/False conditions are as follows: And — Expressions on both sides of the And must evaluate True for the result to be True. If one or more expressions in the And comparison is False, the result is False. And — Expressions on both sides of the And must evaluate True for the result to be True. If one or more expressions in the And comparison is False, the result is False. Or — If either side of an Or comparison is True, or both sides are True, then the result is True. The result of an Or is False only if both expressions are False. Or — If either side of an Or comparison is True, or both sides are True, then the result is True. The result of an Or is False only if both expressions are False.

Using Boolean Logic in If Conditions Xor — This stands for exclusive or. This operator is similar to Or but False if both sides are True. Not — Negates the result of an expression, Not True is False and Not False is True.

Boolean Operators xyx And y FFF FTF TFF TTT xyx Or y FFF FTT TFT TTT xyx Xor y FFF FTT TFT TTF xNot x FT TF

Using Boolean Logic in If Conditions IF username.text=“ahsan” And password.text = “123” Then lblMsg.text = “Welcome Ahsan” Else lblMsg.text = “Login Failed” End If

Working with Loops For Loops For Loops Dim i As Integer Dim i As Integer Dim Output As Integer = 0 Dim Output As Integer = 0 For i = 1 To 10 For i = 1 To 10 Output = Output + 1 Output = Output + 1 Next i Next i

Working with Loops Using Do While Statements Using Do While Statements Dim Counter As Integer = 0 Do While Counter < 10 Counter += 1 Counter += 1Loop

Working with Loops Using Do While Statements Using Do While Statements Dim Counter As Integer = 0 Do Counter += 1 Counter += 1 Loop While Counter < 10

Working with Loops Note Note Do not put the While condition clause in both the Do and the Loop statements because doing so causes an error when you try to run your program. Do not put the While condition clause in both the Do and the Loop statements because doing so causes an error when you try to run your program.