Sunteți pe pagina 1din 20

DEPARTMENT OF TECHNICAL EDUCATION

ANDHRA PRADESH

Name : K. Sreeramacharyulu
Designation : Lecturer
Branch : Commercial and Computer Practice
Institute : Govt. Polytechnic, Srikakulam
Year/Semester : V Semester
Subject : VISUAL BASIC-I
Sub. Code : CCP-503
Topic : Programming Fundamentals
Duration : 50 Minutes
Sub. Topic : Built in Functions in VB
Teaching Aids : PPT, Clips and Images

CCP503.38 1
Objectives

On completion of this period , you would


be able to Know…

 Built in Functions or Library Functions

CCP503.38 2
Recap

 The concepts of User defined Function Sub-


Programs in VB

 The types of User defined Functions

CCP503.38 3
Library or Built-in Functions

 Classified as Math, String and Date and time


functions

 A built in function is pre-defined and can be used


with its name and arguments just like a user
defined function

CCP503.38 4
Some of Built-In functions:
String functions
 Int : Takes a numeral and returns an integer value
Syntax: Int (expression)
Example: length =Int( Totallength / 2),
Int(12.45)=12

 Len : Counts the characters in a string & returns


length
Syntax: Len ( String)
Example: Len (String) -- returns the value 6

CCP503.38 5
 InStr : Returns the first position of a string inside
another string . If string not found , returns 0
Syntax :
Instr ([ start position], string , substring [,compare])
Example :
Debug. Print instr(6, “I study 3rd DCCP”, “6th Sem “)

CCP503.38 6
 Left : Returns desired number of characters from
the left hand side of string
Syntax: Left ( String , Length)
Example : SAlphabets = “ABCDEFGH”
spiece = Left ( SAlphabets , 3)
Debug. print spiece
Output would be : ABC

CCP503.38 7
 Right : Returns desired number of characters from
the right hand side of string
Syntax: Right ( Sstring , Length)
Example : SAlphabets = “ABCDEFGH”
spiece = Right ( SAlphabets , 3)
Debug. print spiece
Output would be : FGH

CCP503.38 8
 Mid : Returns characters from any part of a string
Syntax : Mid (String , start ,[ , and length]))
Example : SAlphabets = “ABCDEFGH”
spiece = Mid ( SAlphabets ,4, 3)
Debug. print spiece
Output would be : DEF

CCP503.38 9
 Lcase : Returns a string with all letters converted to
lower
Syntax : Lcase (String)

 Ucase : Returns a string with all letters converted to


Uppercase
Syntax : Ucase (String)

CCP503.38 10
 TRIM : Trim function returns a copy of a string
without leading spaces (Ltrim) , without trailing
spaces(RTrim) , or without both leading and trailing
spaces (Trim)
Syntax : Ltrim (String)
Rtrim (String)
Trim (string)

CCP503.38 11
 Asc : Returns the ASCII character code
corresponding to first letter in a string
Syntax : Asc (String)
ASC(“A”) – returns 65
 Chr : Returns character associated with specified
character code
Syntax : Chr (Char code)
Chr (65) –returns “A”
 Space : Returns a string consisting of specified
number of spaces
Syntax : Space (number)
Space (10) – returns 10 spaces

CCP503.38 12
 String : Returns a repeating character string of the
length specified
Syntax : String (number , character)
Example : Dim sString as string * 20
sString = String (20,” * ”)
Debug.Print sString
Output: shows 20 stars

CCP503.38 13
Date and Time functions
 Now : Returns current System date & time
Example : Dim DtToday As Date
DtToday = Now
Debug . Print DtToday – shows current

system date &


time

 Date : Reads or set current system date


Example : text1.text = Date

 Time : Reads or sets system time


CCP503.38 14

Example : text1.text = time


 IsDate : Returns a Boolean value to indicate
whether string passed contains a valid
date
Example : if not IsDate (txtDate) Then
TxtDate = “<Invalid Date >”
End If

 DateValue : Returns a date data type from a string


representation of date that is passed to it
Example : dimdtMyDate as Date
Dim sMystring as string
sMystring = “7-Mar-2008”
dtMyDate = Datevalue(sMystring)

CCP503.38 15
 TimeValue : Takes a string representation of time
and converts it to a date data type
Example : Dim dtMyDate as Date
Dim sMystring as string
sMystring = “08:30:00”
dtMyDAte = Timevalue(sMystring)

 Hour, Minute, Second : Used to extract integer


representations of Hour, Minute and Second
respectively form Date date type
Example : Hour (now)
Minute(now)
Second(now)
CCP503.38 16
Summary
In this Session, you learnt …

 About the Built-in or Library Functions in VB

CCP503.38 17
Frequently Asked Questions
2. What is a Built-in function and give an example?

4. List the Built – in Functions available in VB ?

6. Distinguish between user define Functions and Library


Functions in VB?

CCP503.38 18
Quiz
1 Len() is ____
A. Procedure
B. Function
C. Built-in function
D. User defined Function

2. Which Library function, counts the no. of characters in


a string & returns length
A. Lset
B. InString
C. Len
D. Val

CCP503.38 19
Assignment
1. Explain any 10 built-in functions

CCP503.38 20

S-ar putea să vă placă și