Skip to main content

VB Script - Part II

VB Script - Part II


Array Function:
Array: Returns a Variant containing an array. 
 
Syntax: Array(arglist)
 
Arguments:
 
arglist:(required) argument is a comma-delimited list of values that are assigned to the elements of an array contained with the
 Variant. If no arguments are specified, an array of zero length is created. 

Example:
A = Array(10,20,30)

Print  A(0)                'Output --> 10
Print  A(1)                'Output --> 20
Print  A(2)                'Output -->30

  'Single dimensional Array with  five elements
Dim  Num(5)
Num(0)=10
Num(1)=20
Num(2)=30
Num(3)=40
Num(4)=50


Print  Num(0)                'Output --> 10
Print  Num(1)                'Output --> 20
Print  Num(2)                'Output -->30
Print  Num(3)                'Output -->40


'multidimensional array
Dim  DNum(3,2)
DNum(0,0)=10
DNum(0,1)=20
DNum(1,0)=30
DNum(1,1)=40
DNum(2,0)=50
DNum(2,1)=60


Print  DNum(0,0)                'Output --> 10
Print  DNum(0,1)                'Output --> 20
Print  DNum(1,0)                'Output -->30
Print  DNum(1,1)                'Output -->40
Print  DNum(2,0)                'Output -->50
Print  DNum(2,1)                'Output -->60

IsArray Function 
IsArray: Returns a Boolean value indicating whether a variable is an array.
 
Syntax: IsArray(varname)
 
Arguments:
varname:Can be any variable.
 
Example: 
'IsArray

Dim Arr
Dim  NArr

Arr = Array(10,20,30)

Print  IsArray(Arr)            'Output -->True

Print  IsArray(NArr)            'Output -->False

LBound Function 
LBound: Returns the smallest available subscript for the indicated dimension of an array.
 
Syntax: LBound(arrayname[, dimension])
 
Arguments:
arrayname:Name of the array variable; follows standard variable naming conventions.
dimension:Whole number indicating which dimension's lower bound is returned. Use 1 for the first dimension, 2 for the second, and so on. If dimension is omitted, 1 is assumed.
 Example: 
'LBound 
Dim LArr
LArr = Array(10,20,30)
Print  Lbound(LArr,1)                 'Output --> 0

''multidimensional array
Dim  Lmarr(3,2)

Print  LBound(Lmarr,2)       'Output --> 0

UBound Function 
UBound: Returns the largest available subscript for the indicated dimension of an array.
 
Syntax: UBound(arrayname[, dimension])
 
Arguments:
 
arrayname:(Required) Name of the array variable; follows standard variable naming conventions.
dimension:(Optional) Whole number indicating which dimension's upper bound is returned. Use 1 for the first dimension,
 2 for the second, and so on. If dimension is omitted, 1 is assumed. 
Example: 
'UBound 

Dim UArr
UArr = Array(10,20,30)
Print  Ubound(UArr,1)                 'Output --> 2

''multidimensional array
Dim  Umarr(3,2,4)

Print  UBound(Umarr,1)       'Output --> 3
Print  UBound(Umarr,2)       'Output --> 2
Print  UBound(Umarr,3)       'Output --> 4

Date Function 
Date: Returns the current system date.
 
Syntax: Date 
Example: 

'Date Print Date 'Output -->Displays the current system date.

Time Function
Time: Returns a Variant of subtype Date indicating the current system time.
 
Syntax: Time 
Example:
'Time

Print Time                                  
'Output --> Displays the  current system time.

DateAdd Function 
DateAdd: Returns a date to which a specified time interval has been added. 
 
Syntax: DateAdd(interval, number, date)
 
Arguments:
 
interval:(Required) String expression that is the interval you want to add. See Settings section for values.
number:(Required) Numeric expression that is the number of interval you want to add. The numeric expression can either be positive, for dates in the future, or negative, for dates in the past. 
 
date: (Required) Variant or literal representing the date to which interval is added.

Example: 
'DateAdd 

Print  DateAdd("yyyy",1,"November 01, 2010")                
'Output-->11/1/2011

DateDiff Function 
DateDiff: Returns the number of intervals between two dates. 
 
Syntax: DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])
 
Arguments:
 
interval:(Required) String expression that is the interval you want to use to calculate the differences between
date1 and date2.
date1, date2:(Required) Date expressions. Two dates you want to use in the calculation.
firstdayofweek:(Optional) Constant that specifies the day of the week. If not specified, Sunday is assumed.
firstweekofyear:(Optional) Constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs. 

Example: 

'DateDiff Print DateDiff("yyyy","November 01, 2008","November 01, 2009") 'Output--> 1

DatePart Function
DatePart: Returns the specified part of a given date.
 
Syntax: DatePart(interval, date[, firstdayofweek[, firstweekofyear]])
 
Arguments:
interval:(Required) String expression that is the interval of time you want to return.
date:(Required) Date expression you want to evaluate.
firstdayof week:(Optional) Constant that specifies the day of the week. If not specified, Sunday is assumed.
firstweekofyear:(Optional) Constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs.
 
Example: 
'DatePart

Print DatePart("yyyy","November 01, 2008")          
'Output-->    2008

Day Function 
Day: Returns a whole number between 1 and 31, inclusive, representing the day of the month.
 
Syntax: Day(date)
 
date:expression represent a date. If date contains Null, Null is returned.
 
Example: 
'Day

Print  Day("11-01-2010")                                        
'Output -->1

Print  Day("11/1/2010")                                                
'Output -->1

Print  Day("November 01, 2010")                            
'Output -->1

Month Function

Month: Returns a whole number between 1 and 12, inclusive, representing the month of the year.
 
Syntax: Month(date)
 
date:expression represent a date. If date contains Null, Null is returned.
 
 Example: 
'Month 

Print  Month("11-01-2010")                                        
'Output -->11

Print  Month("11/1/2010")                                                
'Output -->11

Print  Month("November 01, 2010")                            
'Output -->11

MonthName Function

MonthName: Returns a string indicating the specified month.
 
Syntax: MonthName(month[, abbreviate])
 
Arguments:
 
month:(Required) The numeric designation of the month. For example, January is 1, February is 2, and so on.
abbreviate:(Optional) Boolean value that indicates if the month name is to be abbreviated. If omitted, the default is False, which means that the month name is not abbreviated. 
 

Example: 
'MonthName

Print  MonthName(11,true)                                                  
'Output -->Nov

Print  MonthName(12,false)                                                
'Output -->December

Print  MonthName(9)                                                                
'Output -->September

Weekday Function 
Weekday:
 
Returns a whole number representing the day of the week. 
 
Syntax: Weekday(date, [firstdayofweek])
 
Arguments:
 
date:Any expression that can represent a date. If date contains Null, Null is returned.
firstdayofweek:A constant that specifies the first day of the week. If omitted, vbSunday is assumed.
Example: 
'Weekday

Print  Weekday("November 03, 2010")                                  
'Output -->4  (which means its a Wednesday)

WeekdayName Function 
WeekdayName: Returns a string indicating the specified day of the week.
 
Syntax: WeekdayName(weekday, abbreviate, firstdayofweek)
 
Arguments:
 
weekday:(Required) The numeric designation for the day of the week. Numeric value of each day depends on setting of the  firstdayofweek setting.
abbreviate:(Optional) Boolean value that indicates if the weekday name is to be abbreviated. If omitted, the default is False, which means that the weekday name is not abbreviated.
firstdayofweek:(Optional) Numeric value indicating the first day of the week.

Example: 
'WeekdayName

Print  WeekdayName(4)                                  
'Output -->Wednesday

Year Function 
Year: Returns a whole number representing the year.
 
Syntax: Year(date)
 
Arguments:
date:Any expression that can represent a date. If date contains Null, Null is returned.
 
Example: 
'Year 

Print  Year("11-01-2010")                                        
'Output -->2010

Print  Year("11/1/2010")                                                
'Output -->2010

Print  Year("November 01, 2010")                            
'Output -->2010

Hour Function 
Hour: Returns a whole number between 0 and 23, inclusive, representing the hour of the day. 
 
Syntax: Hour(time)
 
Arguments:
 
time:is any expression that can represent a time. If time contains Null, Null is returned.
 
 Example: 
'Hour 

Print  Hour(Now)                                 
'Output -->Displays the current system hour.

Minute Function

Minute: Returns a whole number between 0 and 59, inclusive, representing the minute of the hour.
 
Syntax: Minute(time)
 
Arguments:
 
time:is any expression that can represent a time. If time contains Null, Null is returned.

Example: 
'Minute

Print  Minute(Now)                                 
'Output -->Displays the current system minute.

Second Function 
Second: Returns a whole number between 0 and 59, inclusive, representing the second of the minute. 
 
Syntax: Second(time)
 
Arguments:
 
time:is any expression that can represent a time. If time contains Null, Null is returned. 

Example: 
'Second


Print  Second(Now)                                 
'Output -->Displays the current system Second.

Now Function 
Now: Returns the current date and time according to the setting of your computer's system date and time.
 
Syntax: Now
 
Example: 
'Now

Print  Now                                     
'Output -->Displays the current system date & time.

TimeSerial Function

TimeSerial: Returns a Variant of subtype Date containing the time for a specific hour, minute, and second.
 
Syntax: TimeSerial(hour, minute, second)
 
Arguments:
 
hour:Number between 0 (12:00 A.M.) and 23 (11:00 P.M.), inclusive, or a numeric expression.
minute:Any numeric expression.
second:Any numeric expression.

Example: 
'TimeSerial

Print  Timeserial(13,30,00)                    
'Output -->1:30:00 PM

TimeValue Function 
TimeValue: Returns a Variant of subtype Date containing the time.
 
Syntax: TimeValue(time)
 
Arguments:
 
time:is usually a string expression representing a time from 0:00:00 (12:00:00 A.M.) to 23:59:59 (11:59:59 P.M.), inclusive. However, time can also be any expression that represents a time in that range. If time contains Null, Null is returned.
 

Example: 
'TimeValue

Print  TimeValue("16:30:00")            
'Output -->4:30:00 PM

Comments

Popular posts from this blog

JMeter Exceeded Maximum Number of Redirects Error Solution

While running performance test, JMeter allows maximum 5 redirects by default. However, if your system demands more than 5 redirects, it may result in JMeter exceeded maximum number of redirects error. In this post, we have listed down steps to overcome this error. Actual error in JMeter: Response code: “Non HTTP response code: java.io.IOException” Response message: “Non HTTP response message: Exceeded maximum number of redirects: 5” This error is noticed because  JMeter  allows maximum 5 redirects by default and your system may be using more than 5 redirects. You need to increase this count to more than 5 in jmeter.properties file. Follow below steps to achieve this. Navigate to /bin directory of your JMeter installation. Locate jmeter.properties file and open it in any editor. Search for “httpsampler.max_redirects” property in opened file. Uncomment the above property by removing # before it. Change to value to more than 5 Eg. 20. Save the file and restart JMeter. If

SSO with SAML login scenario in JMeter

SAML(Security Assertion Markup Language) is increasingly being used to perform single sign-on(SSO) operations. As WikiPedia puts it, SAML is an XML-based open standard data format for exchanging authentication and authorization data between parties, in particular, between an identity provider and a service provider. With the rise in use of SAML in web applications, we may need to handle this in JMeter. This step-by-step tutorial shows SAML JMeter scenario to perform login operation. First request from JMeter is a GET request to fetch Login page. We need to fetch two values ‘SAMLRequest’ and ‘RelayState’ from the Login page response data. We can do this by using  Regular Expression Extractor . These two values need to be sent in POST request to service provider. Refer below image to see how to do this. We will get an HTML login page as a response to the request sent in 1st step. We need to fetch values of some hidden elements to pass it in the next request. We can do this b

A Tutorial to Send Email using JMeter

Sending email is a mundane activity in any professional’s life. It’s a common medium for communication nowadays. Therefore performance testing of email server is not only important but necessary for an organization. JMeter can be helpful to perform load testing in such scenarios. In this tutorial, we will see how JMeter can be used to send email. We will use SMTP Sampler of JMeter to send an email. JavaMail API is needed to enable email functionality in JMeter. Download it from  here  and paste the jar in JMeter’s lib folder. Now, perform below steps to configure SMTP Sampler. Add a new Thread Group under Test Plan. Right click on Thread Group and select Add–>Sampler–>SMTP Sampler. We need to populate SMTP server’s details in this sampler. We will use GMail for sending an email. For this, enter these values in SMTP Sampler fields. Server: smtp.googlemail.com, Port: 587. Provide values in Email Address From and To fields of Mail Settings section to specify sender and reci