Monday, August 29, 2011

Regular Expression

A regular expression is a string that describes or matches a set of strings. It is often called a pattern as it describes set of strings.

Given underneath is one of the most widely used and ever confused BackLash character. The remaining expressions are serialized below that.

Using the Backslash Character
A backslash (\) instructs QuickTest to treat the next character as a literal character, if it is otherwise a special character. The backslash (\) can also instruct QuickTest to recognize certain ordinary characters as special characters. For example, QuickTest recognizes \n as the special newline character. 
For example:
w matches the character w
\w is a special character that matches any word character including underscore

The period would be mistaken as an indication of a regular expression. To indicate that the period is not part of a regular expression, you would enter it as follows:
mercurytours\.mercuryinteractive\.com Note: If a backslash character is used before a character that has no special meaning, the backslash is ignored. For example, \z matches z.

Expressions & Explanation
Special characters and sequences are used in writing patterns for regular expressions. The following describes the characters and sequences that can be used.


\
Marks the next character as either a special character or a literal. For example, "n" matches the character "n". "\n" matches a newline character. The sequence "\\" matches "\" and "\(" matches "(".

^
Matches the beginning of input.

$
Matches the end of input.

*
Matches the preceding character zero or more times. For example, "zo*" matches either "z" or "zoo".

+
Matches the preceding character one or more times. For example, "zo+" matches "zoo" but not "z".

?
Matches the preceding character zero or one time. For example, "a?ve?" matches the "ve" in "never".

.
Matches any single character except a newline character.

(pattern)
Matches pattern and remembers the match. The matched substring can be retrieved from the resulting Matches collection, using Item [0]...[n]. To match parentheses characters ( ), use "\(" or "\)".

xy
Matches either x or y. For example, "zwood" matches "z" or "wood". "(zw)oo" matches "zoo" or "wood".

{n}
n is a nonnegative integer. Matches exactly n times. For example, "o{2}" does not match the "o" in "Bob," but matches the first two o's in "foooood".

{n,}
n is a nonnegative integer. Matches at least n times. For example, "o{2,}" does not match the "o" in "Bob" and matches all the o's in "foooood." "o{1,}" is equivalent to "o+". "o{0,}" is equivalent to "o*".

{n,m}
m and n are nonnegative integers. Matches at least n and at most m times. For example, "o{1,3}" matches the first three o's in "fooooood." "o{0,1}" is equivalent to "o?".

[xyz]
A character set. Matches any one of the enclosed characters. For example, "[abc]" matches the "a" in "plain".

[^xyz]
A negative character set. Matches any character not enclosed. For example, "[^abc]" matches the "p" in "plain".

[a-z]
A range of characters. Matches any character in the specified range. For example, "[a-z]" matches any lowercase alphabetic character in the range "a" through "z".

[^m-z]
A negative range characters. Matches any character not in the specified range. For example, "[m-z]" matches any character not in the range "m" through "z".

\b
Matches a word boundary, that is, the position between a word and a space. For example, "er\b" matches the "er" in "never" but not the "er" in "verb".

\B
Matches a non-word boundary. "ea*r\B" matches the "ear" in "never early".

\d
Matches a digit character. Equivalent to [0-9].

\D
Matches a non-digit character. Equivalent to [^0-9].

\f
Matches a form-feed character.

\n
Matches a newline character.

\r
Matches a carriage return character.

\s
Matches any white space including space, tab, form-feed, etc. Equivalent to "[ \f\n\r\t\v]".

\S
Matches any nonwhite space character. Equivalent to "[^ \f\n\r\t\v]".

\t
Matches a tab character.

\v
Matches a vertical tab character.

\w
Matches any word character including underscore. Equivalent to "[A-Za-z0-9_]".

\W
Matches any non-word character. Equivalent to "[^A-Za-z0-9_]".

\num
Matches num, where num is a positive integer. A reference back to remembered matches. For example, "(.)\1" matches two consecutive identical characters.

\n
Matches n, where n is an octal escape value. Octal escape values must be 1, 2, or 3 digits long. For example, "\11" and "\011" both match a tab character. "\0011" is the equivalent of "\001" & "1". Octal escape values must not exceed 256. If they do, only the first two digits comprise the expression. Allows ASCII codes to be used in regular expressions.

\xn
Matches n, where n is a hexadecimal escape value. Hexadecimal escape values must be exactly two digits long. For example, "\x41" matches "A". "\x041" is equivalent to "\x04" & "1". Allows ASCII codes to be used in regular expressions.

File handling in QTP


To interact with text files using QTP. Interaction can be(but not limited to) in the form of reading input from a file, writing output to a file.  This post describe in detail "File handling using QTP".
We use FSO object to do this.

What is FSO?
FSO stands for File System Object. This is used to support text file creation and manipulation through the TextStream object and is contained in the Scripting type library (Scrrun.dll)
The FSO Object Model has a rich set of properties, methods and events to process folders and files.


How to create a file?
We first create a FSO object using CreateObject and then create a text file using CreateTextFile.
For Example: Suppose you want to create a file called "test.txt" located in C:
Dim fso, file, file_location
file_location = "C:\file_location"
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set file = fso.CreateTextFile(file_location, True) // True--> file is to be overwritten if                  it already exists else false 
We would use the same example for the rest of this post.
How to open a file?
Set file= fso.OpenTextFile("C:\file_location", ForWriting, True)
//2nd argument can be ForReading, ForWriting, ForAppending
//3rd argument is "True" if new file has to be created if the specified file doesn’t exist else false, blank signify false.
How to read content from a file?
Use ReadLine() method
For example:
Set file= fso.OpenTextFile("C:\file_location", ForReading, True) //2nd argument should always be "ForReading" in order to read contents from a file
Do while file.AtEndofStream <> True
      data = file.ReadLine()
      msgbox data
Loop
How to write content to a file?
You can use  Write() or WriteLine() Methods to write text into a file. The difference between the Write() and WriteLine() Method is that the latter automatically inserts a new line character while the former doesn’t insert a new line character.
For example:
Set file= fso.OpenTextFile("C:\file_location", ForWriting, True) //2nd argument should always be "ForWriting" in order to write contents to a file
file.Write("This is a place to get all your qtp")
file.Write("questions and answers solved.")
//Output will be:
This is a place to get all your qtp questions and answers solved.
 while
file.WriteLine("This is a place to get all your qtp")
file.Write("questions and answers solved.")
//Output will be:
This is a place to get all your qtp
questions and answers solved.
How to delete content?
Use DeleteFile() method to delete a file from a particular location
Foe Example:
file_location = "C:\file_location"
Set fso = CreateObject(“Scripting.FileSystemObject”)
fso.DeleteFile(file_location)

Sunday, May 8, 2011

Datatable

Usage of datatable
 
Use the DataTable.Value method to access data from the data table and input it into the application
For data in the Global datasheet:QTP and Excel
1. Open a new script.
2. In column A of the Global datasheet, enter the data in three rows.
3. Go to www.google.com.
4. Begin recording.
5. Type a value into the Google search field.
6. Stop recording.
7. Go to the Expert view. Modify the script so it look like this:
rc = DataTable.Value ("A", dtGlobalSheet)
msgbox rc
Browser("Google").Page("Google").WebEdit("q").Set rc
8. To run all rows in the global data table, go to Test ->; Test Settings -> Run tab, and select "Run on all rows."
For data in the Local datasheet:
1. Start a new script.
2. In column A of the Action1 datasheet, enter the data in three rows:
3. Go to www.google.com.
4. Begin recording.
5. Type a value into the Google search field.
6. Stop recording.
7. Go to the Expert view. Modify the script so it look like this:
rc = DataTable.Value ("A", dtLocalSheet)
msgbox rc
Browser("Google").Page("Google").WebEdit("q").Set rc
8. To run all rows:
  1. Right-click on the Action name in the Tree View.
  2. Go to Action Properites -> Run tab, and select "Run all rows."

Similarly, How can we use the data table to get output data from an application?

Create an Output Value. The text will be placed in the datatable and can be accessed as needed.
1. Once you see the text you want to retrieve, start recording.
2. From the Insert menu, select Output Value, then Text Output Value.
3. Click on the desired text. The "Text Output Value Properties" window will appear.
4. In the window you can verify or set the Before and After text settings.
5. By default the retrieved value will be added to the Global sheet. You can modify the settings by selecting Output Text in the combobox, then clicking Modify.
6. Once satisfied, click OK.
An Output statement will be entered into the script.
Example:
Browser("Browser").Page("Page").Output CheckPoint("Text")
msgbox DataTable.Value("PageOutput_Text_out", dtGlobalSheet)
In addition, a column (in the example, PageOutput_Text_out) will be inserted into the datatable(Remember in the runtime datatable), with the output text.
OR Another method to retrieve data during run time is to do just the opposite of what we did above in the first question above.
DataTable.Value(ParameterID [, SheetID])=NewValue
Note:
The value property is the default property for the DataTable object. As the default property you do not need to explicitly use .Value.
DataTable(ParameterID [, SheetID]) = NewValue
Example:
' Add data to the current row of the Global sheet
DataTable("VarName", dtGlobalSheet) = "new value" ' Using DataTable by itself
DataTable.Value("VarName2", dtGlobalSheet) = "new value2" ' Using .Value
' Add data to the current row of the Local sheet
DataTable("VarName", dtLocalSheet) = "new value" ' Using DataTable by itself
DataTable.Value("VarName2", dtLocalSheet) = "new value2" ' Using .Value

Friday, May 6, 2011

Sample Code for conditional statements

'Sample Code for conditional statements

a=10
b=20

If a<b Then
    reporter.ReportEvent micPass,"Condition Check","A is less than B"
Else
     reporter.ReportEvent micFail,"Condition Check","B is less than A"   
End If


d=0

For i= 1 to 10
    d = cint(d)+cint(i)
Next

msgbox d


a=0
j=0

While A <=10
    j= cint(j)+ A
    A = cint(a)+1
Wend

msgbox j

'CODE FOR EXECUTION OF COMMAND PROMPT STATEMENTS

'CODE FOR EXECUTION OF COMMAND PROMPT STATEMENTS

Set oshell = createObject("wscript.shell")

oshell.run "cmd /k Net start > c:\services.txt"               'Creates a text file in C:\
oshell.run "cmd /k dir > c:\Dir.txt"                                    'Creates a text file in C:\

Set oshell=nothing

Tuesday, March 15, 2011

Scheduling QTP Script Execution during Out of office

Do you Want to run your QTP scripts when you are not in office/ infront of the computer? Please follow below steps....

1) Create a .vbs file to launch QTP with required settings, add-ins etc.
Here is a sample vbs code
Set App = CreateObject("QuickTest.Application")
App.Launch
App.Visible = True
App.WindowState = "Maximized" ' Maximize the QuickTest window
App.ActivateView "ExpertView" ' Display the Expert View
App.open "C:\Program Files\Mercury Interactive
\QuickTest Professional\Tests\Test1", False  'Opens the test in editable mode

2) ok, for the first timers. Create a sample QTP test and save it as Test1 at the location above. Copy the code into notepad and name the file as testing.vbs 3) Now we will automate the opening of vbs file through Windows Scheduler. Go To Start > Control Panel > Schedule Tasks > Click Add Schedule Tasks Click Next on the screen.
4) Click Browse and and select the .vbs file you just created.You will get this screen
 5) Give a name to the task and select the frequency for performing the given tasks. For this demo we will select "One time only"
 6) Select Start Time and Start Date. For this demo, select Start Time as current time+5 mins and Start date as todays date.
7) Next Screen Enter "UserName", "Password" and "Confirm Password" Click Next and you should get this screen. 
8) Click on Finish and yay, you're done.
Note: The steps above are for Windows XP and may be different for other Operating Systems.

Please feel free to comment on this if any questions.

Tuesday, February 22, 2011

Clicking on all links of Google Search

browser("micclass:=Browser").page("micclass:=Page").webedit("name:=q").Set "QTPPRABHAKAR"
browser("micclass:=Browser").page("micclass:=Page").webbutton("name:=Google Search").Click
browser("micclass:=Browser").Sync
Set oDesc=Description.Create
oDesc("micclass").value="Link"
set lnkList=browser("micclass:=Browser").page("micclass:=Page").childobjects(oDesc)
Set oDictionary=createobject("scripting.dictionary")
For i=0 to lnkList.count-1
    oDictionary.add i,lnkList(i).getROproperty("name")
Next
   LnkProperties = oDictionary.Items
  
For i = 0 To oDictionary.Count -1
   
    If i=oDictionary.count-1 then
        Exit for
    End if
   
    If LnkProperties(i+1)="Cached" Then
        browser("micclass:=Browser").page("micclass:=Page").Link("name:="&LnkProperties(i)).click
        browser("micclass:=Browser").Back
        browser("micclass:=Browser").Sync
    End If
Next

Use of .INI file in QTP

Use of .INI file in QTP

It's used to store user defined external environment variables in 5x and 6x versions of QTP.
Because
of the increased XML usage in all technologies from 8x, QTP is given
a facility to store user defined external environment variables in XML
files. QTP is having backward compatibility so that it will support
.INI files in latest versions of QTP.

How to store environment variables in INI files?

step1: open a notepad file
step2: on top of the file write [Environment]
step3: specify variable names and values
step4: Save it as .ini file
step5: Associate environment file in QTP 
File-->Settings-->environment-->User Defined

EX:-
'************************************************************
[Environment]

URL=www.google.com
ScriptsPath=D:\AutomationProject\

'************************************************************

Creating Comments and Action Template

Creating Comments and Action Template

While editing your test, you can add comments in the Keyword View or in the Expert View. You can also add comments to function libraries. A comment is an explanatory remark in a program. When you run a test, QuickTest does not process comments. You can use comments to explain sections of your tests to improve readability and to make them easier to update. You can add comments directly to the Keyword View or the Expert View, or you can use the Insert Comment dialog box. You can also modify comments at any time directly in the Keyword View or the Expert View, or using the Comment Properties dialog box.

To add a comment in the Keyword View: 

If the Comment column is not visible, right-click any column header and select Comment.

  • To add a comment on the same line as a step, select the step and type your comment in the Comment column.
  • To add a comment on a separate line, select a step and choose Insert > Comment, or right-click a step and choose Insert Step > Comment. The Insert Comment dialog box opens. Type a comment and click OK. A comment statement is added to your test.
To add a comment in the Expert View or a function library: 

Type an apostrophe (') or use "rem" statement and then type your comment. You can add a comment at the end of a line or at the beginning of a separate line.

Example:

'This is a demo test

or
rem this is a demo test
ctrl+m and ctrl+shift+m are the key board short cuts to comment and uncomment a single or bulk statements.
If you want to add the same comment to every action that you create, you can add the comment to an Action Template.

Creating an Action Template
If you want to include one or more statements in every new action in your test, you can create an action template. For example, if you always enter your name as the author of an action, you can add this comment line to your action template. An action template applies only to actions created on your computer.

To create an action template:

Create a text file containing the comments, function calls, and other statements that you want to include in your action template. The text file must be in the structure and format used in the Expert View.
Save the text file as ActionTemplate.mst in your <QuickTest Installation Folder>\dat folder. All new actions you create contain the script lines from the action template.

Note: Only the file name ActionTemplate.mst is recognized as an action template.

'***************************************************************

Sample Action Template
'########################################################
' Objective            :     The objective of the testcase
' Test Case           :     Test Case Name
' Author                :     Author Name
' Date Created       :     XX/XX/XXXX (mm/dd/yyyyy)
' Date Updated      :     XX/XX/XXXX (mm/dd/yyyyy)
'Updated by          :   
'########################################################

'##############Initialize Variables and Load Libraries##################

'-----------Write Statements to initialize Variable and to execute libraries

'#####################
Driver Script ##########################


'-----------Write the main Script here


'########################################################

'############## Report Generation & Memory Cleanup ################

'-----------Write code to generate report and to cleanup memory of variables

'########################################################
'****************************************************************

Index VS Location in QTP

The Definitions by QTP
Index :- Indicates the order in which the object appears in the application code relative to other objects with an otherwise identical description.
Index property values are object-specific. Therefore, if you use Index:=3 to describe a WebEdit test object, QuickTest searches for the fourth WebEdit object in the page. However, if you use Index:=3 to describe a WebElement object, QuickTest searches for the fourth Web object on the page—regardless of the type—because the WebElement object applies to all Web objects.
Location :- Indicates the order in which the object appears within the parent window, frame, or dialog box relative to other objects with an otherwise identical description.
Location property values are object-specific. Therefore, if you use Location:=3 to describe a WinButton test object, QuickTest searches from top to bottom, and left to right for the fourth WinButton object in the page. However, if you use Location:=3 to describe a WinObject object, QuickTest searches from top to bottom, and left to right for the fourth standard object on the page—regardless of the type—because the WinObject object applies to all standard objects.
These are confusing statements. Let me give a stand on  this.
Here is an example.
Index
In the below page image the first link which is appeared is “Web”. The index for this link will be “0” because it is the first link in the page. Like the way Images, News, and Maps will have the index 1,2 and 3.
Location
Location is the position of the object from left to right and top to bottom of the page. This means that when you add an object QTP assigns the location id based on the object position from left to right side and top to bottom.
In the below page the 0th location link is Alerts. Because in the page from left to right QTP will identify a series of links in the same column. Those are Alerts, Blog Search, …..etc. Now QTP assigns location from top to bottom like Alerts –0, Blog Search –1, Books-2…etc.
The link “web” will have the location id “13” but the index is “0”.
The definition by QTP for location says “QuickTest searches from top to bottom, and left to right “. But the actual is “from left to right and top to bottom of the page”.
I am in process of getting clarification from HP on this.
You can get the below page from this URL http://www.google.co.in/intl/en/options/

Object Repository window VS Object Repository Manager


Functionality
Object Repository window
Object Repository Manager
Adding Test Objects to a Local or Shared Object Repository
YesYes
Copying, Pasting, and Moving Objects in the Object Repository
YesYes
Deleting Objects from the Object Repository
YesYes
Highlighting an Object in Your Application
YesYes
Locating a Test Object in the Object Repository
YesYes
Specifying or Modifying Property Values
YesYes
Updating Identification Properties from an Object in Your Application
YesYes
Restoring Default Mandatory Properties for a Test Object
YesYes
Renaming Test Objects
YesYes
Adding Properties to a Test Object Description
YesYes
Defining New Identification Properties
YesYes
Removing Properties from a Test Object Description
YesYes
Exporting Local Objects to a Shared Object Repository
YesNo
Copying an Object to the Local Object Repository
YesNo
Creating New Object Repositories
NoYes
Opening Object Repositories
NoYes
Saving Object Repositories
NoYes
Closing Object Repositories
NoYes
Editing Object Repositories
NoYes
Adding Test Objects to Your Test Using the Object Repository Manager
YesYes
Adding Test Objects Using the Navigate and Learn Option
NoYes
Managing Repository Parameters
NoYes
Adding Repository Parameters
NoYes
Modifying Repository Parameters
NoYes
Deleting Repository Parameters
NoYes
Specifying a Property Value
NoYes
Locating Test Objects
YesYes
Performing Merge Operations
NoYes
Importing from XML
NoYes
Exporting to XML
NoYes

How to Run the analog recorded code which is copied from another test?

How to Run the analog recorded code which is copied from another test?

Good Question. If you want to copy the same recorded code to another test, you must copy AnalogTrackList.dat file to the test in which you want to use the analog script code.
AnalogTrackList.dat --> This file will be available in Action folder where that analog recorded steps are recorded.

Monday, February 7, 2011

VB Scripting Basics

Data types in VB Script

VBScript has only one data type called a Variant. A Variant is a special kind of data type that can contain different kinds of information, depending on how it is used. 
If you use a variable for assigning a numeric value, that variable behaves like a numeric data type. If you assign string value, that variable behaves like a string.

However VBSCRIPT is having sub data types in Variant.

1. Empty
2. Null
3. Boolean
4. Byte
5. Integer
6. Currency
7. Long
8. Single
9. Double
10. Date (Time)
11. String
12. Object
13. Error.

We can use conversion functions to convert data from one subdatatype to another type. To find subdatatype of a variant we need to use 
vartype function.

Variables
A variable is a convenient placeholder to store program information. You can change variable value in script running time. In VBScript variables are always of one fundamental data type Variant.
Use of variables in script:
Variable is very useful for carrying a value. For example if your script is using a value 10 in five places (3rd, 7th, 12th, 17th, 20th lines). Suppose if that value is changed from 10 to 20 then you need to change that value in all the places where ever it is used. But if you have used variable in place of value (x=10) you need to change in only one place if that value is changed from 10 to 20(x=20).  Variables are having flexibility to change value in run time.
Declaring Variables:
Because of vbscript is having only one data type no need to declare any variable in the script. By default all variables are comes under variant datatype. But it is not the good practice because you could misspell the variable name in one or more places, causing unexpected results when your script is run.
For that reason, the Option Explicit statement is available to require explicit declaration of all variables. Option Explicit statement will enforce you to declare all the variables.
We can declare the variables using Dim statement.
Ex:       Dim x
            X=10   'Normal Declaration


Optional Explicit
Dim x
X=10   'When working with optional explicit
Naming Restrictions to Variables:
Variable names follow the standard rules for naming anything in VBScript. 
A variable name:
  • Must begin with an alphabetic character.
  • Cannot contain an embedded period.
  • Must not exceed 255 characters.
  • Must be unique in the scope in which it is declared.
scope of a Variable:
If you declare a variable with in a Function then it is local to that function only. You can access that variable only with in that function. Now It has local scope and is a procedure-level variable.
If you declare a variable with in a Script then it can be used by entire script and can be accessed by all functions. Now It has local scope and is a procedure-level variable. This is a script-level variable, and it has script-level scope.

Array Variables

a variable containing a single value is a scalar variable. you can create a variable that can contain a series of values using an index number. This is called an array variable. Arrays are useful when you're storing sets of similar data.You can store any kind of data in an array. The array can hold a combination of data types.
Creating Arrays:
Using Dim Statement we can create an array. we can convert a variable in to an array using array function.
Types of Arrays:
1. Fixed Length Arrays
2. Dynamic Arrays
Fixed arrays have a specific number of elements in them, whereas dynamic arrays can vary in the number of elements depending on how many are stored in the array.
Creating Fixed Length Arrays:
Dim a(10)
Here 'a' is an array and is having 11 elements (Array count starts from 0). Here it's a fixed size array with size 10.
Creating Dynamic Arrays:
A dynamic array is created in the same way as a fixed array, but you don't put any bounds in the declaration.
Dim x()
Here 'x' is the dynamic array and we can store n number of elements in it. The benefit of a dynamic array is that if you don't know how large the array will be when you write the code, you can create code that sets or changes the size while the VBScript code is running.
We can store more values in dynamic array by redeclaring the array using Redim statement.
ReDim Statement:
Using Redim we can redeclare an array size. ReDim tells VBScript to "re-dimension" the array for how many elements you specify. If you use redim statement in your script it will clear all existing data which is stored in that array and declares that array as fresh array.
Redim with Preserve Keyword:
When your working redim it will clear all the existing data in an array. The preserve keyword is useful to overcome this problem. Preserve keyword will preserve the existing data and resize the array with the specified size.
Ex: Redim preserve a(20)
Using Fixed arrays:
Dim x(2)
x(0)="how"
x(1)="are"
x(2)="you"
for i=lbound(x) to ubound (x)
msgbox x(i)
Next
Here we cann't store more than 3 elements. Because this is a fixed length array..
Using Dynamic Arrays:
Dim x()
Redim preserve x(2)
x(0)="how"
x(1)="are"
x(2)="you"
Redim preserve x(3)
x(3)=123
Here 'x' is a dynamic array and by redeclaring x it can able to store more values into it.
Converting a variable into an array:
We can convert a variable in to array variable using array function. 
Example
Dim v
v=array("how","are","you")
for i=lbound(v) to ubound (v)
msgbox v(i)
Next
Here 'v' is a dynamic array. We can store some more elements by redeclaring the array.
Constants
A constant is a meaningful name that takes the place of a number or string and never changes. The difference between variable and constant is we can change the variable value in run time but for constants its not possible.
Creating constants:
const str="QTP"
here str is a constant and the value will never change.
We have public and Private constants. By default all are public. If you want specify the type then
Public const str="QTP"
        or
Private const str="QTP"
VB Script Procedures
There are two types of procedures
1. Function Procedure
2. Sub Procedure
Function Procedure
A Function procedure is a series of VBScript statements enclosed by the Function and End Function statements. Function Procedure can able to return the value.
Example:
Function demo_add(a,b)
    demo_add=a+b
End Function
oVal=demo_add(2,3)
msgbox oVal    'Returns 5
In this example demo_add function returns a value to oVal. In Function procedures we can use function name to assign a value.
Sub Procedure
A Sub procedure is a series of VBScript statements enclosed by the Sub and End Sub statements. Sub Procedure cannot return any value.
Example:
Sub demo_sub(a,b,c)
    c=a+b
End sub
demo_sub 2,3,x
msgbox x    'Returns 5
This example will do the same as what function procedure is doing above. But in sub Procedure we need to use one more parameter to get values from the sub procedure.Types of arguments in procedures
1. ByVal
2. ByRef
ByVal:
Indicates that the argument is passed by value. 
ByRef :
Indicates that the argument is passed by reference. 
By default all arguments are 'ByRef'.
Syntax
Function demo_add(a,b)
    demo_add=a+b
End Function
Here a,b are the arguments. By default these are 'ByRef'.
In simple words ByRef Means the value which is assigned to the variable with in the function is permanent and we can use that value out side of that function also.
ByVal means the value which is assigned to the variable with in the function is temporary and we can use that value only with in that function.
Example:
Function demo_parameters(byref x,byval y)
    x=20
    y=50
    demo_parameters=x+y
End Function
a=10
b=20
msgbox demo_parameters(a,b)
msgbox a
msgbox b

In the above function x and y are the arguments, declared as byref and byval.
With in that function i assigned values to x and y.
Outside of the function i assigned values to two variables and passing those variables in to the function.
'a' is passing reference to x and b is passing value to y.
With in that function i am changing the value for x. This value is permanent for 'a'. Because 'a' is passed as 'ByRef'.
But the value of 'b' will not be changed because it is passed as 'ByVal'.