Docsity

Visual Basic Predefined Functions: A Comprehensive Guide - Prof. Nancy Mccracken, Study notes of Information Technology

Toggle sidebar
bg1
Visual Basic Predefined Functions
Each function has a name and takes a number of parameters, given in
parentheses. Each function also returns a value that can be used in a program.
Examples of using the function called StrReverse:
Dim Mystring As String
Mystring = StrReverse ( “MIRROR”)
or Mystring = “MY” & StrReverse ( “MIRROR”)
Examples of using the function called InStr:
Dim position As Integer
position = InStr ( “Cadillac”, “a” )
or position = 15 + InStr ( “Cadillac”, “a” )
String Functions: Syntax: Use:
Asc Asc(char) Returns the ASCII key code of a character; for
example Asc(“A”) returns 65
Chr Chr(int) Returns a character that is associated with the
ASCII value of the integer; for example Chr(66)
returns “B”
Val Val(string) Converts the string to numeric value; for
example Val(“-23.5) returns -23.5 (as a double)
Str Str(int) Converts an integer into a string; for example
Str(-32.5) returns “-32.5”
StrReverse StrReverse(S) Returns a string in the mirror image of the string
S; for example StrReverse(“MIRROR”) returns
“RORRIM”
LCase LCase(S) Returns a string of all lowercase letters of the
string S; for example LCase(“LOWer”) returns
“lower”
UCase UCase(S) Returns a string of all uppercase letters of the
string S; for example UCase(“uppER”) returns
“UPPER”
Space Space(n) Generates a string of n number of spaces; for
example Space(1) returns “ “
StrDup StrDup(n, char) Generates a string with n number of repetitive
characters; for example StrDup(3, “Z”) returns
“ZZZ”
pf3

Partial preview of the text

Download Visual Basic Predefined Functions: A Comprehensive Guide - Prof. Nancy Mccracken and more Study notes Information Technology in PDF only on Docsity!

Visual Basic Predefined Functions

Each function has a name and takes a number of parameters, given in

parentheses. Each function also returns a value that can be used in a program.

Examples of using the function called StrReverse:

Dim Mystring As String

Mystring = StrReverse ( “MIRROR”)

or Mystring = “MY” & StrReverse ( “MIRROR”)

Examples of using the function called InStr:

Dim position As Integer

position = InStr ( “Cadillac”, “a” )

or position = 15 + InStr ( “Cadillac”, “a” )

String Functions: Syntax: Use:

Asc Asc( char ) Returns the ASCII key code of a character; for example Asc(“A”) returns 65

Chr Chr( int) Returns a character that is associated with the ASCII value of the integer; for example Chr(66) returns “ B”

Val Val( string) Converts the string to numeric value; for example Val(“-23.5) returns -23.5 (as a double)

Str Str( int ) Converts an integer into a string; for example Str(-32.5) returns “-32.5”

StrReverse StrReverse( S ) Returns a string in the mirror image of the string S; for example StrReverse(“MIRROR”) returns “RORRIM”

LCase LCase( S ) Returns a string of all lowercase letters of the string S; for example LCase(“LOWer”) returns “lower”

UCase UCase( S ) Returns a string of all uppercase letters of the string S; for example UCase(“uppER”) returns “UPPER”

Space Space( n ) Generates a string of n number of spaces; for example Space(1) returns “ “

StrDup StrDup( n, char ) Generates a string with n number of repetitive characters; for example StrDup(3, “Z”) returns “ZZZ”

Left Strings.Left( S, n ) Returns a string with the first n characters of the string S; for example Strings.Left(“My Cats”, 2) returns “My”

Right Strings.Right( S, n ) Returns a string with the first n characters of the string S; for example Strings.Right(“My Cats”, 3) returns “ats”

Mid 1) Mid(S, b) Returns a string starting from the bth place of the string S; for example Mid(“My Cats”, 2) -or- returns “y Cats”

  1. Mid( S, b, n ) Returns a string of n characters starting at the bth place of the string S; for example Mid(“My Cats”, 2, 3) returns “y C”

InStr 1) InStr( S, m ) Returns the position in the string S at which the content matches the string m; for example -or- InStr(“Cadillac”, “a”) returns 2 Or returns 0 if there is no match.

  1. InStr ( b, S, m ) Returns the position in the string S at which the content matches the string m. The comparison will start from the bth position of S; for example InStr(4, “Cadillac”, “a”) returns 7 Or returns 0 if no match from that position.

InStrRev 1) InStrRev( S, m ) Returns the position in the string S at which the content matches the string m. The comparison starts from the last position of S for example -or- InStr(“Science”, “c”) returns 6

  1. InStrRev ( S, m, b ) Returns the position in the string S at which the content matches the string m. The comparison will start from the bth position of S, and work its way to the beginning of the string; for example InStr(“Science”, “c”, 5) returns 2

Len Len( string ) Returns the integer length of the string; for example Len(“Hello”) returns 5

LTrim LTrim( string ) Returns a string with all the leading blank spaces trimmed off; for example LTrim(“ Hello “) returns “Hello “

RTrim RTrim( string ) Returns a string with all the trailing blank spaces trimmed off; for example RTrim(“ Hello “) returns “ Hello“

Trim RTrim( string ) Returns a string with all the leading and trailing blank spaces trimmed off; for example Trim(“ Hello “) returns “Hello“