Slide 1 VB Programming Fundamentals. Slide 2 Visual Basic Language v VB language is powerful and easy to use v Descendent of BASIC (Beginner's All-Purpose.

Slides:



Advertisements
Similar presentations
CSI 1306 PROGRAMMING IN VISUAL BASIC PART 2. Part 2  1. Strings  2. Translating Conditional Branch Instructions  3. Translation Set 2  4. Debugging.
Advertisements

Manipulating Strings String Functions. VB provides a large number of functions that facilitate working with strings. These are found in Microsoft.VisualBasic.Strings.
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Types and Arithmetic Operators
The number of calories burned per hour by cycling, jogging and swimming are 200, 475 and 275 respectively. A person loses 1pound of weight for each 3500.
1 Chapter 3 Arithmetic Expressions. 2 Chapter 3 Topics l Overview of Java Data Types l Numeric Data Types l Declarations for Numeric Expressions l Simple.
1 Pertemuan 04 Expression Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Strings in Visual Basic Words, Phrases, and Spaces.
Introduction to Computing Dr. Nadeem A Khan. Lecture 6.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
JavaScript, Fourth Edition
JavaScript, Third Edition
On to… string operations & functions. Concatenation (&) §When we want to combine two character strings into one new (longer) string, we can concatenate.
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
Variables & Math Operators CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Chapter 5 new The Do…Loop Statement
BACS 287 Visual Basic String Manipulation. BACS 287 Visual Basic Strings In Visual Basic, a “string” is a series of text, numbers, and special characters.
Chapter 9 Creating Formulas that Manipulate Text Microsoft Office Excel 2003.
Strings PART II STRING$ AND SPACE$. Create strings of specified number String$ creates string of specified character Space$ creates string of spaces Example:
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
2440: 211 Interactive Web Programming Expressions & Operators.
Manipulation Masterclass By the VB Gods. In this masterclass, we will learn how to use some of the string manipulation function such as Len, Right, Left,
CS0004: Introduction to Programming Variables – Strings.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
Microsoft Visual Basic 2005 BASICS Lesson 4 Mathematical Operators.
Visual Basic.NET BASICS Lesson 4 Mathematical Operators.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
CIS 338: Operators and Formatting in VB.NET Dr. Ralph D. Westfall April, 2011.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
Manipulating Strings. What is a string? Data composed of text characters. The data is stored in consecutive bytes of memory. Each byte stores the ASCII.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Variables, Expressions and Statements
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
Doing math In java.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Numbers1 Working with Numbers There are times that we have to work with numerical values. When we count things, we need Integers or whole numbers. When.
CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu.
PYTHON VARIABLES : CHAPTER 2 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
Tutorial 4: The Selection Structure 1 Tutorial 4 The Selection Structure.
1 Inside Module 8 Extracting Data Page n Using the Extract command2 n Coercion3 n $-functions4 n Extract from a table7.
Strings PART I STRINGS, DATES, AND TIMES. FUNDAMENTALS OF CHARATERS AND STRINGS VB represents characters using American National Standards Institute(ANSI)
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
CHAPTER FOUR Performing Calculations and Manipulating Data: Expressions.
Gollis University Faculty of Computer Engineering Chapter Five: Retrieval, Functions Instructor: Mukhtar M Ali “Hakaale” BCS.
1 VB-06-String Manipulation Mar 03, 2002 String Function VISUAL BASIC.
CSC 162 Visual Basic I Programming. String Functions LTrim( string ) –Removes leading spaces from the left side of string RTrim( string ) –Removes trailing.
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.
13/06/ Strings Left, Right and Trim. 213/06/2016 Learning Objectives Explain what the Left, Right and Trim functions do.
Introduction to Python Lesson 2a Print and Types.
Topics Designing a Program Input, Processing, and Output
Open Source Server Side Scripting MySQL Functions
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
Visual Basic Variables
Multiple variables can be created in one declaration
Variables, Expressions, and IO
VB Math All of your favorite mathematical operators are available in VB: + Addition - Subtraction * Multiplication / Division \ Integer Division Mod Modulo.
Sub Procedures and Functions
VBScript Session 10.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
MapInfo SQL String Functions
Lecture 5 SQL FUNCTIONS.
Presentation transcript:

Slide 1 VB Programming Fundamentals

Slide 2 Visual Basic Language v VB language is powerful and easy to use v Descendent of BASIC (Beginner's All-Purpose Symbolic Instruction Code)

Slide 3 Assignment Statement v Variable_name = value v Examples: –x = 5 –sName = “Ali” –fAgerage = nTotal / nNum –sFullName = sFName & “ “ & sLName –sCapitalName = UCase(“Mohammed”)

Slide 4 Mathematical Operations Operation Operator Addition + Subtraction - Multiplication * Division / Integer division \ Modulus mod Exponentiation ^ v Example: (115 + Val(txtAmount.Text)) / 69 * 1.098

Slide 5 Addition and Subtraction v Addition –result = number1 + number2 [+ number3] u result = v Subtraction –result = number1 - number2 [- number3] u result =

Slide 6 Multiplication and Division v Multiplication –result = number1 * number2 [* number3] u result = 15 * 6 * 3 v Division –Floating point division (/) u result = number1 / number2 [/ number3] u 4 / 3 = 1.33 –Integer division (\) u result = number1 \ number2 [\ number3] u 4 \ 3 = 1 –Modulus or remainder u result = number1 mod number2 [mod number3] u 20 mod 3 = 2

Slide 7 Exponentiation (power) v Exponential operator (^) v Examples: Sample Exponent Function Performed 3 ^ 2 = 9 This is the square of the number. 9 ^ 0.5 = 3 This is the square root of the number. 2 ^ –2 = 0.25 A fraction is obtained by using a negative exponent.

Slide 8 Operator Precedence v 4 * / 2 = ? v Operator evaluation order: –Exponentiation (^) –Negation (-) –Multiplication and division (*, /) –Integer division (\) –Modulus arithmetic (Mod) –Addition and subtraction (+, -) v Control the order with parentheses () –4 * (3 + 6) / 2

Slide 9 String Operations v UCase and LCase : Change the case of text to all uppercase or all lowercase, respectively v InStr and InStrRev : Find the location of one string contained within another v Left and Right : Retrieve a selected number of characters from one end of a string v Mid : Retrieves or replaces a selected number of characters in a string v LTrim, RTrim, and Trim : Remove spaces from one or both end(s) of a string v Len : Returns the length of a string v Chr and Asc : Work with a single character’s ASCII code v Str, CStr, and Val : Convert a number or expression to a string, and vice versa v Replace : Finds and replaces within a string v StrReverse : Reverses the order of characters in a string

Slide 10 String Concatenation v Concatenation operator (&) v newstring = stringexpr1 & stringexpr2 [& stringexpr3] sFullName = “Mr.” & “ “ & “Ali”  “Mr. Ali” v Use double quotes to mark the start and end of strings

Slide 11 String Length v result = Len(inputstr) v result = Len(“Mohammed”)  8

Slide 12 Changing the Case of a String v UCase(): changes a string to Upper case v LCase(): changes a string to Lower case v Result = UCase(“Ali”)  “ALI” v Result = LCase(“Ali”)  “ali” v Example: Dim sWord as String, sProperWord as String sWord=”mIxEd CaSe” sProperWord = UCase$(Left$(sWord, 1)) sProperWord = sProperWord & LCase$(Mid$(sWord,2))

Slide 13 Searching a String v chrpos = InStr(sourcestr, searchstr) –Charpos = Instr(“I’ll see you next Tuesday.”,”you”)  10 v chrpos = InStr(StartPos, sourcestr, searchstr) –Charpos = Instr(11, “I’ll see you next Tuesday.”,”y”)  25 v chrpos = InStr(StartPos, sourcestr, searchstr, 1) –0 is case sensitive search (default) –1 is case insensitive search

Slide 14 Extracting Pieces of a String v Left - Retrieves a specified number of characters from the left end of a string v Right - Retrieves a specified number of characters from the right end of a string v Mid - Retrieves characters from the middle of a string v OutStr = Left$(InptStr, NumChars) v OutStr = Right$(InptStr, NumChars) v OutStr = Mid(InptStr, startpos[, numchars]) –Mid(“Robert Allen”,8) ‘Returns “Allen” –Mid(“Robert Allen”,8,2) ‘Returns “Al”

Slide 15 Getting Rid of Spaces v LTrim — Removes the spaces from the beginning of a string v RTrim — Removes the spaces from the end of string v Trim — Removes the spaces from both the beginning and end of a string v LTrim(“ Hello, world! ”)  “Hello, world! ” v RTrim(“ Hello, world! ”)  “ Hello, world!” v Trim(“ Hello, world! ”)  “Hello, world!”

Slide 16 Replacing Characters in a String v Mid function can be used to replace part of a string v Mid(sourcestr, startpos[, numchars]) = replstr

Slide 17 Formatting Results Print FormatDateTime(“20:10”,vbLongTime)

Slide 18 Rounding Numbers v Round(202.5) ‘Returns 202 v Round(202.56) ‘Returns 203 v Round(202.56,1) ‘Returns v Round(202.56,2) ‘Returns v Round(202,4) ‘Returns 202 – no decimal places

Slide 19 Format Function v Formatting Numbers –Format(GrossSales, “Currency”) –Format(GrossSales, “$####.00”)

Slide 20 Numeric Format v Format(TotalDistance, “##,##0.0000”)

Slide 21 Date and Time Format Format(Now,”mm/dd/yyyy”)