Sub-Routines are similar to functions but they cannot return any value. For Eg:-
sum 3,4
Sub sum(a, b)
msgbox a+b
End Sub
There are a number of in-built functions in function libraries of VB. The complete list is given at - UFT Help -> VB Script -> VB Script Language Reference -> Functions. Over here, we are going to cover few of the important in-built functions:-
str = "Yes!! Today is Friday!!"
msgbox left(str, 5)
Output: Yes!!
Mid - It is used to return middle part of a string.
str = "Yes!! Today is Friday!!"
msgbox mid(str, 7,5)
Output: Today
Hence, syntax of mid is - mid(<string>, <start>, [optional] length)
Right - It is used to return Right part of a string.
str = "Yes!! Today is Friday!!"
msgbox Right(str, 8)
Output: Friday!!
Split - It is used to split an expression into various elements. And, it stores the elements of the expression in the form of an array. Eg:-
str = "Yes!! Today is Friday!!"arr = split(str, " ") ' Here, space in the second parameter acts as a Delimiter.
For Iterator = 0 To ubound(arr)
Print arr(iterator)
Next
Output: Yes!!
Today
is
Friday!!
UCase and LCase - They are used to convert the case of a string to upper or lower.
Print ucase("abcdEFGH")
Print lcase("abcdEFGH")
Output: ABCDEFGH
abcdefgh
LTrim, RTrim and Trim - LTrim removes the blank spaces from left hand side, RTrim removes the blank spaces from right hand side and Trim removes the blank faces from both the sides.
IsNumeric, CStr and CInt - IsNumeric function tells us whether a string is numeric or not. And, CInt converts a string to an integer. Similarly, CStr is used to convert an Integer to a string.
a = "44"
b = "33"
If IsNumeric(a) and isnumeric(b) Then
msgbox CInt(a) + CInt(b)
End If
Output: 77.
a = 124
msgbox CStr(a)
Date, Time and Now - Date retruns Date, Time returns Time and Now returns both.
msgbox Date
msgbox Time
msgbox Now
msgbox datevalue("10 november, 2013") - This returns date in mm/dd/yyyy format.
How to find Date difference between 2 given dates?
For this, there is an in-built function called as dateDiff.
d1 = dateValue("november 10, 2010")
d2 = dateValue("november 10, 2011")
msgbox datediff("d", d1, d2) - Output: 365 - so, dateDiff returns difference in days.
msgbox datePart("d", d1) - Output: 10 - retruns date part of a date.
msgbox datePart("m", d1) - Output: 11 - returns month part of a date.
TIME -
print time - Returns current time.
print hour(time) - Returns hour part of time.
print minute(time) - Returns minute part of time.
print second(time) - Returns second part of time.
Output:
11:53:27 PM
23
53
27
==============***********************===============
sum 3,4
Sub sum(a, b)
msgbox a+b
End Sub
There are a number of in-built functions in function libraries of VB. The complete list is given at - UFT Help -> VB Script -> VB Script Language Reference -> Functions. Over here, we are going to cover few of the important in-built functions:-
- Left
- Right
- Mid
- Split
- UCase/LCase
- ltrim, rtrim, trim
- cint, cstr
- isnumeric
- date
- time
- now
- datevalue
- datepart
- datediff
- hour
- min
- sec
str = "Yes!! Today is Friday!!"
msgbox left(str, 5)
Output: Yes!!
Mid - It is used to return middle part of a string.
str = "Yes!! Today is Friday!!"
msgbox mid(str, 7,5)
Output: Today
Hence, syntax of mid is - mid(<string>, <start>, [optional] length)
Right - It is used to return Right part of a string.
str = "Yes!! Today is Friday!!"
msgbox Right(str, 8)
Output: Friday!!
Split - It is used to split an expression into various elements. And, it stores the elements of the expression in the form of an array. Eg:-
str = "Yes!! Today is Friday!!"arr = split(str, " ") ' Here, space in the second parameter acts as a Delimiter.
For Iterator = 0 To ubound(arr)
Print arr(iterator)
Next
Output: Yes!!
Today
is
Friday!!
UCase and LCase - They are used to convert the case of a string to upper or lower.
Print ucase("abcdEFGH")
Print lcase("abcdEFGH")
Output: ABCDEFGH
abcdefgh
LTrim, RTrim and Trim - LTrim removes the blank spaces from left hand side, RTrim removes the blank spaces from right hand side and Trim removes the blank faces from both the sides.
IsNumeric, CStr and CInt - IsNumeric function tells us whether a string is numeric or not. And, CInt converts a string to an integer. Similarly, CStr is used to convert an Integer to a string.
a = "44"
b = "33"
If IsNumeric(a) and isnumeric(b) Then
msgbox CInt(a) + CInt(b)
End If
Output: 77.
a = 124
msgbox CStr(a)
Date, Time and Now - Date retruns Date, Time returns Time and Now returns both.
msgbox Date
msgbox Time
msgbox Now
msgbox datevalue("10 november, 2013") - This returns date in mm/dd/yyyy format.
How to find Date difference between 2 given dates?
For this, there is an in-built function called as dateDiff.
d1 = dateValue("november 10, 2010")
d2 = dateValue("november 10, 2011")
msgbox datediff("d", d1, d2) - Output: 365 - so, dateDiff returns difference in days.
msgbox datePart("d", d1) - Output: 10 - retruns date part of a date.
msgbox datePart("m", d1) - Output: 11 - returns month part of a date.
TIME -
print time - Returns current time.
print hour(time) - Returns hour part of time.
print minute(time) - Returns minute part of time.
print second(time) - Returns second part of time.
Output:
11:53:27 PM
23
53
27
==============***********************===============
No comments:
Post a Comment