Tuesday, April 20, 2010

Calling FileSystemObject from VB Script

Previous21222324252627282930Next

How to call from FileSystemObject Library


For us to write VB scripts for QTP we generally interact with FileSystemObject and Excel Objects. There is a process in calling a FileSystemObject Object and use it in the VB script to get the desired output.



In order to call from FileSystemObject (FSO) Library we first need to create and Object Variable.

An Object Variable is a Variant with sub type which holds an Object and should be prefixed with a Key word called "SET". To interact with different libraries we need to create Objects and these Objects are used along with different Methods to perform different operations.

Let us look at some examples to create Object to use from different Libraries.

Set Fso = CreateObject("Scripting.FileSystemObject")

Here we are creating an object to call a method from the File System Object Library

Set xlapp = CreateObject("Excel.Application")

Here we are creating an object to call a method from the Excel Library

Set IE = CreateObject("InternetExplorer.Application")

Here we are creating an object to call a method from the Internet Explorer Library

Set QtpApp = CreateObject("QuickTest.Application")

Here we are creating an object to call a method from the Quick Test Library

Set doc = CreateObject("Word.Application")

Here we are creating an object to call a method from the Microsoft Word Library

Set OutlookObj = CreateObject("OutLook.Application")

Here we are creating an object to call a method from the Outlook Library

All the above variables are used as a standard convention to understand as to what the object is doing.

Please look at the following scripts where File System Object is used in VB Script for various purposes.

1. How to Create a Text File using VB Script? Click Here for the Code

2. How to create multiple Text Files? Click Here for the Code

3. How to create a Folder using VB script? Click Here for the Code

4. How to display File Properties in VB script? Click Here for the Code

Previous21222324252627282930Next

No comments:

Post a Comment