Download presentation

Presentation is loading. Please wait.

Published byMeryl Miles Modified about 1 year ago

1
Slide 1 VB Programming Fundamentals

2
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)

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

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

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

6
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

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

8
Slide 8 Operator Precedence v 4 * 3 + 6 / 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

9
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

10
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

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

12
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))

13
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

14
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”

15
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!”

16
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

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

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

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

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

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

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google