### Programming (OLD) - Library Functions

CBSE Class 12 Informatics Practices

Revision Notes
Chapter - 7
Library Functions

Library Functions: Library functions are those In-build functions that are already available in VB. In particular, all input and output operations (e.g., writing to the terminal) and all math operations (e.g., evaluation of sines and cosines) are implemented by library functions

Types of Library Functions:
• STRING FUNCTIONS
• NUMERIC FUNCTIONS
• DATE & TIME FUCTIONS

• STRING FUNCTIONS String functions are used to work with strings in numerous ways such as changing their cases, extracting some characters from a string, determining whether a character is part of string etc.

• VARIOUS STRING FUNCTIONS ARE:
1. Lcase and Ucase functions
2. Len function
3. Trim, LTrim and RTrim functions
4. Left and Right functions
5. Mid function and Mid statement
6. Instr function
7. Space function
8. String function
9. Str function
10. ASC function
11. Chr function
12. StrReverse function

1. Lcase and Ucase functions:
Lcase ( ): This function converts a given string into all lower case.
Syntax: Lcase(string)
Example: Print Lcase(“SCHOOL”)
Output: school
Ucase ( ): This function converts a given string into all lower case.
Syntax: Ucase(string)
Example: Print Ucase(“school”)
Output: SCHOOL

2. Len ( ): This function gives the length of the string i. e. how many characters long the string
is. All characters are counted including spaces and punctuation.
Syntax: Len(string)
Example: Len(“kendriya vidyalaya”)
Output: 18

3. Trim, LTrim and RTrim : LTrim (): This function removes leading spaces from a string.
Syntax: LTrim(string)
Example: LTrim(“ kendriya”)
Output: kendriya
4. RTrim(): This function removes trailing spaces from a string.
Syntax: RTrim(string)
Example: RTrim(“kendriya ”)
Output: kendriya
5. Trim (): This function removes all leading as well as trailing spaces from a string.
Syntax: Trim(string)
Example: Trim(“ kendriya ”)
Output: kendriya

6. Left and Right ( ) :
Left ( ):
This function is used to extract a certain number of characters from the
leftmost portion of string.
Syntax: Left(string,no-of chars)
Example: Left(“vidyalaya”,5)
Output: vidya
Right ( ): This function is used to extract a certain number of characters from the
rightmost portion of string.
Syntax: Right(string,no-of chars)
Example: Right(“vidyalaya”,3)
Output: aya

7. Mid ( ): Mid function is used to extract Character from the middle of the given string,
SYNTAX: MID (STRING, START_POSITION, NO_OF_CHAR)
EG: - Dim S as String
S = “Study Material for Bright Students”
PRINT MID(A,20,6) ‘ Will print Bright.

8. Mid statement not only extracts the character but also replaces them with the text we specify.
St = “Computer Science” ‘St contain Computer Science this time.
Mid (St, 9, l) = ‘ - '
Print St ‘Now St will contain Computer-Science.

9. Instr ( ): Instr function searches for strings within string. This function also needs three arguments.
SYNTAX: INSTR(Start, Stl, St2, Compare)
- The first argument is the position in the string to start searching.
- The second argument is the string to search in.
- The third argument is the string to search for and
- The last argument is whether or not you want a case sensitive search. (0 for yes,1 for no)

Compare: 0 - for case sensitive search (Binary Comparison), It is by default search.
1 - for ignoring case (Text Comparison).
Eg: Print Instr (1, “Bright Students”,”T”) ‘will print 0
Print Instr (1, “Bright Students”,”t”) ‘will print 6
Print Instr (7, “Bright Students”,”T”) ‘will print 9

10. Space ( ): This function by itself produces a certain number of spaces.
Syntax: space (number)
Example:
Dim a, c As String
a = Space(10)
c = "ok" & a & "bye"
Print c
Output: ok bye

11. String ( ): This function is used for producing a string with a certain number of repeating characters.
Syntax: String(number, character)
The first argument is the number of characters.
The second argument is the character code to repeat.
Example:

 Dim a As String Dim a As String a = String(5, "a") a = String(5, "abc") Print a Print a Output: aaaaa Output: aaaaa

12. Str ( ): This function converts a number into equivalent string.
Syntax : str(number, character)
Example:

 Dim a As String Dim a As String a = String(5, "a") a = String(5, "abc") Print a Print a Output: aaaaa Output: aaaaa

13. ASC ( ): This function is used to get a character’s equivalent ASCIIcode.
Syntax: ASC(string)
Example:
Dim a, b As String
a = "India"
b = Asc(a)
Print b
Output: 7 3

14. Chr ( ): This function returns a string containing the character associated with the specified character code.
Syntax: chr(charcode)
Example:
Dim a As String a = Chr(65)
Print a Output: A

15. StrReverse ( ): This function returns a string in which the character order ofa specified string is reversed.
Syntax: StrReverse(string)
Example:
Dim a, b As String
M 1 M
a = abc
b = StrReverse (a)
Print b
Output: cba• VARIOUS NUMERIC FUNCTIONS ARE:
16. Int ( ) and Fix ( ) :- This function simply truncates the fractional part .
Syntax :- Int(Number)
Example :- Int ()
Output :- 14
Syntax: :- Fix(Number)
Example :- Fix (-14)
Output : - -14

DATE and TIME FUNCTIONS: This section deals with various date and time functions.

17. Now ( ):- It Returns current date and time.
Syntax: Now ( )
Output: Today’s date and Current Time.
Example: 1- 23-2009 03:23:38 PM

18. Date ( ): This function returns the current date in Variant type in following format
Syntax: Date ( )
Output: 16/6/08

19. Date\$( ): This function returns the current date in String type in following format.
Syntax: Date\$ ( )
Output: 01-23-2009

Numeric Function : VB supports many Numeric functions that can make your complicated work very easy.

1. Abs : Returns the absolute value of a number.
Syntax : Abs(number)

2. Exp : Returns the value of raised to a power
Syntax : Exp(Number)

3. Int : This standard VB function returns the integer part of a number.
Syntax : Int(number)

4. Rnd : This standard VB function returns a single-precision random number between 0 and 1.   Syntax : Rnd[(number)]

5. Sqr : This standard VB function returns the square root of a number.
Syntax :  Sqr(number)