0% found this document useful (0 votes)
13 views18 pages

FUNCTIONS 'O' Level

The document provides an overview of functions in programming, explaining their characteristics, types, and examples of built-in functions. It details string manipulation functions, conversion functions, and includes code snippets demonstrating their usage. Additionally, it covers random number generation and mathematical operations using functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views18 pages

FUNCTIONS 'O' Level

The document provides an overview of functions in programming, explaining their characteristics, types, and examples of built-in functions. It details string manipulation functions, conversion functions, and includes code snippets demonstrating their usage. Additionally, it covers random number generation and mathematical operations using functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

FUNCTIONS

DEF

 A function is a self contained module that returns a value to the part


of a program which call it every time it is called or executed.
 OR it is a block of code that perform a specific task and returns a
value.

CHARACTERISTICS
 It has a name just like variables.
 Takes zero or more arguments (also known as parameters)

 Performs some calculations or operations.


 A function returns a value.
CONT…..

 Functions can be in_ built or user defined


IN_BUILT FUNCTIONS

 Are already available for use in your library. Eg


1) Math. Abs()- returns the absolute value of a number.
2) Math. Sqrt () – returns the square root of a number
3) String. Length () – returns the length of a string.
4) String. ToUpper () – convert a string to uppercase.
5) Convert. ToInt32() – convert a value to an integer.
CONVERSION FUNCTIONS

 Are functions that convert one type of data to another.


 Most of the functions start with letter “C” e.g
 Cbool, Cbyte, Ccur, Cdate, CDbl, CSng,CLng, CStr,Cvar e.t.c
 Val and Str functions enable you to convert from string to a number
and from a number to a string respectively.
SRING FUNCTIONS

 Functions that have a non – numeric result in most cases.


 Used to manipulate a string or query information about a string.e.g
THE LEN FUNCTION
 Used to find out number of characters in any given string.
SYNTAX - Len(string)
THE MID FUNCTION
 used to return a substring containing a specified number of characters from a
string.
SYNTAX – Mid(string, start[, length])
 String - string expression from which characters are returned.
 Start - long. Character position in string at which the part to taken begins.
 Length – length is optional. Number of characters t return
CONT…

 THE LEFT FUNCTION


 extract the left Portion of a string
 SYNTAX – Left (“string”,n)
THE RIGHT FUNCTION
 Extract the right portion of a string
 SYNTAX – Right (“String”, n )
THE SPACE FUNCTION
 Used to return a string containing a specified number of blank space.
THE UCASE AND LCASE
 Used to convert all characters of a string form lower case to capital letters
 Lcase convert all character of a string from uppercase to small letters
RESERVED WORD

 INTERFACE
CODE

Dim word As String


word = TextBox1.Text
Dim reversedword As String = StrReverse(word)
TextBox2.Text = reversedword
CODE 2

 Dim inputstring As String = TextBox1.Text


 Dim reversedString As String = ""
 For i As Integer = inputstring.Length - 1 To 0 Step -1
 reversedString &= inputstring(i)
 Next
 TextBox2.Text = reversedString
 End Sub
OUTPUT
CHARACTER COUNT IN A STRING

INTERFACE
CODE

Dim inputword As String = TextBox1.Text


Dim charactercount As Integer = Len(inputword)
lbldisplay.Text = "Number of characters- " & charactercount.ToString
OUTPUT
RANDOM FUNCTION

USING CONSOLE APPLICATION

IMPORTS SYSTEM.CONSOLE
MODULE RANDOMEXAMPLE
Sub main()
Dim rand as new random
Dim num as integer
For i as integer = 1 to 10
Num = rand.next(1,10)
Writeline(num)
Next I
Readkey ()
WINDOWS APPLICATION

Dim num as integer


Randomize()
Num = Int(Rand()* 6) + 1
Lbldisplay.text = num

OR
Dim rand as new randpm
Dim numrand as integer
Numrand – rand. Next (1,7)
Lbldisplay.text
UCASE PROGRAM

 Dim inputword As String = TextBox1.Text


 Dim smallLetters As String = UCase(inputword)
 TextBox2.Text = smallLetters
OUTPUT
MATH.SQRT

CODE
 Dim inputNumber As Integer = TextBox1.Text
 Dim root As Double = Math.Sqrt(inputNumber)
 TextBox2.Text = root

You might also like