<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>KR Testing Solutions</title>
	<atom:link href="http://kuldeepse.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kuldeepse.wordpress.com</link>
	<description>Quality is effected by your work process</description>
	<lastBuildDate>Thu, 25 Dec 2008 12:46:49 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='kuldeepse.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/90d0e1d9a7b5ada4b0de3575cdda4566?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>KR Testing Solutions</title>
		<link>http://kuldeepse.wordpress.com</link>
	</image>
			<item>
		<title>Steps for learning Descriptive programming</title>
		<link>http://kuldeepse.wordpress.com/2008/02/05/steps-for-learning-descriptive-programming/</link>
		<comments>http://kuldeepse.wordpress.com/2008/02/05/steps-for-learning-descriptive-programming/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 12:55:25 +0000</pubDate>
		<dc:creator>kuldeep kumar</dc:creator>
				<category><![CDATA[Learn VBScript for QTP (Descriptive Programming)]]></category>

		<guid isPermaLink="false">http://kuldeepse.wordpress.com/2008/02/05/steps-for-learning-descriptive-programming/</guid>
		<description><![CDATA[Learning VBScript for QTP 
We can learn the VBScript without QTP also. You need Notepad and command prompt on your system and follow below steps: 

Create a notepad file.
Write a small VBScript in the notepad file.

e.g. 
Option Explicit
Dim myResponse
myResponse = MsgBox(&#8220;Do you wish to quit?&#8221;, 1, &#8220;What do you wish to do?&#8221;) 

Save the above [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=126&subd=kuldeepse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><b><span style="font-size:10pt;font-family:Verdana;">Learning VBScript for QTP</span></b><span style="font-size:10pt;font-family:Verdana;"> </span></p>
<p><span style="font-size:10pt;font-family:Verdana;">We can learn the VBScript without QTP also. You need Notepad and command prompt on your system and follow below steps:</span><span style="font-size:10pt;font-family:Verdana;"> </span></p>
<ol>
<li class="MsoNormal"><span style="font-size:10pt;font-family:Verdana;">Create a notepad file.</span></li>
<li class="MsoNormal"><span style="font-size:10pt;font-family:Verdana;">Write a small VBScript in the notepad file.</span></li>
</ol>
<p><span style="font-size:10pt;font-family:Verdana;"></span><b><span style="font-size:10pt;font-family:Verdana;">e.g. </span></b></p>
<p><b><span style="font-size:10pt;font-family:Verdana;"></span></b><b><span style="font-size:10pt;font-family:Verdana;">Option Explicit</span></b><br />
<b><span style="font-size:10pt;font-family:Verdana;"></span></b><b><span style="font-size:10pt;font-family:Verdana;">Dim myResponse</span></b><br />
<b><span style="font-size:10pt;font-family:Verdana;"></span></b><b><span style="font-size:10pt;font-family:Verdana;">myResponse = MsgBox(&#8220;Do you wish to quit?&#8221;, 1, &#8220;What do you wish <span></span></span></b><b><span style="font-size:10pt;font-family:Verdana;">to do?&#8221;)</span></b><b><span style="font-size:10pt;font-family:Verdana;"> </span></b></p>
<ol>
<li class="MsoNormal"><span style="font-size:10pt;font-family:Verdana;">Save the above Notepad file as Test.vbs.</span></li>
<li class="MsoNormal"><span style="font-size:10pt;font-family:Verdana;">Run above file from the command prompt using CScript.exe.</span></li>
<li class="MsoNormal"><span style="font-size:10pt;font-family:Verdana;">C:\&gt;CScript.exe Test.vbs</span></li>
<li class="MsoNormal"><span style="font-size:10pt;font-family:Verdana;">You will be getting the result of your script.</span></li>
</ol>
<p><span style="font-size:10pt;font-family:Verdana;"><strong><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">Descriptive programming in QTP </span></strong><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span></span><br />
<span style="font-size:10pt;font-family:Verdana;"><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">Whenever QTP records any action on any object of an application, it adds some description on how to recognize that object to a repository of objects called object repository. QTP cannot take action on an object until unless its object description is in the Object Repository. But descriptive programming provides a way to perform action on objects which are not in Object repository</span></span><span style="font-size:10pt;font-family:Verdana;"><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span></span><br />
<span style="font-size:10pt;font-family:Verdana;"><br />
<span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><strong>Object Identification:</strong><br />
To identify an object during the play back of the scripts QTP stores some properties which helps QTP to uniquely identify the object on a page. Below screen shots shows an example Object repository:</span></span><span style="font-size:10pt;font-family:Verdana;"><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">Now to recognize a radio button on a page QTP had added 2 properties the name of the radio button and the html tag for it. The name the left tree view is the logical name given by QTP for the object. This can be changed as per the convenience of the person writing the test case. QTP only allows UNIQUE logical name under same level of hierarchy. As we see in the snapshot the two objects in Browser-&gt;Page node are “WebTable” and “testPath”, they cannot have the same logical name. But an object under some other node can have the same name. Now with the current repository that we have, we can only write operation on objects which are in the repository. Some of the example operations are given below</span></span><span style="font-size:10pt;font-family:Verdana;"><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span></span><br />
<span style="font-size:10pt;font-family:Verdana;"><br />
<span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><strong>Browser(&#8220;Browser&#8221;).Page(&#8220;Page&#8221;).WebRadioGroup (&#8220;testPath&#8221;).Select &#8220;2&#8243;<br />
cellData = Browser(&#8220;Browser&#8221;).Page(&#8220;Page&#8221;).WebTable (&#8220;WebTable&#8221;).GetCellData (1,1)<br />
Browser(&#8220;Example2&#8243;).Page(&#8220;Page&#8221;).WebEdit(&#8220;testPath&#8221;).Set &#8220;Test text&#8221;</strong> </span><strong><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">When and </span></strong></span><br />
<span style="font-size:10pt;font-family:Verdana;"><br />
<strong><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">Why to use Descriptive programming? </span></strong></span><br />
<span style="font-size:10pt;font-family:Verdana;"><strong><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span></strong><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">Below are some of the situations when Descriptive Programming can be considered useful:<br />
The objects in the application are dynamic in nature and need special handling to identify the object. The best example would be of clicking a link which changes according to the user of the application, Ex. “Logout &lt;&lt;UserName&gt;&gt;”.<br />
When object repository is getting huge due to the no. of objects being added. If the size of Object repository increases too much then it decreases the performance of QTP while recognizing a object.<br />
When you don’t want to use object repository at all. Well the first question would be why not Object repository? Consider the following scenario which would help understand why not Object repository</span></span></p>
<p><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><b>Scenario 1:</b> Suppose we have a web application that has not been developed yet. Now QTP for recording the script and adding the objects to repository needs the application to be up, that would mean waiting for the application to be deployed before we can start of with making QTP scripts. But if we know the descriptions of the objects that will be created then we can still start off with the script writing for testing</span></p>
<p><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><b>Scenario 2:</b> Suppose an application has 3 navigation buttons on each and every page. Let the buttons be “Cancel”, “Back” and “Next”. Now recording action on these buttons would add 3 objects per page in the repository. For a 10 page flow this would mean 30 objects which could have been represented just by using 3 objects. So instead of adding these 30 objects to the repository we can just write 3 descriptions for the object and use it on any page.</span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">Modification to a test case is needed but the Object repository for the same is Read only or in shared mode i.e. changes may affect other scripts as well.</span><br />
<span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">When you want to take action on similar type of object i.e. suppose we have 20 textboxes on the page and there names are in the form txt_1, txt_2, txt_3 and so on. Now adding all 20 the Object repository would not be a good programming approach. </span><br />
<span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span><br />
<strong><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">How to use Descriptive programming? </span></strong></p>
<p><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">There are two ways in which descriptive programming can be used<br />
By creating properties collection object for the description.<br />
By giving the description in form of the string arguments.</span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">By creating properties collection object for the description.</span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">To use this method you need first to create an empty description</span><br />
<span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><br />
<strong>Dim obj_Desc ‘Not necessary to declare<br />
Set obj_Desc = Description.Create<br />
</strong><br />
Now we have a blank description in “obj_Desc”. Each description has 3 properties “Name”, “Value” and “Regular Expression”.</span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"> </span></p>
<p><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><strong>obj_Desc(“html tag”).value= “INPUT”<br />
</strong><br />
When you use a property name for the first time the property is added to the collection and when you use it again the property is modified. By default each property that is defined is a regular expression. Suppose if we have the following description</span></p>
<p><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><strong>obj_Desc(“html tag”).value= “INPUT<br />
” obj_Desc(“name”).value= “txt.*”<br />
</strong><br />
This would mean an object with html tag as INPUT and name starting with txt. Now actually that “.*” was considered as regular expression. So, if you want the property “name” not to be recognized as a regular expression then you need to set the “regularexpression” property as FALSE</span></p>
<p><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><strong>obj_Desc(“html tag”).value= “INPUT”<br />
obj_Desc(“name”).value= “txt.*”<br />
obj_Desc(“name”).regularexpression= “txt.*”<br />
</strong><br />
This is how of we create a description. Now below is the way we can use it</span></p>
<p><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><strong>Browser(“Browser”).Page(“Page”).WebEdit(obj_Desc).set “Test”<br />
</strong><br />
When we say .WebEdit(obj_Desc) we define one more property for our description that was not earlier defined that is it’s a text box (because QTPs WebEdit boxes map to text boxes in a web page).</span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">If we know that we have more than 1 element with same description on the page then we must define “index” property for the that description</span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">Consider the HTML code given below</span></p>
<p><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><strong>&lt;INPUT type=”textbox” name=”txt_Name”&gt;<br />
&lt;INPUT type=”textbox” name=”txt_Name”&gt;<br />
</strong><br />
Now the html code has two objects with same description. So distinguish between these 2 objects we will use the “index” property. Here is the description for both the object</span></p>
<p><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><strong>For 1st textbox:<br />
obj_Desc(“html tag”).value= “INPUT”<br />
obj_Desc(“name”).value= “txt_Name<br />
” obj_Desc(“index”).value= “0”<br />
</strong><br />
<strong>For 2nd textbox:<br />
obj_Desc(“html tag”).value= “INPUT”<br />
obj_Desc(“name”).value= “txt_Name”<br />
obj_Desc(“index”).value= “1”<br />
</strong><br />
Consider the HTML Code given below:</span></p>
<p><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><strong>&lt;INPUT type=”textbox” name=”txt_Name”&gt;<br />
&lt;INPUT type=”radio” name=”txt_Name”&gt;</strong></span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"> </span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">We can use the same description for both the objects and still distinguish between both of them</span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><strong>obj_Desc(“html tag”).value= “INPUT”<br />
obj_Desc(“name”).value= “txt_Name”<br />
</strong><br />
When I want to refer to the textbox then I will use the inside a WebEdit object and to refer to the radio button I will use the description object with the WebRadioGroup object.</span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><strong>Browser(“Browser”).Page(“Page”).WebEdit(obj_Desc).set “Test” ‘Refers to the text box<br />
Browser(“Browser”).Page(“Page”).WebRadioGroup(obj_Desc).set “Test” ‘Refers to the radio button<br />
</strong><br />
But if we use WebElement object for the description then we must define the “index” property because for a webelement the current description would return two objects.<br />
<b><br />
Hierarchy of test description:</b><br />
When using programmatic descriptions from a specific point within a test object hierarchy, you must continue to use programmatic descriptions from that point onward within the same statement. If you specify a test object by its object repository name after other objects in the hierarchy have been described using programmatic descriptions, QuickTest cannot identify the object.</span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">For example, you can use <strong>Browser(Desc1).Page(Desc1).Link(desc3),</strong> since it uses programmatic descriptions throughout the entire test object hierarchy. You can also use <strong>Browser(&#8220;Index&#8221;).Page(Desc1).Link(desc3),</strong> since it uses programmatic descriptions from a certain point in the description (starting from the Page object description).</span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">However, you cannot use Browser(Desc1).Page(Desc1).Link(&#8220;Example1&#8243;), since it uses programmatic descriptions for the Browser and Page objects but then attempts to use an object repository name for the Link test object (QuickTest tries to locate the Link object based on its name, but cannot locate it in the repository because the parent objects were specified using programmatic descriptions).</span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><b>Getting Child Object:</b><br />
We can use description object to get all the objects on the page that matches that specific description. Suppose we have to check all the checkboxes present on a web page. So we will first create an object description for a checkboxe and then get all the checkboxes from the page</span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><strong>Dim obj_ChkDesc<br />
Set obj_ChkDesc=Description.Create<br />
obj_ChkDesc(“html tag”).value = “INPUT”<br />
obj_ChkDesc(“type”).value = “checkbox”<br />
</strong><br />
<strong>Dim allCheckboxes, singleCheckBox<br />
Set allCheckboxes = Browse(“Browser”).Page(“Page”).ChildObjects(obj_ChkDesc)</strong><br />
<span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;">For each singleCheckBox in allCheckboxes</span></span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"></span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><strong>singleCheckBox.Set “ON”<br />
</strong><br />
Next<br />
The above code will check all the check boxes present on the page. To get all the child objects we need to specify an object description i.e. we can’t use the string arguments that will be discussed later in the 2nd way of using the programming description.</span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"><b>Possible Operation on Description Object</b></span><span style="font-size:10pt;color:black;line-height:150%;font-family:Verdana;"> Consider the below code for all the solutions<br />
<strong>Dim obj_ChkDesc</strong><strong> Set obj_ChkDesc=Description.Create<br />
obj_ChkDesc(“html tag”).value = “INPUT”<br />
obj_ChkDesc(“type”).value = “checkbox” </strong></span></span></p>
<p align="right"><a href="http://kuldeepse.wordpress.com/2008/02/04/1-declaring-variables/"><font color="#000044">Next Step &#8211; Variable Declaration</font></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kuldeepse.wordpress.com/126/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kuldeepse.wordpress.com/126/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kuldeepse.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kuldeepse.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kuldeepse.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kuldeepse.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kuldeepse.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kuldeepse.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kuldeepse.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kuldeepse.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kuldeepse.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kuldeepse.wordpress.com/126/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=126&subd=kuldeepse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kuldeepse.wordpress.com/2008/02/05/steps-for-learning-descriptive-programming/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b37d5959686c283f564079068ff8246f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kuldeep</media:title>
		</media:content>
	</item>
		<item>
		<title>10: FileSystemObject</title>
		<link>http://kuldeepse.wordpress.com/2008/02/05/10-filesystemobject/</link>
		<comments>http://kuldeepse.wordpress.com/2008/02/05/10-filesystemobject/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 11:49:47 +0000</pubDate>
		<dc:creator>kuldeep kumar</dc:creator>
				<category><![CDATA[Learn VBScript for QTP (Descriptive Programming)]]></category>

		<guid isPermaLink="false">http://kuldeepse.wordpress.com/?p=125</guid>
		<description><![CDATA[Managing Files and Folders 
As you have already seen this afternoon the FileSystemObject is actually fairly easy to work with. All that you have to do is establish an instance of it and you can start using its properties and methods. In the sections that follow you’ll see examples of how to use this object [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=125&subd=kuldeepse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong><span style="font-size:10pt;font-family:Verdana;">Managing Files and Folders </span></strong><br />
<span style="font-family:Verdana;"><font size="2">As you have already seen this afternoon the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> is actually fairly easy to work with. All that you have to do is establish an instance of it and you can start using its properties and methods. In the sections that follow you’ll see examples of how to use this object to create, copy, move, and delete files and folders.</font></span><br />
<strong><span style="font-size:10pt;font-family:Verdana;">Copying Files</span></strong><br />
<span style="font-family:Verdana;"><font size="2">Using the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">CopyFile()</span></span> method you can copy one or more files. For example, you might want to copy all the files in the folder on your computer to a network drive at the end of each day. I’ll show you how to work with network drives this evening. For now let’s just focus on how the <span class="fixed1"><span style="font-family:Verdana;">CopyFile()</span></span> method works.</font></span><span style="font-family:Verdana;"><font size="2">The first step in copying a file is to set up an instance of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span>. Then you can execute its <span class="fixed1"><span style="font-family:Verdana;">CopyFile()</span></span> method as shown here.</font><font size="2"> </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">fsoObject.CopyFile("d:\ displayText.txt", "d:\myDocs\ displayText.txt")</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">In this example, a file named <span class="fixed1"><span style="font-family:Verdana;">myFile.txt</span></span> is copied from the root folder on the <span class="fixed1"><span style="font-family:Verdana;">C:</span></span> drive to a folder named <span class="fixed1"><span style="font-family:Verdana;">myDocs</span></span> located on the computer’s <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drive. You can modify this example to copy more than one file using wildcard characters as shown in the next example. Here all files in the root directly with a filename of <span class="fixed1"><span style="font-family:Verdana;">myFile</span></span> are copied to the destination folder regardless of their file extension. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">fsoObject.CopyFile("d:\ displayText.*", "d:\Docs")</font></span></b></pre>
<h4><span style="font-size:10pt;font-family:Verdana;">Moving Files</span></h4>
<p><span style="font-family:Verdana;"><font size="2">Moving files is similar to copying them except that instead of leaving the original file in place and placing a duplicate copy in the destination location, the original file is moved leaving only one copy of the file. You can move one or more files using the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">MoveFile()</span></span> method.</font></span><span style="font-family:Verdana;"><font size="2">For example, you can move all files with a <span class="fixed1"><span style="font-family:Verdana;">.txt </span></span>file extension found in the root of the <span class="fixed1"><span style="font-family:Verdana;">C:</span></span> drive to a <span class="fixed1"><span style="font-family:Verdana;">myDocs</span></span> folder on the <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drive using the following VBScript statements. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">fsoObject.MoveFile("c:\*.txt", "c:\Docs")</font></span></b></pre>
<p><strong><span style="font-size:10pt;font-family:Verdana;">Deleting Files</span></strong><br />
<span style="font-family:Verdana;"><font size="2">You can use the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">DeleteFile()</span></span> method to delete one or more files. For example, you might want to write a script that cleans out a folder at the end of each day or that deletes files after reading and processing them. You can delete one or more files as demonstrated here. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">fsoObject.DeleteFile("d:\*.txt")</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">Here all files that have a <span class="fixed1"><span style="font-family:Verdana;">.txt</span></span> file extension located in the root of the <span class="fixed1"><span style="font-family:Verdana;">C:</span></span> drive will be deleted.</font></span><br />
<strong><span style="font-size:10pt;font-family:Verdana;">Creating a Folder</span></strong><br />
<span style="font-family:Verdana;"><font size="2">Working with folders is similar to working with files. You can use the <span class="fixed1"><span style="font-family:Verdana;">FolderExists(</span></span>) method of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> to determine if a folder exists. If the folder does not exist, you can create it using the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">CreateFolder()</span></span> method as demonstrated here. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">If (fsoObject.FolderExists("d:\Docs") = false) Then</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Set myFolder = fsoObject.CreateFolder("d:\Docs")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">End If</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">The first thing that this example does is check to see if a folder named <span class="fixed1"><span style="font-family:Verdana;">myDocs</span></span> already exists on the computer’s <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drive. If it does not exist, then the folder is created. Otherwise nothing happens.</font></span><br />
<strong><span style="font-size:10pt;font-family:Verdana;">Copying Folders</span></strong><br />
<span style="font-family:Verdana;"><font size="2">Copying a folder is pretty much the same as copying a file. The folder and all its contents are copied to a new location leaving the original copy still in place. You can copy folders using the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">CopyFolder()</span></span> method.</font></span><span style="font-family:Verdana;"><font size="2">Take a look at the following example. It copies a folder named <span class="fixed1"><span style="font-family:Verdana;">myDocs</span></span> located on the computer’s <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drive to its <span class="fixed1"><span style="font-family:Verdana;">C:</span></span> drive. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">fsoObject.CopyFolder("c:\Docs", "d:\Docs")</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">As you can see the <span class="fixed1"><span style="font-family:Verdana;">CopyFolder()</span></span> methods requires two arguments, the source and destination folder names, including their complete paths. By changing the name assigned to the destination folder, you can rename the folder as part of the copy operation as demonstrated here. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">fsoObject.CopyFolder("c:\Docs", "d:\NewDocs")</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">If the destination folder already exists, then the contents of the source folder are copied into it alongside its current contents. The <span class="fixed1"><span style="font-family:Verdana;">CopyFolder()</span></span> method supports an additional third parameter that allows you to tell it what to do if the destination folder contains files with duplicate filenames of those found in the source folder. This parameter is set to either a value of <span class="fixed1"><span style="font-family:Verdana;">true</span></span> or <span class="fixed1"><span style="font-family:Verdana;">false</span></span>. Setting it to <span class="fixed1"><span style="font-family:Verdana;">true</span></span> causes any matching files to be overridden. Setting it to <span class="fixed1"><span style="font-family:Verdana;">false</span></span> prevents this from happening. Let’s look at a couple examples.</font><font size="2"> </font></span><span style="font-family:Verdana;"><font size="2">The first example prevents files with duplicate filenames from being overridden.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">fsoObject.CopyFolder("c:\Docs", "d:\Docs", "False")</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">The second example allows files with duplicate names to be overridden in the destination folder.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">fsoObject.CopyFolder("c:\Docs", "d:\Docs", "True")</font></span></b></pre>
<p><strong><span style="font-size:10pt;font-family:Verdana;">Moving Folders</span></strong><br />
<span style="font-family:Verdana;"><font size="2">Moving a folder works pretty much the same as copying one except that moving the folder leaves you with only the one copy. You can move folders using the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">MoveFolder()</span></span> method. This method moves a folder and all its contents, including subfolders, to a new destination.</font></span><span style="font-family:Verdana;"><font size="2">For example, the following VBScript statements move a folder called <span class="fixed1"><span style="font-family:Verdana;">myDocs</span></span> from the computer’s <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drive to its <span class="fixed1"><span style="font-family:Verdana;">C:</span></span> drive. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">fsoObject.MoveFolder("c:\Docs", "d:\Docs")</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">If a folder with the same name already exists at the root of the computer’s <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drive, then the contents of the source folder will be copied into the existing destination along side its current contents.</font></span></p>
<h4><span style="font-size:10pt;font-family:Verdana;">Deleting Folders</span></h4>
<p><span style="font-family:Verdana;"><font size="2">You can delete one or more folders using the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">DeleteFolder()</span></span> method. This method deletes a folder and all its contents, including subfolders. For example, the following VBScript statements can be used to delete a folder named <span class="fixed1"><span style="font-family:Verdana;">myDocs</span></span> located on a computer’s <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drive. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">fsoObject.DeleteFolder("d:\Docs")</font></span></b></pre>
<p><strong><span style="font-size:10pt;font-family:Verdana;">Managing Files with the File Object</span></strong></p>
<p><span style="font-family:Verdana;"><font size="2">The <span class="fixed1"><span style="font-family:Verdana;">File</span></span> Object allows you to work with one file at a time as opposed to the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span>, which lets you manage multiple files. Using the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> object instead of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> requires a little more work. You still have to create an instance of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> to interact with the file system. You also need to use the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">GetFile()</span></span> method to retrieve a <span class="fixed1"><span style="font-family:Verdana;">File</span></span> object that represents the file that your script will be managing. Once these two things are set up you can execute any of the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> object’s methods.</font></span></p>
<h4><span style="font-size:10pt;font-family:Verdana;">Copying a File</span></h4>
<p><span style="font-family:Verdana;"><font size="2">Using the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">Copy()</span></span> method you can copy a file from one location to another. This method does not support the use of wildcard characters and cannot therefore be used to copy multiple files.</font></span><span style="font-family:Verdana;"><font size="2">The following example demonstrates how to use the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">Copy()</span></span> method to copy a file named <span class="fixed1"><span style="font-family:Verdana;">myFile.txt</span></span> from the <span class="fixed1"><span style="font-family:Verdana;">myDocs</span></span> folder on the computer’s <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drive to the root of the <span class="fixed1"><span style="font-family:Verdana;">C:</span></span> drive.</font><font size="2"> </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Set source_file = fsoObject.GetFile("c:\Docs\ displayText.txt")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">source_file.Copy("d:\")</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">In this example, the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">GetFile()</span></span> method is used to establish a reference to the file that is to be copied. Then the <span class="fixed1"><span style="font-family:Verdana;">Copy()</span></span> method is used to set the destination where the file is to be copied.</font></span></p>
<p><strong><span style="font-size:10pt;font-family:Verdana;">Moving a File</span></strong></p>
<p><span style="font-family:Verdana;"><font size="2">As you probably expect by now, moving a file using the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">Move()</span></span> method works almost exactly like copying it using the <span class="fixed1"><span style="font-family:Verdana;">Copy()</span></span> method. For example, the following VBScript statements demonstrate how to move a file from one location to another. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Set source_file = fsoObject.GetFile("c:\Docs\ displayText.txt")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">source_file.Move("d:\")</font></span></b></pre>
<h4><span style="font-size:10pt;font-family:Verdana;">Deleting a File</span></h4>
<p><span style="font-family:Verdana;"><font size="2">You can delete an individual file using the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> Object’s <span class="fixed1"><span style="font-family:Verdana;">Delete()</span></span> method. Like the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> object’s other methods, the <span class="fixed1"><span style="font-family:Verdana;">Delete()</span></span> method does not support wildcard characters limiting it to being able to delete just one file at a time.</font></span><span style="font-family:Verdana;"><font size="2">Take a look at the following example. Here a file named <span class="fixed1"><span style="font-family:Verdana;">myFile.txt</span></span> is deleted from a folder named <span class="fixed1"><span style="font-family:Verdana;">myDocs</span></span> located on the computer’s <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drive. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Set source_file = fsoObject.GetFile("c:\Docs\ displayText.txt ")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">source_file.Delete()</font></span></b></pre>
<p><strong><span style="font-size:10pt;font-family:Verdana;">Managing Folders with the Folder Object</span></strong><br />
<span style="font-family:Verdana;"><font size="2">The <span class="fixed1"><span style="font-family:Verdana;">Folder</span></span> object is similar to the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> object only it works with one folder at a time instead of one file at a time. Like the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> object, it requires a little more work to set up than does simply using the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span>. First, you’ll need to instantiate the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span>. Then you must use the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">GetFolder()</span></span> method to retrieve a <span class="fixed1"><span style="font-family:Verdana;">Folder</span></span> object that represents the folder that your script will be working with. Once these two things are set up you can execute any of the <span class="fixed1"><span style="font-family:Verdana;">Folder</span></span> object’s methods.</font><font size="2"> </font></span></p>
<h4><span style="font-size:10pt;font-family:Verdana;">Copying a Folder</span></h4>
<p><span style="font-family:Verdana;"><font size="2">Like the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> object, the <span class="fixed1"><span style="font-family:Verdana;">Folder</span></span> object supports the <span class="fixed1"><span style="font-family:Verdana;">Copy()</span></span> method. Because it doesn’t support wildcard characters it is useful only when you want to work with a single folder at a time. The <span class="fixed1"><span style="font-family:Verdana;">Copy()</span></span> method copies the folder and all its contents, including any subfolders, to a new location.</font></span><span style="font-family:Verdana;"><font size="2">For example, the following VBScript statements demonstrate how to use the <span class="fixed1"><span style="font-family:Verdana;">Copy()</span></span> method. In this case a folder named <span class="fixed1"><span style="font-family:Verdana;">myDocs</span></span> is copied from the root of the computer’s <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drive to the root of the computer’s <span class="fixed1"><span style="font-family:Verdana;">C:</span></span> drive. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Set source_folder = fsoObject.GetFolder("d:\Docs")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">source_folder.Copy("c:\")</font></span></b></pre>
<p><strong><span style="font-size:10pt;font-family:Verdana;">Moving a Folder</span></strong><br />
<span style="font-family:Verdana;"><font size="2">The <span class="fixed1"><span style="font-family:Verdana;">Folder</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">Move()</span></span> method lets you move a folder from one location to another. This method recursively copies a folder and all its contents. Because it does not support wildcard characters, this method can only move one folder at a time, as opposed to the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">MoveFolder()</span></span> method, which can move any number of folders in a single operation.</font></span><span style="font-family:Verdana;"><font size="2">The following example demonstrates how to use this method to move a folder. In this case the folder is named <span class="fixed1"><span style="font-family:Verdana;">myDocs</span></span> and it is moved from the computer’s <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drive to its <span class="fixed1"><span style="font-family:Verdana;">C:</span></span> drive.</font><font size="2"> </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Set source_folder = fsoObject.GetFolder("d:\Docs")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">source_folder.Move("c:\")</font></span></b></pre>
<h4><span style="font-size:10pt;font-family:Verdana;">Deleting a Folder</span></h4>
<p><span style="font-family:Verdana;"><font size="2">You can delete a folder using the <span class="fixed1"><span style="font-family:Verdana;">Folder</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">Delete()</span></span> method. Wildcard character matching is not supported so it only works with one folder at a time. If you need to delete more than one folder you can use the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">DeleteFolder()</span></span> method, discussed earlier in this chapter.</font></span><span style="font-family:Verdana;"><font size="2">This method deletes the specified folder and all its contents, including subfolders. Its use is demonstrated here.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Set source_folder = fsoObject.GetFolder("d:\Docs")</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">source_folder.Delete()</font></span></b></pre>
<p align="right"><a href="http://kuldeepse.wordpress.com/2007/11/11/qtp-script-for-sending-a-mail-using-outlook/"><font color="#000044">Next Step &#8211; QTP Script Examples</font></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kuldeepse.wordpress.com/125/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kuldeepse.wordpress.com/125/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kuldeepse.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kuldeepse.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kuldeepse.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kuldeepse.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kuldeepse.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kuldeepse.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kuldeepse.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kuldeepse.wordpress.com/125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kuldeepse.wordpress.com/125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kuldeepse.wordpress.com/125/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=125&subd=kuldeepse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kuldeepse.wordpress.com/2008/02/05/10-filesystemobject/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b37d5959686c283f564079068ff8246f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kuldeep</media:title>
		</media:content>
	</item>
		<item>
		<title>9: Scripting related to File system</title>
		<link>http://kuldeepse.wordpress.com/2008/02/05/9-scripting-related-to-file-system/</link>
		<comments>http://kuldeepse.wordpress.com/2008/02/05/9-scripting-related-to-file-system/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 11:16:24 +0000</pubDate>
		<dc:creator>kuldeep kumar</dc:creator>
				<category><![CDATA[Learn VBScript for QTP (Descriptive Programming)]]></category>

		<guid isPermaLink="false">http://kuldeepse.wordpress.com/?p=124</guid>
		<description><![CDATA[Working with File System
The main runtime object is the FileSystemObject from which all other runtime objects are derived (except for the dictionary object, which is independent of the FileSystemObject). lists of VBScript runtime objects.


FileSystemObject 

Object
Access Provided


Drive 
Disk drive properties


Drives Collection 
System drive information


File 
File properties


Files Collection 
All files contained in the specified folder


Folder 
Folder properties


Folders [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=124&subd=kuldeepse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong><span style="font-size:10pt;font-family:Verdana;"><em>Working with File System</em></span></strong><br />
<span style="font-family:Verdana;"><font size="2">The main runtime object is the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> from which all other runtime objects are derived (except for the <span class="fixed1"><span style="font-family:Verdana;">dictionary</span></span> object, which is independent of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span>). lists of VBScript runtime objects.</font></span></p>
<table border="1" width="373" cellPadding="0" style="width:373px;height:226px;" class="MsoNormalTable">
<thead>
<td colSpan="2" style="background:white;border:#ece9d8;padding:0.75pt;"><strong><span><span style="font-size:10pt;font-family:Verdana;">FileSystemObject</span> </span></strong></td>
<tr>
<td width="50%" vAlign="top" style="background:white;width:50%;border:#ece9d8;padding:0.75pt;"><b><span style="font-size:10pt;font-family:Verdana;">Object</span></b></td>
<td width="50%" vAlign="top" style="background:white;width:50%;border:#ece9d8;padding:0.75pt;"><b><span style="font-size:10pt;font-family:Verdana;">Access Provided</span></b></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span class="fixed1"><span style="font-size:10pt;font-family:Verdana;">Drive</span></span><span style="font-size:10pt;font-family:Verdana;"> </span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Disk drive properties</span></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span class="fixed1"><span style="font-size:10pt;font-family:Verdana;">Drives Collection</span></span><span style="font-size:10pt;font-family:Verdana;"> </span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">System drive information</span></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span class="fixed1"><span style="font-size:10pt;font-family:Verdana;">File</span></span><span style="font-size:10pt;font-family:Verdana;"> </span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">File properties</span></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span class="fixed1"><span style="font-size:10pt;font-family:Verdana;">Files Collection</span></span><span style="font-size:10pt;font-family:Verdana;"> </span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">All files contained in the specified folder</span></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span class="fixed1"><span style="font-size:10pt;font-family:Verdana;">Folder</span></span><span style="font-size:10pt;font-family:Verdana;"> </span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Folder properties</span></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span class="fixed1"><span style="font-size:10pt;font-family:Verdana;">Folders Collection</span></span><span style="font-size:10pt;font-family:Verdana;"> </span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">All folders contained in the specified folder</span></td>
</tr>
</thead>
</table>
<p><span style="font-family:Verdana;"><font size="2">To use the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> within your VBScripts you must first establish an instance of it. You can do this using the <span class="fixed1"><span style="font-family:Verdana;">WScript</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">CreateObject()</span></span> method and by referencing it as <span class="fixed1"><span style="font-family:Verdana;">Scripting. FileSystemObject</span></span>. This is demonstrated in the following example. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = WScript.CreateObject ("Scripting.FileSystemObject")</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">Here <span class="fixed1"><span style="font-family:Verdana;">fsoObject</span></span> is just the name that I assigned to a variable that can now be used by the rest of the script to reference the properties and methods of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span>. With this instance of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> now established the script is read to interact with the Windows file system.</font></span><span style="font-family:Verdana;"><font size="2">Let’s put this previous <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> example to work in a few quick examples to see how it really works.</font><font size="2"> </font></span><br />
<span style="font-size:10pt;font-family:Verdana;">Displaying Drive Free Space</span></p>
<h3></h3>
<p><span style="font-family:Verdana;"><font size="2">This first example demonstrates how to use a number of methods and properties of the VBScript runtime objects to access drive information. Specifically the example shown here displays the amount of free space on a computer’s <span class="fixed1"><span style="font-family:Verdana;">C:</span></span> and <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drives. </font></span></p>
<pre>
<b><span style="font-family:Verdana;"><font size="2">' * Script Name: Script 5.vbs<span>       </span>*</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">On Error Resume Next</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">dim fsoObject, drive1, drive2</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">set drive1 = fsoObject.GetDrive(fsoObject.GetDriveName("c:"))</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">set drive2 = fsoObject.GetDrive(fsoObject.GetDriveName("d:"))</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' ********* Main processing section **********</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' Call a function that displays drive information</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Free_Space()</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' *********** Procedures go here *************</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' This function displays the amount of free space on drive 1 and drive 2</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Function Free_Space()</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo( "Free Space on drive 1 is: " _</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span>  </span>&amp; FormatNumber(drive1.FreeSpace / 1024 , 0) &amp; " KB")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo( "Free Space on drive 2 is: " _</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span>  </span>&amp; FormatNumber(drive2.FreeSpace / 1024 , 0) &amp; " KB")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">End Function</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">The script begins by defining three variables. The first variable is <span class="fixed1"><span style="font-family:Verdana;">fsoObject</span></span>. It will be used to create an instance of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject </span></span>as discussed earlier. The next two variables will be used to set up references to the computer’s <span class="fixed1"><span style="font-family:Verdana;">C:</span></span> and <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drives.</font></span><span style="font-family:Verdana;"><font size="2">The two statements that set up the values of these two variables for the computer’s drives probably look a little complex to you at first. So let’s take a moment and break them down. First, the <span class="fixed1"><span style="font-family:Verdana;">GetDriveName()</span></span> method of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> is used by appending it to the variable <span class="fixed1"><span style="font-family:Verdana;">fsoObject</span></span> (for example, <span class="fixed1"><span style="font-family:Verdana;">fsoObject.GetDriveName()</span></span>). Remember that the <span class="fixed1"><span style="font-family:Verdana;">fsoObject</span></span> variable provides the script with a reference to the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> and its properties and methods. The <span class="fixed1"><span style="font-family:Verdana;">GetDriveName()</span></span> method returns the name of the drive associated with the specified driver letter (that is, <span class="fixed1"><span style="font-family:Verdana;">C:</span></span> or <span class="fixed1"><span style="font-family:Verdana;">D:</span></span>). Next, the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">GetDrive()</span></span> method is used to retrieve the <span class="fixed1"><span style="font-family:Verdana;">Drive</span></span> object associated with the specified drive name. The reason that we need to establish a reference to the <span class="fixed1"><span style="font-family:Verdana;">Drive</span></span> object is because we are going to want to use its <span class="fixed1"><span style="font-family:Verdana;">Freespace</span></span> property a little later in the script.</font><font size="2"> </font></span><span style="font-family:Verdana;"><font size="2">After executing the statements in the script’s initialization section, the VBScript statement in the main processing section executes. There is only one VBScript statement in this section and it calls a function named <span class="fixed1"><span style="font-family:Verdana;">Display_Msg()</span></span>. The function then executes. Its job is to display the amount of free space on each drive. This is accomplished by taking the amount of free space left on a given drive as contained by the <span class="fixed1"><span style="font-family:Verdana;">Drive</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">FreeSpace</span></span> property and dividing it by 1024 (1 kilobyte or 1 KB). The results are then formatted using the <span class="fixed1"><span style="font-family:Verdana;">Drive</span></span> object’s<span class="fixed1"><span style="font-family:Verdana;"> FormatNumber()</span></span> method, which in this case formats the number with zero trailing decimal spaces (that is, as whole number).</font></span><span style="font-family:Verdana;"><font size="2">When I ran this script on my computer, I got the following results.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">C:\&gt;CScript "Script 5.vbs"</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Microsoft (R) Windows Script Host Version 5.6</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Free Space on drive 1 is: 11,116 KB</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Free Space on drive 2 is: 15,784 KB</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">C:\&gt;</font></span></b></pre>
<p><span style="font-size:10pt;font-family:Verdana;">Examining File System Types</span><br />
<span style="font-family:Verdana;"><font size="2">Let’s look at another example of how to work with the methods and properties of the VBScript runtime objects. This time we’ll write a VBScript example that displays the type of file system that the computer’s <span class="fixed1"><span style="font-family:Verdana;">C:</span></span> and <span class="fixed1"><span style="font-family:Verdana;">D:</span></span> drives have been formatted with. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">' * Script Name: Script 6.vbs<span></span>*</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">On Error Resume Next</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">dim fsoObject, drive1, drive2</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">set drive1 = fsoObject.GetDrive("C:")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">set drive2 = fsoObject.GetDrive("D:")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' ********* Main processing section **********</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' Call a function that displays drive information</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Used_Disk()</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' *********** Procedures go here *************</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' This function displays the file system used to format drive 1 and drive 2</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Function Used_Disk()</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo("The file system used on drive 1 is: " &amp; drive1.FileSystem)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo("The file system used on drive 2 is: " &amp; drive2.FileSystem)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">End Function</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">As you can see this VBScript is similar to the previous example. The same variables are defined in the initialization section. In addition, the same instance of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> is set up and once again its <span class="fixed1"><span style="font-family:Verdana;">GetDrive()</span></span> method is used to retrieve <span class="fixed1"><span style="font-family:Verdana;">Drive</span></span> object references to each drive on the computer.</font></span><span style="font-family:Verdana;"><font size="2">Next, a single VBScript statement in the main processing section calls a function that displays a file system type for each drive. This is accomplished by using <span class="fixed1"><span style="font-family:Verdana;">Drive</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">FileSystem</span></span> property.</font></span><span style="font-family:Verdana;"><font size="2">When I ran this script on my computer I received the following results.</font><font size="2"> </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">C:\&gt;CScript "Script 6.vbs"</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Microsoft (R) Windows Script Host Version 5.6</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">The file system used on drive 1 is: NTFS</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">The file system used on drive 2 is: NTFS</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">C:\&gt;</font></span></b></pre>
<p><span style="font-size:10pt;font-family:Verdana;">Examining File Properties</span><br />
<span style="font-family:Verdana;"><font size="2">Let’s look at one final example before we rush off and begin to master the art of reading from and writing to text files. This example starts off like the previous two examples by defining its variables and instantiating an instance of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span>. This time the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">GetFile()</span></span> method is used. This method is used to retrieve the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> object associated with the specified file, which in this example is <span class="fixed1"><span style="font-family:Verdana;">c:\winzip.log</span></span>.</font></span><span style="font-family:Verdana;"><font size="2">Again, a VBScript statement in the main processing section calls on a function named <span class="fixed1"><span style="font-family:Verdana;">Display_Msg()</span></span>. The function contains a number of <span class="fixed1"><span style="font-family:Verdana;">WScript.Echo</span></span> statements each of which displays a different property associated with the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> object. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">' ********************************************</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' * Script Name: Script 7.vbs<span>       </span>*</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' * Author: Kuldeep<span>            </span>*</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' * Created: 03/02/08<span>            </span>*</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' ********************************************</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' **** Perform script initialization here ****</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">On Error Resume Next</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">dim fsoObject, targetFile</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">set targetFile = fsoObject.GetFile("d:\Test.vbs")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' ********* Main processing section **********</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' Call a function that displays drive information</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Details()</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' *********** Procedures go here *************</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' This function displays file properties</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Function Details()</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo("File properties of d:\Test.vbs")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo("-----------------------------------")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo("Created on:<span>  </span>" &amp; targetFile.DateCreated)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo("Last Modified: " &amp; targetFile.DateLastModified)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo("Last Accessed: " &amp; targetFile.DateLastAccessed)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo("File Name:<span>   </span>" &amp; targetFile.Name)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo("File Path:<span>   </span>" &amp; targetFile.Path)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo("File Type:<span>   </span>" &amp; targetFile.Type)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo("File Size:<span>   </span>" &amp; targetFile.Size)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">End Function</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">The following output was displayed when I ran this script.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">C:\&gt;CScript "Script 7.vbs"</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Microsoft (R) Windows Script Host Version 5.6</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">File properties of d:\Test.vbs</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">-----------------------------------</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Created on:<span>  </span>2/4/2008 11:23:36 PM</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Last Modified: 2/4/2008 10:38:52 AM</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Last Accessed: 2/4/2008</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">File Name:<span>   </span>Test.vbs</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">File Path:<span>   </span>D:\Test.vbs</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">File Type:<span>   </span>VBScript Script File </font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">File Size:<span>   </span>1081</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">C:\&gt;</font></span></b> <b><span style="font-family:Verdana;"><font size="2"> </font></span></b></pre>
<p><span style="font-size:10pt;font-family:Verdana;"><em>Creating Documents, Reports, and Logs</em></span><span style="font-family:Verdana;"><font size="2">By this point you should have a fairly good understanding of what the VBScript runtime objects are and what they can do. Now let’s look at how you can use them to generate reports, logs, and other types of text documents.</font></span><span style="font-family:Verdana;"><font size="2">To work with files and their contents you must first establish an instance of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> within your VBScript as shown here. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">Next, you should always check to see if the file that you want to work with already exists. If it does, you can open it. If it does not already exist, you can create it and then open it. You can check to see if a file exists using the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">FileExists</span></span> property as shown here. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">If (fsoObject.FileExists("C:\displayText.txt" ) ) Then</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">You must open a file before you can work with it. You can use the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">OpenTextFile()</span></span> method to open files. To use this method you need to supply a few pieces of information including the following.</font></span><span style="font-family:Verdana;"><font size="2"> </font></span><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><span style="font-family:Verdana;"><font size="2">The name and path of the file to be opened</font></span><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><span style="font-family:Verdana;"><font size="2">Whether you want the file to be opened for reading, writing, or appending</font></span><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><span style="font-family:Verdana;"><font size="2">Whether to create the file if it does not exist</font></span><span style="font-family:Verdana;"><span style="color:windowtext;"><font size="2">Table </font></span><font size="2">defines constants that are used to tell the <span class="fixed1"><b><span style="font-family:Verdana;">OpenTextFile()</span></b></span> method what you want to do once the file is opened.</font></span><span style="font-family:Verdana;"><font size="2"> </font></span></p>
<table border="1" width="501" cellPadding="0" style="width:501px;height:122px;" class="MsoNormalTable">
<thead>
<td colSpan="3" style="background:white;border:#ece9d8;padding:0.75pt;"><strong><span class="fixed1"><span style="font-size:10pt;font-family:Verdana;">OpenTextFile()</span></span><span><span style="font-size:10pt;font-family:Verdana;"><font color="#800000"> Constants</font></span> </span></strong></td>
<tr>
<td width="36%" vAlign="top" style="background:white;width:36%;border:#ece9d8;padding:0.75pt;"><b><span style="font-size:10pt;font-family:Verdana;">Constant</span></b></td>
<td width="32%" vAlign="top" style="background:white;width:32%;border:#ece9d8;padding:0.75pt;"><b><span style="font-size:10pt;font-family:Verdana;">Description</span></b></td>
<td width="32%" vAlign="top" style="background:white;width:32%;border:#ece9d8;padding:0.75pt;"><b><span style="font-size:10pt;font-family:Verdana;">Value</span></b></td>
</tr>
<tr>
<td width="36%" vAlign="top" style="width:36%;background-color:transparent;border:#ece9d8;padding:0;"><span class="fixed1"><span style="font-size:10pt;font-family:Verdana;">ForReading</span></span><span style="font-size:10pt;font-family:Verdana;"> </span></td>
<td width="32%" vAlign="top" style="width:32%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Opens a file for reading</span></td>
<td width="32%" vAlign="top" style="width:32%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">1</span></td>
</tr>
<tr>
<td width="36%" vAlign="top" style="width:36%;background-color:transparent;border:#ece9d8;padding:0;"><span class="fixed1"><span style="font-size:10pt;font-family:Verdana;">ForWriting</span></span><span style="font-size:10pt;font-family:Verdana;"> </span></td>
<td width="32%" vAlign="top" style="width:32%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Opens a file for writing</span></td>
<td width="32%" vAlign="top" style="width:32%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">2</span></td>
</tr>
<tr>
<td width="36%" vAlign="top" style="width:36%;background-color:transparent;border:#ece9d8;padding:0;"><span class="fixed1"><span style="font-size:10pt;font-family:Verdana;">ForAppending</span></span><span style="font-size:10pt;font-family:Verdana;"> </span></td>
<td width="32%" vAlign="top" style="width:32%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Opens a file for appending</span></td>
<td width="32%" vAlign="top" style="width:32%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">8</span></td>
</tr>
</thead>
</table>
<p><span style="font-family:Verdana;"><span style="color:windowtext;"><font size="2">Table </font></span><font size="2">defines two options that govern what the <span class="fixed1"><b><span style="font-family:Verdana;">OpenTextFile()</span></b></span> method should do when the file to be opened does and does not exist.</font></span><span style="font-family:Verdana;"><font size="2"> </font></span></p>
<table border="1" width="419" cellPadding="0" style="width:419px;height:130px;" class="MsoNormalTable">
<thead>
<td colSpan="2" style="background:white;border:#ece9d8;padding:0.75pt;"><strong><span class="table-titlelabel"><span style="font-size:10pt;font-family:Verdana;">Table : </span></span><span class="fixed1"><span style="font-size:10pt;font-family:Verdana;">OpenTextFile()</span></span><span><span style="font-size:10pt;font-family:Verdana;"><font color="#800000"> File Creation Options</font></span> </span></strong></td>
<tr>
<td width="50%" vAlign="top" style="background:white;width:50%;border:#ece9d8;padding:0.75pt;"><b><span style="font-size:10pt;font-family:Verdana;">Value</span></b></td>
<td width="50%" vAlign="top" style="background:white;width:50%;border:#ece9d8;padding:0.75pt;"><b><span style="font-size:10pt;font-family:Verdana;">Description</span></b></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span class="fixed1"><span style="font-size:10pt;font-family:Verdana;">True</span></span><span style="font-size:10pt;font-family:Verdana;"> </span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Open the file if it exists, otherwise create and open it</span></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span class="fixed1"><span style="font-size:10pt;font-family:Verdana;">False</span></span><span style="font-size:10pt;font-family:Verdana;"> </span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Open the file if it exists, otherwise do not create it</span></td>
</tr>
</thead>
</table>
<p><span style="font-size:10pt;font-family:Verdana;">Opening and Closing Files</span></p>
<h3></h3>
<p><span style="font-family:Verdana;"><font size="2">It is very important that you correctly specify the type of operation that you are opening a file for (reading, writing, or appending). If you open a file to write to it and the file exists, then the file will be reinitialized. In other words, any data that is already in the file is lost and the file pointer is placed at the beginning of the new file (in the first row and column of the file).</font></span><span style="font-family:Verdana;"><font size="2">By appending to a file, you are able to preserve its contents and add to it. In other words, the file is opened and the file pointer is placed at the end of the file in the last row and column position.</font></span><span style="font-family:Verdana;"><font size="2">The file pointer is used to identify where the next character of data will be placed with a file. In a newly initialized file, the pointer would automatically be positioned in the upper-left corner (row 0, column 0). If one new character of information were added, the pointer would be moved over one position to column 1 in row 0. If a carriage return were added (indicating an end-of-line marker), then the file pointer would move to column 0 row 1. Knowing the location of the file pointer and how it is moved around is important, especially if you will be writing to or reading from files that have fixed record formats with data fields starting and ending in specified column positions.</font><font size="2"> </font></span><span style="font-family:Verdana;"><font size="2">Okay, enough about the file pointer. Let’s look at an example that ties together everything that we have talked about. In this example, I’ve written a VBScript that opens a file named <span class="fixed1"><span style="font-family:Verdana;">myFile.txt</span></span>, which resides in the root directory of my <span class="fixed1"><span style="font-family:Verdana;">C:</span></span> drive. If the file already exists, then the script opens it but if it does not already exist it will be created and opened. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">' * Script Name: Script 8.vbs<span>       </span>*</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">On Error Resume Next</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Dim fsoObject, open_File, target_File</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">target_File = "D:\ displayText.txt"</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' ********* Main processing section **********</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' Call a function that displays drive information</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Open_File()</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_File.WriteLine "This line of data should be written to the text file."</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Close_File()</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' *********** Procedures go here *************</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' This function opens a file</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Function Open_File()</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> If (fsoObject.FileExists(target_File ) ) Then</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span>  </span>Set open_File = fsoObject.OpenTextFile(target_File, 8 )</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> Else</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span>  </span>Set open_File = fsoObject.OpenTextFile(target_File, 2, "True" )</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> End If</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">End Function</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">' This function closes a file</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Function Close_File()</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> open_File.Close()</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">End Function</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">The file is opened using the <span class="fixed1"><span style="font-family:Verdana;">forWriting</span></span> constant ( with a value of 2 ) if it already exists. If the file does not exist, then the <span class="fixed1"><span style="font-family:Verdana;">forAppending</span></span> constant (with a value of 8 ) is specified to open the file and place the file pointer at the end of the file.</font></span><span style="font-family:Verdana;"><font size="2">If you take at look at the script’s main processing section you will see the following statement between a pair of function calls, which open and close the file.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">open_File.WriteLine "This line of data should be written to the text file."</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">This statement writes one line of data to the file and executes a carriage return placing the file pointer in the first column of the following line. I’ll talk more about the use of this and other methods that are used to write data to files in just a bit.</font><font size="2"> </font></span><span style="font-family:Verdana;"><font size="2">The last statement in the main processing section calls a function that executes the following statement.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">open_File.Close()</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">This statement executed the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">close()</span></span> method i to close the opened file. You must remember to close any file that you open before allowing your script to end. Failing to do so may cause an error the next time that you open the file because the end-of-file marker will not have been created.</font></span><span style="font-family:Verdana;"><font size="2">Run this script and open the <span class="fixed1"><span style="font-family:Verdana;">myFile.txt</span></span> file and you’ll see the following line of data. </font></span><br />
<span style="font-family:Verdana;"><font size="2">This line of data should be written to the text file.</font></span></p>
<p><span style="font-size:10pt;font-family:Verdana;"><strong>Writing to Files</strong><br />
</span><br />
<span style="font-family:Verdana;"><font size="2">As you just learned, you should always check for the existence of a file before creating it. Once opened, you have several different ways in which you can write text data to your files.One option is to write a specific number of characters at a time. This technique is best used when you need to write carefully formatted data to your files such as when you write reports with data that appears in columns. Another option for writing to a file is to write an entire line of data at a time. This technique is best used when your documents are more free-formed and is probably the option that you’ll use most often, especially if you plan to create log files in which you record error messages and other types of event information as your scripts execute.Finally, you might want to add blank lines to your files. Blank lines are especially useful for formatting your documents to improve their presentation and make them easier to read.</font></span><span style="font-size:10pt;font-family:Verdana;"><br />
<strong>Adding Characters to a File</strong></span><br />
<span style="font-family:Verdana;"><font size="2">You can write a specific number of characters to a file at a time using the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">Write()</span></span> method. This method does not automatically append a carriage return at the end of each write operation. Therefore, the next time a write operation occurs additional text is inserted immediately following the text written by the previous write operation.</font></span><span style="font-family:Verdana;"><font size="2">The following example demonstrates how you can use the <span class="fixed1"><span style="font-family:Verdana;">Write()</span></span> method to append text to an existing file. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Set open_file = fsoObject.OpenTextFile("d:\ displayText.txt", 8 )</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.Write("Welcome to ")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.Write("KR Testing Solutions!")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.Close()</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">As you can see even though two separate write operations occurred, the text for both write operations was placed on the same line.</font></span><br />
<span style="font-size:10pt;font-family:Verdana;">Adding a Line to a File</span></p>
<h3></h3>
<p><span style="font-family:Verdana;"><font size="2">By replacing the <span class="fixed1"><span style="font-family:Verdana;">Write()</span></span> method with the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">WriteLine()</span></span> method in the previous example, you can change the previous script to write data to the file a line at a time. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Set open_file = fsoObject.OpenTextFile("d:\ displayText.txt", 8 )</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.WriteLine("Welcome to KR Testing Solutions!")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.Close()</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">The <span class="fixed1"><span style="font-family:Verdana;">WriteLine()</span></span> method automatically adds a carriage return to the end of each line returning the file pointer to the first column of the next line.</font></span><br />
<span style="font-size:10pt;font-family:Verdana;">Adding Blank Lines to a File</span></p>
<h3></h3>
<p><span style="font-family:Verdana;"><font size="2">If you want to format your text files with blank lines to create better looking reports or make them easier to read you can use the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">WriteBlankLines()</span></span> method. When executed, this method writes a blank line to the file and executes a carriage return.</font></span><span style="font-family:Verdana;"><font size="2">The following example demonstrates how to use the <span class="fixed1"><span style="font-family:Verdana;">WriteBlankLines()</span></span> method to format the data in a small report. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Set myCDrive = fsoObject.GetDrive("d:")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Set open_file = fsoObject.OpenTextFile("d:\ displayText.txt", 8 )</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.WriteLine("------------------------------")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.WriteBlankLines(1)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.WriteLine("<span>   </span>My d: Drive Report<span>   </span>")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.WriteBlankLines(1)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.WriteLine("------------------------------")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.WriteBlankLines(2)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.WriteLine("File System - " &amp; myCDrive.FileSystem)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.WriteLine("Total Size - " &amp; myCDrive.TotalSize)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.WriteLine("Free Space - " &amp; myCDrive.AvailableSpace)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.Close()</font></span></b><strong><span style="font-size:10pt;font-family:Verdana;">Reading from Files</span></strong></pre>
<p><span style="font-family:Verdana;"><font size="2">Reading the contents of a file is handled in much the same way as writing to it. First, be sure that the file exists. If it does, then your script may open it. The next thing your script should do is use the <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">AtEndOfStream</span></span> property to find out if the file has any data in it. After all, there is no point to trying to read an empty file. In fact, you should check the value of the <span class="fixed1"><span style="font-family:Verdana;">AtEndOfStream</span></span> property just before each read operation to be sure that your script has not reached the end of file marker (e.g., the end of the file).</font><font size="2"> </font></span><span style="font-family:Verdana;"><font size="2">The first thing that you need to do to begin reading a text file is create an instance of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> and then use the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">OpenTextFile()</span></span> method as shown here. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Set open_file = fsoObject.OpenTextFile("d:\ displayText.txt", 1 )</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">As you can see the <span class="fixed1"><span style="font-family:Verdana;">forReading</span></span> constant has been specified. Next you could set up a loop that runs until the <span class="fixed1"><span style="font-family:Verdana;">AtEndOfStream</span></span> property has a value of <span class="fixed1"><span style="font-family:Verdana;">true</span></span> (the end of the file is reached). During each iteration of the loop your script should read a line of text using the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">ReadLine()</span></span> method as shown here. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Do while False = open_file.AtEndOfStream</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo(open_file.ReadLine())</font></span></b> <font size="2">  </font><font size="2">  

<b><span style="font-family:Verdana;">Loop</span></b></font> <font size="2">  

<b><span style="font-family:Verdana;"></span></b><b><span style="font-family:Verdana;"></span></b></font> </pre>
<p><span style="font-family:Verdana;"><font size="2">The preceding VBScript statements will process every line in the file, </font></span><span style="font-family:Verdana;"><font size="2">terminating when the end of file marker is reached. After your script </font></span><span style="font-family:Verdana;"><font size="2">is done reading the file, it can close it as shown here.</font></span><span style="font-family:Verdana;"><font size="2"></font></span><span style="font-family:Verdana;"><font size="2"><br />
<b><span style="font-family:Verdana;"><font size="2">open_file.Close</font></span></b><br />
<span style="font-family:Verdana;"><font size="2">If you put these lines of code together and ran them as a script using the CScript execution host you’d see output similar to the following.</font></span></font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">C:\&gt;CScript test.vbs</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Microsoft (R) Windows Script Host Version 5.6</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">------------------------------</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span>   </span>My d: Drive Report</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">------------------------------</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">File System - NTFS</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Total Size - 2146631554</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Free Space - 234554452</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">C:\&gt;</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">In this example we read an entire file by reading it one line at a time. There are a number of other techniques for reading files. These include</font></span><span style="font-family:Verdana;"><font size="2"> </font></span><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><span style="font-family:Verdana;"><font size="2">Skipping lines when reading a file</font></span><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><span style="font-family:Verdana;"><font size="2">Reading a specified number of characters from a file</font></span><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><span style="font-family:Verdana;"><font size="2">Reading an entire file in one operation</font></span><br />
<span style="font-size:10pt;font-family:Verdana;">Skipping Portions of a File</span></p>
<h3></h3>
<p><span style="font-family:Verdana;"><font size="2">If a file has headers or other information that you are not interested in reading you can always skip them and read only the portion of the file that interests you. For example, the file that we have been working with contains a five-line header followed by two blank lines after which the data in the report begins.</font></span><span style="font-family:Verdana;"><font size="2">You can use either of the following methods, both of which belong to the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span>, to skip text in a file.</font></span><span style="font-family:Verdana;"><font size="2"> </font></span><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Skip()</span></b></span><span style="font-family:Verdana;">. Skip a specific number of characters</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">SkipLine()</span></b></span><span style="font-family:Verdana;">. Skips a line</span></font><span style="font-family:Verdana;"><font size="2">The <span class="fixed1"><span style="font-family:Verdana;">Skip()</span></span> method lets you supply a number indicating how many characters should be skipped. For example, the following statement would skip 25 characters in a file referenced as <span class="fixed1"><span style="font-family:Verdana;">open_file</span></span>. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">open_file.Skip(25)</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">Unfortunately, the <span class="fixed1"><span style="font-family:Verdana;">SkipLine()</span></span> method does not allow you to pass it a number, indicating how many lines to skip. If you want to skip more than one line, you can wrap the method up inside a loop as demonstrated here. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">For i = 1 to 7</font></span></b><b><span style="font-family:Verdana;"><font size="2">open_file.SkipLine()</font></span></b><b><span style="font-family:Verdana;"><font size="2">Next</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">Here the first seven lines of the file referenced as <span class="fixed1"><span style="font-family:Verdana;">open_file</span></span> would be skipped.</font><font size="2"> </font></span><br />
<span style="font-size:10pt;font-family:Verdana;">Reading Formatted Data</span></p>
<h3></h3>
<p><span style="font-family:Verdana;"><font size="2">If your file has been formatted to contain fixed length data, then you have the option of reading it by character instead of by line. To do so you will use the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">Read()</span></span> method.</font></span><span style="font-family:Verdana;"><font size="2">The following example demonstrates how to use this method. Here a reference is set up for a file named <span class="fixed1"><span style="font-family:Verdana;">myfile.txt</span></span>. Then a <span class="fixed1"><span style="font-family:Verdana;">For</span></span> loop is set up to skip the first seven lines of the file using the <span class="fixed1"><span style="font-family:Verdana;">SkipLine()</span></span> method. Next the <span class="fixed1"><span style="font-family:Verdana;">Skip()</span></span> method is used to skip the first fourteen characters on the eighth line. Finally the next four characters, beginning with the twenty-third character are read and then displayed. Then the file is closed. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Set open_file = fsoObject.OpenTextFile("d:\ displayText.txt", 1 )</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">For i = 1 to 7</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> open_file.SkipLine()</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Next</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">open_file.Skip(14)</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">WScript.Echo("The file system in use on this drive is: "</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">&amp; open_file.Read(4))</font></span></b><b><span style="font-family:Verdana;"><font size="2">open_file.Close</font></span></b></pre>
<p><strong><span style="font-size:10pt;font-family:Verdana;">Reading Entire Files</span></strong></p>
<p><span style="font-family:Verdana;"><font size="2">Another way in which you can read files is to read the entire file all at once using the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> object’s <span class="fixed1"><span style="font-family:Verdana;">ReadAll()</span></span> method as demonstrated in the following example.</font><font size="2"> </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Set fsoObject = CreateObject("Scripting.FileSystemObject")</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Set open_file = fsoObject.OpenTextFile("d:\ displayText.txt", 1 )</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">read_rpt = open_file.ReadAll()</font></span></b><b><span style="font-family:Verdana;"><font size="2">open_file.Close()</font></span></b><b><span style="font-family:Verdana;"><font size="2">MsgBox(read_rpt)</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">In this example, the entire file is read using a single statement, which assigns the data read by the <span class="fixed1"><span style="font-family:Verdana;">ReadAll()</span></span> method to a variable named <span class="fixed1"><span style="font-family:Verdana;">read_rpt</span></span>. The file is then closed and the value of <span class="fixed1"><span style="font-family:Verdana;">read_rpt</span></span> displayed using the VBScript <span class="fixed1"><span style="font-family:Verdana;">MsgBox()</span></span> function.</font></span></p>
<p><strong><span style="font-size:10pt;font-family:Verdana;">Performing File and Folder Administration</span></strong><br />
z<br />
<span style="font-family:Verdana;"><font size="2">Managing your files and folders can involve a lot of work. Using VBScript and the WSH you can automate much of this work. For example, typical file and folder tasks involve copying or moving files and folders from one location to another in order to create backups or better organize them. Administration may also include deleting files once they have been processed or after they have reached a certain age.</font></span><span style="font-family:Verdana;"><font size="2">You can use methods belonging to the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> to manage one or more files or folders at a time. <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> methods for handling files include</font></span><span style="font-family:Verdana;"><font size="2"> </font></span><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';"> </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">CopyFile()</span></b></span><b><span style="font-family:Verdana;">.</span></b><span style="font-family:Verdana;"> Copies one or more files.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">MoveFile()</span></b></span><b><span style="font-family:Verdana;">.</span></b><span style="font-family:Verdana;"> Moves one or more files to a different location.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">DeleteFile().</span></b></span><span style="font-family:Verdana;"> Delete one or more files.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">FileExists()</span></b></span><span style="font-family:Verdana;">. Provides verification of whether a file contains data.</span></font><span style="font-family:Verdana;"><font size="2">The <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span> also provides a number of methods that you can use to manage Windows folders, including</font></span><span style="font-family:Verdana;"><font size="2"> </font></span><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">CopyFolder()</span></b></span><span style="font-family:Verdana;">. Copies one or more folders.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">MoveFolder()</span></b></span><span style="font-family:Verdana;">. Moves one or more folders to a different location.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">DeleteFolder()</span></b></span><span style="font-family:Verdana;">. Deletes one or more folders.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">FolderExists()</span></b></span><span style="font-family:Verdana;">. Provides verification of whether a folder exists.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">CreateFolder()</span></b></span><span style="font-family:Verdana;">. Creates a new folder.</span></font><span style="font-family:Verdana;"><font size="2">Alternatively, you can also use the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> and <span class="fixed1"><span style="font-family:Verdana;">Folder</span></span> objects to manage your files and folders instead of the <span class="fixed1"><span style="font-family:Verdana;">FileSystemObject</span></span>. These two objects share many of the same methods, including</font></span><span class="fixed1"><span style="font-family:Verdana;"><font size="2"> </font></span></span><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Copy()</span></b></span><span style="font-family:Verdana;">. Copies a file or folder to the specified location.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Delete()</span></b></span><span style="font-family:Verdana;">. Removes the specified file or folder.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Move()</span></b></span><span style="font-family:Verdana;">. Moves a file or folder to the specified location. </span></font></p>
<p align="right"><a href="http://kuldeepse.wordpress.com/2008/02/05/10-filesystemobject/"><font color="#000044">Next Step &#8211; File System Object</font></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kuldeepse.wordpress.com/124/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kuldeepse.wordpress.com/124/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kuldeepse.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kuldeepse.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kuldeepse.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kuldeepse.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kuldeepse.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kuldeepse.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kuldeepse.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kuldeepse.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kuldeepse.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kuldeepse.wordpress.com/124/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=124&subd=kuldeepse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kuldeepse.wordpress.com/2008/02/05/9-scripting-related-to-file-system/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b37d5959686c283f564079068ff8246f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kuldeep</media:title>
		</media:content>
	</item>
		<item>
		<title>8: Files and Folders related Functions</title>
		<link>http://kuldeepse.wordpress.com/2008/02/05/8-files-and-folders-related-functions/</link>
		<comments>http://kuldeepse.wordpress.com/2008/02/05/8-files-and-folders-related-functions/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 08:49:49 +0000</pubDate>
		<dc:creator>kuldeep kumar</dc:creator>
				<category><![CDATA[Learn VBScript for QTP (Descriptive Programming)]]></category>

		<guid isPermaLink="false">http://kuldeepse.wordpress.com/?p=123</guid>
		<description><![CDATA[Files and Folders related Functions
VBScript Runtime Properties
Like the objects in the WSH core object model, VBScript runtime objects provide an extensive supply of properties. You can use the properties to view or change numerous file system attributes. These properties are listed here. 
·         AtEndOfLine. Returns a value of either true or false depending on whether the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=123&subd=kuldeepse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong><span style="font-size:10pt;font-family:Verdana;">Files and Folders related Functions</span></strong></p>
<p><strong><span style="font-size:10pt;font-family:Verdana;">VBScript Runtime Properties</span></strong></p>
<p><span style="font-family:Verdana;"><font size="2">Like the objects in the WSH core object model, VBScript runtime objects provide an extensive supply of properties. You can use the properties to view or change numerous file system attributes. These properties are listed here.</font></span><span style="font-family:Verdana;"><font size="2"> </font></span><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">AtEndOfLine</span></b></span><span style="font-family:Verdana;">. Returns a value of either <span class="fixed1"><span style="font-family:Verdana;">true</span></span> or <span class="fixed1"><span style="font-family:Verdana;">false</span></span> depending on whether the file pointer precedes the <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> file’s end-of-line marker.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">AtEndOfStream</span></b></span><span style="font-family:Verdana;">. Returns a value of either <span class="fixed1"><span style="font-family:Verdana;">true</span></span> or <span class="fixed1"><span style="font-family:Verdana;">false</span></span> depending on whether the end of a <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> file has been reached.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Attributes</span></b></span><span style="font-family:Verdana;">. Retrieves or sets file and folder attributes.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">AvailableSpace</span></b></span><span style="font-family:Verdana;">. Retrieves the amount of free space available on a drive.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Column</span></b></span><span style="font-family:Verdana;">. Retrieves the current column position within a <span class="fixed1"><br />
<span style="font-family:Verdana;">TextStream</span></span> file.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">CompareMode</span></b></span><span style="font-family:Verdana;">. Retrieves or sets the comparison mode used to compare a <span class="fixed1"><span style="font-family:Verdana;">Dictionary</span></span> object’s string keys.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Count</span></b></span><span style="font-family:Verdana;">. Returns a count of the items in a collection or Dictionary object.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">DateCreated</span></b></span><span style="font-family:Verdana;">. Returns a file or folder’s creation date and time.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">DateLastAccessed</span></b></span><span style="font-family:Verdana;">. Returns the date and time that a file or folder was last accessed.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">DateLastModified</span></b></span><span style="font-family:Verdana;">. Returns the date and time that a file or folder was last modified.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Drive</span></b></span><span style="font-family:Verdana;">. Returns the drive letter representing the drive where a file or folder is stored.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">DriveLetter</span></b></span><span style="font-family:Verdana;">. Returns a drive’s drive letter.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Drives</span></b></span><span style="font-family:Verdana;">. Creates a <span class="fixed1"><span style="font-family:Verdana;">Drives</span></span> collection representing the computer’s <span class="fixed1"><span style="font-family:Verdana;">Drive</span></span> objects.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">DriveType</span></b></span><span style="font-family:Verdana;">. Returns a value indicating a drive’s type.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Files</span></b></span><span style="font-family:Verdana;">. Creates a <span class="fixed1"><span style="font-family:Verdana;">Files</span></span> collection representing the <span class="fixed1"><span style="font-family:Verdana;">File</span></span> objects stored inside a folder.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">FileSystem</span></b></span><span style="font-family:Verdana;">. Returns the file system type implemented on a drive.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">FreeSpace</span></b></span><span style="font-family:Verdana;">. Returns the amount of free space available to the user on a drive. </span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">IsReady</span></b></span><span style="font-family:Verdana;">. Returns a value of either <span class="fixed1"><span style="font-family:Verdana;">true</span></span> or <span class="fixed1"><span style="font-family:Verdana;">false</span></span> depending on whether a drive is available.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">IsRootFolder</span></b></span><span style="font-family:Verdana;">. Returns a value of either <span class="fixed1"><span style="font-family:Verdana;">true</span></span> or <span class="fixed1"><span style="font-family:Verdana;">false</span></span> identifying whether a folder is the root folder.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Item</span></b></span><span style="font-family:Verdana;">. Retrieves or sets an item based on the specified <span class="fixed1"><span style="font-family:Verdana;">Dictionary</span></span> object key.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Key</span></b></span><span style="font-family:Verdana;">. Sets a <span class="fixed1"><span style="font-family:Verdana;">Dictionary</span></span> object key.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Line</span></b></span><span style="font-family:Verdana;">. Returns the current line number in the <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> file.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Name</span></b></span><span style="font-family:Verdana;">. Retrieves or sets a file or folder’s name.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">ParentFolder</span></b></span><span style="font-family:Verdana;">. Retrieves a file or folder’s parent folder object.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Path</span></b></span><span style="font-family:Verdana;">. Retrieves the path associated with a file, folder, or drive.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">RootFolder</span></b></span><span style="font-family:Verdana;">. Retrieves the <span class="fixed1"><span style="font-family:Verdana;">Folder</span></span> object associated with the root folder on the specified drive.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">SerialNumber</span></b></span><span style="font-family:Verdana;">. Retrieves a disk volume’s serial number.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">ShareName</span></b></span><span style="font-family:Verdana;">. Retrieves a network drive’s share name.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">ShortName</span></b></span><span style="font-family:Verdana;">. Retrieves a file’s or folder’s 8.3 character short name.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">ShortPath</span></b></span><span style="font-family:Verdana;">. Retrieves the short path associated with a file’s or folder’s 8.3 character name.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Size</span></b></span><span style="font-family:Verdana;">. Retrieves a file’s or folder’s byte size.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">SubFolders</span></b></span><span style="font-family:Verdana;">. Establishes a <span class="fixed1"><span style="font-family:Verdana;">Folders</span></span> collection consisting of all the folders located inside a specified folder.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">TotalSize</span></b></span><span style="font-family:Verdana;">. Returns the total number of bytes left on a drive.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Type</span></b></span><span style="font-family:Verdana;">. Retrieves information about a file’s or folder’s type.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">VolumeName</span></b></span><span style="font-family:Verdana;">. Retrieves or sets a drive’s volume name.</span></font></p>
<h3><span style="font-size:10pt;font-family:Verdana;">VBScript Runtime Methods</span></h3>
<p><span style="font-family:Verdana;"><font size="2">The methods that belong to the VBScript runtime objects are listed here.</font></span></p>
<p><span style="font-family:Verdana;"></span><font size="2"><b><span style="font-family:Verdana;">VBScript Run-time Methods</span></b><span style="font-family:Verdana;"> </span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Add (Dictionary)</span></b></span><span style="font-family:Verdana;">. Adds a key and item pair to a <span class="fixed1"><span style="font-family:Verdana;">Dictionary</span></span> object.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Add (Folders)</span></b></span><span style="font-family:Verdana;">. Adds a <span class="fixed1"><span style="font-family:Verdana;">Folder</span></span> to a collection.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">BuildPath</span></b></span><span style="font-family:Verdana;">. Appends a name to the path.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Close</span></b></span><span style="font-family:Verdana;">. Closes an open <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> file.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Copy</span></b></span><span style="font-family:Verdana;">. Copies a file or folder.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">CopyFile</span></b></span><span style="font-family:Verdana;">. Copies one or more files.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">CopyFolder</span></b></span><span style="font-family:Verdana;">. Recursively copies a folder.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">CreateFolder</span></b></span><span style="font-family:Verdana;">. Creates a new folder.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">CreateTextFile</span></b></span><span style="font-family:Verdana;">. Creates a file and a <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> object that can be used to read and write to the file.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Delete</span></b></span><span style="font-family:Verdana;">. Deletes a file or folder.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">DeleteFile</span></b></span><span style="font-family:Verdana;">. Deletes a file.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">DeleteFolder</span></b></span><span style="font-family:Verdana;">. Deletes a folder’s contents.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">DriveExists</span></b></span><span style="font-family:Verdana;">. Returns either <span class="fixed1"><span style="font-family:Verdana;">true</span></span> or <span class="fixed1"><span style="font-family:Verdana;">false</span></span> depending on the existence of a drive.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Exists</span></b></span><span style="font-family:Verdana;">. Returns either <span class="fixed1"><span style="font-family:Verdana;">true</span></span> or <span class="fixed1"><span style="font-family:Verdana;">false</span></span> depending on whether a key exists in a <span class="fixed1"><span style="font-family:Verdana;">Dictionary</span></span> object. </span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">FileExists</span></b></span><span style="font-family:Verdana;">. Returns either <span class="fixed1"><span style="font-family:Verdana;">true</span></span> or <span class="fixed1"><span style="font-family:Verdana;">false</span></span> depending on whether a file can be found.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">FolderExists</span></b></span><span style="font-family:Verdana;">. Returns a value of <span class="fixed1"><span style="font-family:Verdana;">true</span></span> or <span class="fixed1"><span style="font-family:Verdana;">false</span></span> depending on whether a folder can be found.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">GetAbsolutePathName</span></b></span><span style="font-family:Verdana;">. Returns a complete path name.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">GetBaseName</span></b></span><span style="font-family:Verdana;">. Retrieves a filename less its file extension.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">GetDrive</span></b></span><span style="font-family:Verdana;">. Returns the <span class="fixed1"><span style="font-family:Verdana;">Drive</span></span> object associated with the drive in the specified path.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">GetDriveName</span></b></span><span style="font-family:Verdana;">. Retrieves the name of a drive.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">GetExtensionName</span></b></span><span style="font-family:Verdana;">. Retrieves a file’s extension.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">GetFile</span></b></span><span style="font-family:Verdana;">. Retrieves a <span class="fixed1"><span style="font-family:Verdana;">File</span></span> object.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">GetFileName</span></b></span><span style="font-family:Verdana;">. Retrieves the last filename or folder of the specified path.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">GetFileVersion</span></b></span><span style="font-family:Verdana;">. Retrieves a file’s version number.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">GetFolder</span></b></span><span style="font-family:Verdana;">. Retrieves the <span class="fixed1"><span style="font-family:Verdana;">Folder</span></span> object associated with the folder in the specified path.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">GetParentFolderName</span></b></span><span style="font-family:Verdana;">. Retrieves the name of the parent folder.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">GetSpecialFolder</span></b></span><span style="font-family:Verdana;">. Retrieves a special folder’s name.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">GetTempName</span></b></span><span style="font-family:Verdana;">. Retrieves the name of a temporary file or folder.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Items</span></b></span><span style="font-family:Verdana;">. Returns an array containing the items in a Dictionary object.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Keys</span></b></span><span style="font-family:Verdana;">. Returns an array containing the keys in a Dictionary object.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Move</span></b></span><span style="font-family:Verdana;">. Moves a file or folder.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">MoveFile</span></b></span><span style="font-family:Verdana;">. Moves one or more files.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">MoveFolder</span></b></span><span style="font-family:Verdana;">. Moves one or more folders.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">OpenAsTextStream</span></b></span><span style="font-family:Verdana;">. Opens a file and returns a <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> object that can be used to reference the file.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">OpenTextFile</span></b></span><span style="font-family:Verdana;">. Opens a file and returns a <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> object that can be used to reference the file. </span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Read</span></b></span><span style="font-family:Verdana;">. Returns a string containing <span class="fixed1"><span style="font-family:Verdana;">x</span></span> number of characters from a <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> file.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">ReadAll</span></b></span><span style="font-family:Verdana;">. Reads the whole <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> file and returns its contents.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">ReadLine</span></b></span><span style="font-family:Verdana;">. Reads a line in a <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> file.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Remove</span></b></span><span style="font-family:Verdana;">. Deletes a <span class="fixed1"><span style="font-family:Verdana;">Dictionary</span></span> object’s key, item pair.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Skip</span></b></span><span style="font-family:Verdana;">. Skips <span class="fixed1"><span style="font-family:Verdana;">x</span></span> number of character positions when processing a <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> file.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">SkipLine</span></b></span><span style="font-family:Verdana;">. Skips a line when processing a <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> file.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Write</span></b></span><span style="font-family:Verdana;">. Places a string in the <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> file.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">WriteBlankLines</span></b></span><span style="font-family:Verdana;">. Writes <span class="fixed1"><span style="font-family:Verdana;">x</span></span> number of <span class="fixed1"><span style="font-family:Verdana;">newline</span></span> characters to the <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> file.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">WriteLine</span></b></span><span style="font-family:Verdana;">. Writes a string in the <span class="fixed1"><span style="font-family:Verdana;">TextStream</span></span> file</span></font></p>
<p align="right"><a href="http://kuldeepse.wordpress.com/2008/02/05/9-scripting-related-to-file-system/"><font color="#000044">Next Step &#8211; File Scripting</font></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kuldeepse.wordpress.com/123/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kuldeepse.wordpress.com/123/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kuldeepse.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kuldeepse.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kuldeepse.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kuldeepse.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kuldeepse.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kuldeepse.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kuldeepse.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kuldeepse.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kuldeepse.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kuldeepse.wordpress.com/123/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=123&subd=kuldeepse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kuldeepse.wordpress.com/2008/02/05/8-files-and-folders-related-functions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b37d5959686c283f564079068ff8246f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kuldeep</media:title>
		</media:content>
	</item>
		<item>
		<title>7:Pop-Up Dialogs</title>
		<link>http://kuldeepse.wordpress.com/2008/02/05/7pop-up-dialogs/</link>
		<comments>http://kuldeepse.wordpress.com/2008/02/05/7pop-up-dialogs/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 08:29:40 +0000</pubDate>
		<dc:creator>kuldeep kumar</dc:creator>
				<category><![CDATA[Learn VBScript for QTP (Descriptive Programming)]]></category>

		<guid isPermaLink="false">http://kuldeepse.wordpress.com/?p=122</guid>
		<description><![CDATA[VBScript Pop-Up Dialogs
VBScript provides two built-in functions that allow you to add pop-up dialogs that you can use in your VBScripts to communicate with users. You can call on these functions to execute within your scripts just like you would any function that you wrote yourself.These two functions are available regardless of whether you are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=122&subd=kuldeepse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong><span style="font-size:10pt;font-family:Verdana;">VBScript Pop-Up Dialogs</span><br />
</strong><span style="font-family:Verdana;"><font size="2">VBScript provides two built-in functions that allow you to add pop-up dialogs that you can use in your VBScripts to communicate with users. You can call on these functions to execute within your scripts just like you would any function that you wrote yourself.</font></span><span style="font-family:Verdana;"><font size="2">These two functions are available regardless of whether you are embedding your VBScripts into <span class="fixed1"><span style="font-family:Verdana;">HTML</span></span> pages or writing WSH scripts. Both of these functions are described here.</font></span><span style="font-family:Verdana;"><font size="2"> </font></span><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">MsgBox()</span></b></span><span style="font-family:Verdana;">. A procedure that executes and then returns a result to the statement that called it.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">InputBox()</span></b></span><span style="font-family:Verdana;">. A procedure that executes but that does not return a result.</span></font></p>
<h4><span style="font-size:10pt;font-family:Verdana;">The VBScript MsgBox Function</span></h4>
<p><span style="font-family:Verdana;"><font size="2">The <span class="fixed1"><span style="font-family:Verdana;">MsgBox</span></span> function provides a way for you to display a pop-up dialog and ask the user to respond by clicking the appropriate button. The syntax of the <span class="fixed1"><span style="font-family:Verdana;">MsgBox</span></span> function is shown here. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">MsgBox(<i>prompt</i> [, <i>buttons</i>] [, <i>title</i>] [, <i>helpfile</i>, <i>context</i>])</font></span></b></pre>
<p><font size="2"><span class="fixed1"><span style="font-family:Verdana;">Prompt</span></span><span style="font-family:Verdana;"> is the text message displayed by the dialog and can be as many as 1,024 characters long. <span class="fixed1"><span style="font-family:Verdana;">Button</span></span> is a numeric expression or value that is the sum of a number of other values that specify.</span></font><span style="font-family:Wingdings;"><br />
<span><font size="2">§</font><span style="font:7pt 'Times New Roman';">                    </span></span></span><span style="font-family:Verdana;"><font size="2">The types of buttons to display</font></span><span style="font-family:Wingdings;"><br />
<span><font size="2">§</font><span style="font:7pt 'Times New Roman';">                    </span></span></span><span style="font-family:Verdana;"><font size="2">The type of icon to be displayed in the dialog</font></span><span style="font-family:Wingdings;"><br />
<span><font size="2">§</font><span style="font:7pt 'Times New Roman';">                    </span></span></span><span style="font-family:Verdana;"><font size="2">The button to be selected by default</font></span><span style="font-family:Wingdings;"><br />
<span><font size="2">§</font><span style="font:7pt 'Times New Roman';">                    </span></span></span><span style="font-family:Verdana;"><font size="2">The modality of the dialog</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b> 

<b><span style="font-family:Verdana;"><font size="2">Dim myResponse</font></span></b> 

<b><span style="font-family:Verdana;"><font size="2">myResponse = MsgBox("Do you wish to quit?", 1, "What do you wish to do?")</font></span></b></pre>
<h4><span style="font-size:10pt;font-family:Verdana;">The VBScript InputBox Function</span></h4>
<p><span style="font-family:Verdana;"><font size="2">The <span class="fixed1"><span style="font-family:Verdana;">InputBox()</span></span> function provides a way for you to display a pop-up dialog that prompts the user to supply text input. The <span class="fixed1"><span style="font-family:Verdana;">InputBox</span></span> allows you to ask the user questions and collect text input. The syntax of the <span class="fixed1"><span style="font-family:Verdana;">InputBox()</span></span> function is shown here. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">InputBox(<i>prompt</i> [, <i>title</i>] [, <i>default</i>] [, <i>xpos</i>] [, <i>ypos</i>] [, <i>helpfile</i>, <i>context</i>])</font><a name="164" title="164"></a><a name="beginpage.0ED57D5D-E341-4833-BA2F-5ABD74" title="beginpage.0ED57D5D-E341-4833-BA2F-5ABD74"></a></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">For example, the following statements prompt the user to type the name of the country in which he or she resides.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b><b><span style="font-family:Verdana;"><font size="2">Dim myInput</font></span></b> 

<b><span style="font-family:Verdana;"><font size="2">myInput = InputBox("What country do you reside in?")</font></span></b></pre>
<p align="right"><a href="http://kuldeepse.wordpress.com/2008/02/05/8-files-and-folders-related-functions/"><font color="#000044">Next Step &#8211; File and Folder Functions</font></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kuldeepse.wordpress.com/122/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kuldeepse.wordpress.com/122/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kuldeepse.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kuldeepse.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kuldeepse.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kuldeepse.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kuldeepse.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kuldeepse.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kuldeepse.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kuldeepse.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kuldeepse.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kuldeepse.wordpress.com/122/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=122&subd=kuldeepse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kuldeepse.wordpress.com/2008/02/05/7pop-up-dialogs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b37d5959686c283f564079068ff8246f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kuldeep</media:title>
		</media:content>
	</item>
		<item>
		<title>6: Arrays</title>
		<link>http://kuldeepse.wordpress.com/2008/02/05/6-arrays/</link>
		<comments>http://kuldeepse.wordpress.com/2008/02/05/6-arrays/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 08:26:27 +0000</pubDate>
		<dc:creator>kuldeep kumar</dc:creator>
				<category><![CDATA[Learn VBScript for QTP (Descriptive Programming)]]></category>

		<guid isPermaLink="false">http://kuldeepse.wordpress.com/2008/02/05/6-arrays/</guid>
		<description><![CDATA[Arrays
VBScript allows you to store data in variables that you can then reference and manipulate. While there is no limit to the number of variables that you can create in a single VBScript, you’ll find that trying to manage too many of them can become difficult.VBScript provides another storage structure for managing large groups of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=121&subd=kuldeepse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><b><u><span style="font-family:Verdana;"><font size="2">Arrays</font></span></u></b><br />
<span style="font-family:Verdana;"><font size="2">VBScript allows you to store data in variables that you can then reference and manipulate. While there is no limit to the number of variables that you can create in a single VBScript, you’ll find that trying to manage too many of them can become difficult.</font></span><span style="font-family:Verdana;"><font size="2">VBScript provides another storage structure for managing large groups of related data known as an array. An <i>array</i> is an indexed collection of values that are managed as a unit. For example, rather than creating a whole series of individual variables to store a list of values such as people’s names, you can create an array and assign each name as an array element.</font></span><span style="font-family:Verdana;"><font size="2">VBScript supports the creation of single dimensional and multidimensional arrays. In fact, VBScript allows for the creation of arrays with as many as 60 dimensions, although you’ll probably never need to work with anything bigger than one or two dimensions.</font></span><span style="font-family:Verdana;"><font size="2">VBScript allows you to create an array using the <span class="fixed1"><span style="font-family:Verdana;">Dim</span></span> statement. The syntax of the <span class="fixed1"><span style="font-family:Verdana;">Dim</span></span> statement when used to establish an array is </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2"> </font></span></b> <b><span style="font-family:Verdana;"><font size="2">Dim <i>arrayname</i>(<i>dimensions</i>)</font></span></b></pre>
<p><font size="2"><span class="fixed1"><span style="font-family:Verdana;">Dimensions</span></span><span style="font-family:Verdana;"> is a comma-separated list specifying the length of each of an array’s dimensions. For example, the following statement defines a single dimension array called <span class="fixed1"><span style="font-family:Verdana;">myArray</span></span> that can hold up to four elements. </span></font></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Dim myArray(2)</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">An array is an indexed list. The first value stored in the array is automatically assigned an index value 0. The second element stored in an array has an index value of 1, and so on. Because an array’s index always begins with zero the actual length of an array dimension is equal to the number supplied in the declaration statement plus one. So the array defined above can hold up to 4 elements.</font></span><span style="font-family:Verdana;"><font size="2">Once you have defined and array you can populate it as demonstrated here.</font><font size="2"> </font></span></p>
<pre>
<b><span style="font-family:Verdana;"><font size="2">myArray(0) = "Welcome"</font></span></b><b><span style="font-family:Verdana;"><font size="2">myArray(1) = "To"</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">myArray(2) = "KR Testing Solution"</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">After you have populated an array you can reference its contents. For example, you could use the following statement to display the value stored as the third element in the array.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">WScript.Echo myArray(2)</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">The following examples show how to create an array with more than one dimension. In this case, a two-dimensional array is created using the <span class="fixed1"><span style="font-family:Verdana;">Dim</span></span> statement that can store its data in a spreadsheet like format. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Dim myArray (4,4)</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">You can think of the array created by this example as having five rows by five columns. Remember, the length of any array dimension equals 1 plus the value that specified its length. Similarly, your could define a three-dimensional array by adding additional comma separated values in the <span class="fixed1"><span style="font-family:Verdana;">Dim</span></span> statement as shown here. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Dim myArray (4,4,4)</font></span></b></pre>
<p align="right"><a href="http://kuldeepse.wordpress.com/2008/02/05/7pop-up-dialogs/"><font color="#000044">Next Step &#8211; Message Dialogs</font></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kuldeepse.wordpress.com/121/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kuldeepse.wordpress.com/121/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kuldeepse.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kuldeepse.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kuldeepse.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kuldeepse.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kuldeepse.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kuldeepse.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kuldeepse.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kuldeepse.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kuldeepse.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kuldeepse.wordpress.com/121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=121&subd=kuldeepse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kuldeepse.wordpress.com/2008/02/05/6-arrays/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b37d5959686c283f564079068ff8246f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kuldeep</media:title>
		</media:content>
	</item>
		<item>
		<title>5: Functions</title>
		<link>http://kuldeepse.wordpress.com/2008/02/05/5-functions/</link>
		<comments>http://kuldeepse.wordpress.com/2008/02/05/5-functions/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 08:24:28 +0000</pubDate>
		<dc:creator>kuldeep kumar</dc:creator>
				<category><![CDATA[Learn VBScript for QTP (Descriptive Programming)]]></category>

		<guid isPermaLink="false">http://kuldeepse.wordpress.com/?p=120</guid>
		<description><![CDATA[Functions 
VBScript provides two different types of procedures.
§                    Function. A procedure that executes and then returns a result to the statement that called it.
§                    Subroutine. A procedure that executes but does not return a result.
Functions
VBScript functions are collections of related VBScript statements that are called and executed as a unit. Functions can also return a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=120&subd=kuldeepse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong><span style="font-size:10pt;font-family:Verdana;">Functions </span><br />
</strong><span style="font-family:Verdana;"><font size="2">VBScript provides two different types of procedures.</font></span><br />
<span style="font-family:Wingdings;"><span><font size="2">§</font><span style="font:7pt 'Times New Roman';">                    </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Function</span></b></span><span style="font-family:Verdana;">. A procedure that executes and then returns a result to the statement that called it.</span></font><br />
<span style="font-family:Wingdings;"><span><font size="2">§</font><span style="font:7pt 'Times New Roman';">                    </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Subroutine</span></b></span><span style="font-family:Verdana;">. A procedure that executes but does not return a result.</span></font></p>
<h4><span style="font-size:10pt;font-family:Verdana;">Functions</span></h4>
<p><span style="font-family:Verdana;"><font size="2">VBScript functions are collections of related VBScript statements that are called and executed as a unit. Functions can also return a result to calling statements. The syntax for creating a function is</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">[Public | Private] Function <i>name</i> [(<i>arglist</i>)]</font></span></b> <b><span style="font-family:Verdana;"><font size="2"> <i>statements</i></font></span></b> <b><span style="font-family:Verdana;"><font size="2">End Function</font></span></b></pre>
<p><font size="2"><span class="fixed1"><span style="font-family:Verdana;">Private</span></span><span style="font-family:Verdana;"> and <span class="fixed1"><span style="font-family:Verdana;">Public</span></span> are optional keywords. The <span class="fixed1"><span style="font-family:Verdana;">Private</span></span> keyword is used to set up a function that can only be called from within the script where it has been defined. When used, the <span class="fixed1"><span style="font-family:Verdana;">Public</span></span> keyword allows the function to be called by other scripts. <span class="fixed1"><span style="font-family:Verdana;">Name</span></span> identifies the function’s name. <span class="fixed1"><span style="font-family:Verdana;">Arglist</span></span> is used to specify one or more arguments that that can be passed to the function.</span></font><span style="font-family:Verdana;"><font size="2">To return a result to the statement that called the functions you must be sure that the subroutine has a variable of the same name as the subroutine. </font><a name="137" title="137"></a><a name="beginpage.DC1C7E1F-7D1B-44EA-A11A-AAE514" title="beginpage.DC1C7E1F-7D1B-44EA-A11A-AAE514"></a></span><span style="font-family:Verdana;"><font size="2">The value that the subroutine assigned to this variable is what will be returned.</font></span><span style="font-family:Verdana;"><font size="2">The following example shows a WSH VBScript that has two functions.</font></span></p>
<pre>
<b><span style="font-family:Verdana;"><font size="2">' * Script Name:<span>   </span>Script 3.vbs</font></span></b><b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b></pre>
<p><b><span style="font-family:Verdana;"><font size="2">Const Message = &#8220;Welcome to KR Testing Solutions&#8221;</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">Dim string1</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">Dim string2</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">&#8216; *********** Main processing section ****************</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">&#8216; Collect the First String</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">string1 = GetFirstString()</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">&#8216; Collect the Second String</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">string2 = GetSecondString()</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">&#8216; Display message</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">WScript.Echo Message &amp; &#8221; &#8221; &amp; string1 &amp; &#8221; &#8221; &amp; string2</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">&#8216; ********* Subroutines &amp; Functions go here **********</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">function GetFirstString()</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">GetFirstString = InputBox(&#8220;What is your 1<sup>st</sup> String?&#8221;)</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">End Function</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2"></font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">function GetSecondString()</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">GetSecondString = InputBox(&#8220;What is your 2<sup>nd</sup> String?&#8221;)</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">End Function</font></span></b></p>
<h4><span style="font-size:10pt;font-family:Verdana;">Subroutines</span></h4>
<p><span style="font-family:Verdana;"><font size="2">Subroutines work almost exactly like functions except that they are unable to return any results to the calling statement. The syntax for creating a subroutine is shown here.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">[Public | Private] Sub <i>name</i> [(<i>arglist</i>)]</font></span></b> <b><span style="font-family:Verdana;"><font size="2"> <i>statements</i></font></span></b> <b><span style="font-family:Verdana;"><font size="2">End Sub</font></span></b></pre>
<p align="right"><a href="http://kuldeepse.wordpress.com/2008/02/05/6-Arrays/"><font color="#000044">Next Step &#8211; Array Decleration</font></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kuldeepse.wordpress.com/120/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kuldeepse.wordpress.com/120/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kuldeepse.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kuldeepse.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kuldeepse.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kuldeepse.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kuldeepse.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kuldeepse.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kuldeepse.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kuldeepse.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kuldeepse.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kuldeepse.wordpress.com/120/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=120&subd=kuldeepse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kuldeepse.wordpress.com/2008/02/05/5-functions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b37d5959686c283f564079068ff8246f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kuldeep</media:title>
		</media:content>
	</item>
		<item>
		<title>4: Looping Statement</title>
		<link>http://kuldeepse.wordpress.com/2008/02/05/4-looping-statement/</link>
		<comments>http://kuldeepse.wordpress.com/2008/02/05/4-looping-statement/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 06:19:44 +0000</pubDate>
		<dc:creator>kuldeep kumar</dc:creator>
				<category><![CDATA[Learn VBScript for QTP (Descriptive Programming)]]></category>

		<guid isPermaLink="false">http://kuldeepse.wordpress.com/?p=119</guid>
		<description><![CDATA[Loops
Like any advanced programming language VBScript provides a number of statements that allow VBScripts to loop or iterate repeatedly to quickly and efficiently process large amounts of data. These statements make it possible to write small scripts that are capable of processing enormous amounts of data.VBScript provides five different types of loops, summarized here, each [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=119&subd=kuldeepse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><span style="font-size:10pt;font-family:Verdana;"><strong>Loops</strong></span></p>
<p><span style="font-family:Verdana;"><font size="2">Like any advanced programming language VBScript provides a number of statements that allow VBScripts to loop or iterate repeatedly to quickly and efficiently process large amounts of data. These statements make it possible to write small scripts that are capable of processing enormous amounts of data.</font></span><span style="font-family:Verdana;"><font size="2">VBScript provides five different types of loops, summarized here, each of which has its own unique purpose and advantages.</font></span><span style="font-family:Verdana;"><font size="2"> </font></span><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><b><span style="font-family:Verdana;">Do While</span></b><span style="font-family:Verdana;">. Sets up a loop that iterates as long as a specified condition remains true.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><b><span style="font-family:Verdana;">Do Until</span></b><span style="font-family:Verdana;">. Sets up a loop that iterates until a specified condition becomes true.</span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">        </span></span></span><font size="2"><b><span style="font-family:Verdana;">For…Next</span></b><span style="font-family:Verdana;">. Sets up a loop to execute a specified number of time</span></font><font size="2"><span style="font-family:Verdana;"></span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><b><span style="font-family:Verdana;">While…Wend</span></b><span style="font-family:Verdana;">. Sets up a loop that executes as long as a condition remains true.</span></font><font size="2"><span style="font-family:Verdana;"></span></font><br />
<span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><b><span style="font-family:Verdana;">For…Each…Next.</span></b><span style="font-family:Verdana;"> Creates a loop that iterates through an object’s properties.</span></font></p>
<h4><span style="font-size:10pt;font-family:Verdana;">Do While</span></h4>
<p><span style="font-family:Verdana;"><font size="2">The VBScript <span class="fixed1"><span style="font-family:Verdana;">Do While</span></span> statement is used to create loops that run while a condition remains true. There are two ways that you can set up <span class="fixed1"><span style="font-family:Verdana;">Do While</span></span> loops in your VBScripts. The syntax for the first method is </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Do While <i>condition</i></font></span></b> <b><span style="font-family:Verdana;"><font size="2"> <i>statements</i></font></span></b> <b><span style="font-family:Verdana;"><font size="2">Loop</font></span></b><b><span style="font-family:Verdana;"></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">You can insert as many programming statements as you want to between the opening <span class="fixed1"><span style="font-family:Verdana;">Do</span></span> and closing <span class="fixed1"><span style="font-family:Verdana;">Loop</span></span> keywords. The <span class="fixed1"><span style="font-family:Verdana;">While</span></span> keyword is included at the beginning of the loop. Therefore if the condition being tested is already false, the loop will never execute. For example, the following VBScript statement shows a VBScript <span class="fixed1"><span style="font-family:Verdana;">Do While</span></span> loop that counts to 10. In this example, a variable called <span class="fixed1"><span style="font-family:Verdana;">myCount</span></span> is initialized with a value of 0 and then incremented by 1 each time the loop is executed. When the value of the variable finally exceeds 10 the loop terminates and processing continues with the next statement in the script. Therefore <span class="fixed1"><span style="font-family:Verdana;">myCount</span></span> is used to control the execution and termination of the loop. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">' * Script Name:<span>  </span>Script 2.vbs</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Dim Counter 'Counter used to control loop termination</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Counter = 0</font></span></b> <b><span style="font-family:Verdana;"><font size="2"> </font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Dim crlf ' Contains carriage return and linefeed instructions</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">crlf = Chr(13) &amp; Chr(10)</font></span></b><b><span style="font-family:Verdana;"><font size="2"> </font></span></b>
<b><span style="font-family:Verdana;"><font size="2">' *********** Main processing section ****************</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">WScript.Echo "Counting to 5 with a Do While loop" &amp; crlf</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Do While Counter &lt; 5</font></span></b>
<b><span style="font-family:Verdana;"><font size="2"> Counter = Counter + 1</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">WScript.Echo(Counter) &amp; crlf</font></span></b> <font size="2"></font><font size="2"><b><span style="font-family:Verdana;">Loop</span></b></font><font size="2"><b><span style="font-family:Verdana;"></span></b>
</font></pre>
<p><span style="font-size:10pt;font-family:Verdana;"></span></p>
<h4><span style="font-size:10pt;font-family:Verdana;">Do Until</span></h4>
<p><span style="font-family:Verdana;"><font size="2">The VBScript <span class="fixed1"><span style="font-family:Verdana;">Do Until</span></span> statement is used to create loops that run as long as the tested condition remains false. Like the <span class="fixed1"><span style="font-family:Verdana;">Do While</span></span> statement there are two versions of the <span class="fixed1"><span style="font-family:Verdana;">Do Until</span></span> statement. The syntax for the first form is </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Do Until <i>condition</i></font></span></b> <b><span style="font-family:Verdana;"><font size="2"> <i>statements</i></font></span></b> <font size="2"><b><span style="font-family:Verdana;">Loop</span></b><b><span style="font-family:Verdana;"></span></b></font></pre>
<p><span style="font-family:Verdana;"><font size="2">For example, the following VBScript statements create a <span class="fixed1"><span style="font-family:Verdana;">Do Until</span></span> loop that sets up a loop that executes until the value assigned to a variable named <span class="fixed1"><span style="font-family:Verdana;">myCount</span></span> exceeds 9. </font></span></p>
<pre><span style="font-family:Verdana;"><font size="2"> </font></span><b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b><b><span style="font-family:Verdana;"><font size="2">Dim Counter</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">myCount = 0</font></span></b>
<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>
<b><span style="font-family:Verdana;"><font size="2">WScript.Echo "Counting to 10 with a Do Until loop"</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Do Until Counter &gt; 6</font></span></b>
<b><span style="font-family:Verdana;"><font size="2"> Counter = Counter + 1</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">WScript.Echo(Counter)</font></span></b> <font size="2"></font><font size="2"><b><span style="font-family:Verdana;">Loop</span></b></font><font size="2"> </font><font size="2"><b><span style="font-family:Verdana;"></span></b>
</font></pre>
<p><span style="font-family:Verdana;"><font size="2">If you save this example as a WSH VBScript and run it using the CScript execution host you will see the following output.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Counting to 5 with a Do Until loop</font></span></b> <b><span style="font-family:Verdana;"><font size="2">1</font></span></b> <b><span style="font-family:Verdana;"><font size="2">2</font></span></b> <b><span style="font-family:Verdana;"><font size="2">3</font></span></b> <b><span style="font-family:Verdana;"><font size="2">4</font></span></b> <b><span style="font-family:Verdana;"><font size="2">5</font></span></b></pre>
<p><span style="font-size:10pt;font-family:Verdana;"> </span><span style="font-family:Verdana;"><font size="2">For example, the following VBScript statements set up a <span class="fixed1"><span style="font-family:Verdana;">Do</span></span> loop that will always execute at least one time. </font></span><span style="font-family:Verdana;"><font size="2"> </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Do</font></span></b><b><span style="font-family:Verdana;"><font size="2"> statements</font></span></b> <b><span style="font-family:Verdana;"><font size="2">Loop Until condition</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">The following VBScript statements set up a loop that executes as long as the value of a controlling variable is not greater than 9.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b><b><span style="font-family:Verdana;"><font size="2">Dim Counter</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Counter = 0</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">WScript.Echo "Counting to 5 with a Do Until loop"</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Do</font></span></b><b><span style="font-family:Verdana;"><font size="2"> Counter = Counter + 1</font></span></b>
<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo(Counter)</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Loop Until Counter &gt; 4</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">If you execute the statements exactly as shown previously, you’ll see the same output that was generated in the previous example. However, try changing the initial value of the <span class="fixed1"><span style="font-family:Verdana;">myCount</span></span> variable to 10. You’ll see that, unlike the previous example, the loop will execute and display the following output. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Counting to 10 with a Do Until loop</font></span></b> <b><span style="font-family:Verdana;"><font size="2">6</font></span></b></pre>
<h4><span style="font-size:10pt;font-family:Verdana;">For…Next</span></h4>
<p><span style="font-family:Verdana;"><font size="2">The VBScript <span class="fixed1"><span style="font-family:Verdana;">For…Next</span></span> statement is used to create loops that will execute for a specific number of operations. The syntax for the first method is </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">For counter = <i>begin</i> To <i>end</i> [Step <i>step_value</i>]</font></span></b> <b><span style="font-family:Verdana;"><font size="2"><span>  </span><i>statements</i></font></span></b><b><span style="font-family:Verdana;"><font size="2">Next</font></span></b></pre>
<p><font size="2"><span class="fixed1"><span style="font-family:Verdana;">Counter</span></span><span style="font-family:Verdana;"> specifies the controlling variable. <span class="fixed1"><span style="font-family:Verdana;">Begin</span></span> specifies its initial value and <span class="fixed1"><span style="font-family:Verdana;">end</span></span> sets its ending value. <span class="fixed1"><span style="font-family:Verdana;">Step_value</span></span> is an optional parameter that specifies the value that will be used to increment the variable after each iteration.</span></font><span style="font-family:Verdana;"><font size="2">For example, the following <span class="fixed1"><span style="font-family:Verdana;">For…Next</span></span> loop sets up a loop that will execute 10 times and display the value of the controlling variable <span class="fixed1"><span style="font-family:Verdana;">i</span></span> for each iteration. The variable <span class="fixed1"><span style="font-family:Verdana;">i</span></span> us used to control loop execution and is automatically incremented by 1 at then end of each execution of the loop.</font><font size="2"> </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b><b><span style="font-family:Verdana;"><font size="2">Dim i</font></span></b><b><span style="font-family:Verdana;"><font size="2">For i = 1 To 5</font></span></b>
<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo i</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Next</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">By adding the <span class="fixed1"><span style="font-family:Verdana;">Step</span></span> keyword you can control the value used to increment the counter. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b><b><span style="font-family:Verdana;"><font size="2">Dim i</font></span></b><b><span style="font-family:Verdana;"><font size="2">For i = 1 To 5 Step 2</font></span></b><b><span style="font-family:Verdana;"><font size="2"> WScript.Echo i</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Next</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">In this example, the number of times that the loop will execute is cut in half. Instead of seeing the output display the number 1 through 10 you see the following.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">C:\&gt;CScript.exe test.vbs</font></span></b>
<b><span style="font-family:Verdana;"></span></b>
<b><span style="font-family:Verdana;"><font size="2">Microsoft (R) Windows Script Host Version 5.6</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.</font></span></b>
<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>
<b><span style="font-family:Verdana;"><font size="2">1</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">3</font></span></b>
<b><span style="font-family:Verdana;"><font size="2"> </font></span></b></pre>
<p><span style="font-size:10pt;font-family:Verdana;">While…Wend</span><br />
<span style="font-family:Verdana;"><font size="2">The VBScript <span class="fixed1"><span style="font-family:Verdana;">While…Wend</span></span> statement is used to create loops that will execute as long as the tested condition remains true. The syntax for the first method is shown below. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">While <i>condition</i></font></span></b><b><span style="font-family:Verdana;"><font size="2"> <i>statements</i></font></span></b> <b><span style="font-family:Verdana;"><font size="2">Wend</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">The functionality provided by the <span class="fixed1"><span style="font-family:Verdana;">While…Wend </span></span>statement is duplicated by the <span class="fixed1"><span style="font-family:Verdana;">Do</span></span> loop. It is generally recommended that you use <span class="fixed1"><span style="font-family:Verdana;">Do</span></span> loops in place of it. However, just in case I’ll give you an example of how to use it. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b>
<b><span style="font-family:Verdana;"></span></b>
<b><span style="font-family:Verdana;"><font size="2">Dim i</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">WScript.Echo "Counting to 10 with a While Wend loop"</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">i = 1</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">While i &lt; 6</font></span></b>
<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo i</font></span></b>
<b><span style="font-family:Verdana;"><font size="2"> i = i + 1</font></span></b>
<b><span style="font-family:Verdana;"><font size="2">Wend</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">If you insert the preceding statements into a WSH VBScript and run it with the CScript execution host you see the following output.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Counting to 10 with a While Wend loop</font></span></b> <b><span style="font-family:Verdana;"><font size="2">1</font></span></b> <b><span style="font-family:Verdana;"><font size="2">2</font></span></b> <b><span style="font-family:Verdana;"><font size="2">3</font></span></b> <b><span style="font-family:Verdana;"><font size="2">4</font></span></b> <b><span style="font-family:Verdana;"><font size="2">5</font></span></b></pre>
<h4><span style="font-size:10pt;font-family:Verdana;">For…Each…Next</span></h4>
<p><span style="font-family:Verdana;"><font size="2">VBScript allows you to work with objects such as disk drives and printers. Each object has a unique set of properties that describe and control its characteristics. For example, a file has a name as does a printer. Using the <span class="fixed1"><span style="font-family:Verdana;">For…Each…Next</span></span> statement you can create a loop that can process all the properties associated with an object.</font></span><span style="font-family:Verdana;"><font size="2">The syntax of the <span class="fixed1"><span style="font-family:Verdana;">For…Each…Next</span></span> statement is </font></span><span style="font-family:Verdana;"><font size="2"> </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">For Each <i>element</i> In <i>collection</i></font></span></b> <b><span style="font-family:Verdana;"><font size="2"> <i>statements</i></font></span></b> <b><span style="font-family:Verdana;"><font size="2">Next [<i>element</i>]</font></span></b></pre>
<p><font size="2"><span class="fixed1"><span style="font-family:Verdana;">Element</span></span><span style="font-family:Verdana;"> is a variable representing a property associated with the <span class="fixed1"><span style="font-family:Verdana;">collection</span></span> (or object). You can also use <span class="fixed1"><span style="font-family:Verdana;">For…Each…Next</span></span> statements to process the contents of arrays. An <i>array</i> is a related connection of index data that provides a more efficient way than using variables to store large amounts of related information. You will learn more about arrays a little later in the morning and will find examples of how to work with the <span class="fixed1"><span style="font-family:Verdana;">For…Each…Next</span></span> loop then.</span></font></p>
<p align="right"><a href="http://kuldeepse.wordpress.com/2008/02/05/5-functions/"><font color="#000044">Next Step &#8211; Functions </font></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kuldeepse.wordpress.com/119/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kuldeepse.wordpress.com/119/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kuldeepse.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kuldeepse.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kuldeepse.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kuldeepse.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kuldeepse.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kuldeepse.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kuldeepse.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kuldeepse.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kuldeepse.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kuldeepse.wordpress.com/119/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=119&subd=kuldeepse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kuldeepse.wordpress.com/2008/02/05/4-looping-statement/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b37d5959686c283f564079068ff8246f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kuldeep</media:title>
		</media:content>
	</item>
		<item>
		<title>3: Conditional Statements</title>
		<link>http://kuldeepse.wordpress.com/2008/02/05/3-conditional-statements/</link>
		<comments>http://kuldeepse.wordpress.com/2008/02/05/3-conditional-statements/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 05:46:28 +0000</pubDate>
		<dc:creator>kuldeep kumar</dc:creator>
				<category><![CDATA[Learn VBScript for QTP (Descriptive Programming)]]></category>

		<guid isPermaLink="false">http://kuldeepse.wordpress.com/?p=118</guid>
		<description><![CDATA[Conditional Logic
VBScript provides two statements that allow you to add logic that can alter the logical execution of scripts. This way your scripts can make decisions based on user or environmental criteria. These statements are listed below.
 ·       If…Then…Else. Guides the logical execution of a script based on one or more tested conditions.
·         Select…Case. Guides the logical [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=118&subd=kuldeepse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3><span style="font-size:10pt;font-family:Verdana;">Conditional Logic</span></h3>
<p><span style="font-family:Verdana;"><font size="2">VBScript provides two statements that allow you to add logic that can alter the logical execution of scripts. This way your scripts can make decisions based on user or environmental criteria. These statements are listed below.</font></span><br />
<span style="font-family:Verdana;"><font size="2"> </font></span><span style="font-family:Verdana;"></span><span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">       </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">If…Then…Else</span></b></span><span style="font-family:Verdana;">. Guides the logical execution of a script based on one or more tested conditions.</span></font><font size="2"><br />
<span style="font-family:Verdana;"></span></font><span style="font-family:Symbol;"><span><font size="2">·</font><span style="font:7pt 'Times New Roman';">         </span></span></span><font size="2"><span class="fixed1"><b><span style="font-family:Verdana;">Select…Case</span></b></span><span style="font-family:Verdana;">. Guides the logical execution of a script based on multiple tests performed against the same condition.</span></font></p>
<h3><span style="font-size:10pt;font-family:Verdana;">If…Then…Else</span></h3>
<p><b><span style="font-family:Verdana;"><font size="2">If <i>condition</i> Then <i>statement </i>[Else <i>statement</i>]</font></span></b></p>
<p><b><span style="font-family:Verdana;"><font size="2"></font></span></b><span style="font-family:Verdana;"><font size="2">If you need to execute more than one VBScript statement as a result of your comparisons, then you’ll need to use the following syntax for the <span class="fixed1"><span style="font-family:Verdana;">If…Then…Else</span></span> statement. </font></span></p>
<pre>
<b><span style="font-family:Verdana;"><font size="2">If <i>condition </i>Then</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span>  </span></font></span></b><b><span style="font-family:Verdana;"><font size="2"><span></span><i>statements</i></font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">ElseIf </font></span></b><b><span style="font-family:Verdana;"><font size="2"><i>condition-n</i> </font></span></b><b><span style="font-family:Verdana;"><font size="2">Then</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span></span><i>statements</i></font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">.</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">.</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Else</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span>  </span></font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span></span><i>statements</i></font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">End If</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">For example, you could modify the <span class="fixed1"><span style="font-family:Verdana;">IF…Then…Else</span></span> statement in the previous example as shown here. </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">If<span>  </span>rupeesSent = rupeesReceived Then</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">MsgBox "No rupess remaining now"</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">rupeesOnhand = 0</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Else</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">MsgBox "This rupess is balance"</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">unitsOnhand = rupeesSent - rupeesReceived</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">End If</font></span></b></pre>
<h4><span style="font-size:10pt;font-family:Verdana;">Select Case</span></h4>
<h4><span style="font-size:10pt;font-family:Verdana;"></span></h4>
<p><span style="font-family:Verdana;"><font size="2">The <span class="fixed1"><span style="font-family:Verdana;">Select…Case</span></span> statement provides functionality that is very similar to the <span class="fixed1"><span style="font-family:Verdana;">If…Then…Else</span></span> statement. However, although the <span class="fixed1"><span style="font-family:Verdana;">If…Then…Else</span></span> statement can test a large number of different conditions, the <span class="fixed1"><span style="font-family:Verdana;">Select… Case</span></span> statement is better equipped to test a large number of criteria against a single condition. The syntax of the <span class="fixed1"><span style="font-family:Verdana;">Select…Case</span></span> statement is </font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Select Case <i>value</i></font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Case <i>expression</i></font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span>  </span><i>statements</i></font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span>  </span>.</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span>  </span>.</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Case <i>expression</i></font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span>  </span><i>statements</i></font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">Case Else</font></span></b>  

<b><span style="font-family:Verdana;"><font size="2"><span>  </span><i>statements</i></font></span></b>  

<b><span style="font-family:Verdana;"><font size="2">End Select</font></span></b></pre>
<p><font size="2"><span class="fixed1"><span style="font-family:Verdana;">Select…Case</span></span><span style="font-family:Verdana;"> evaluates a single value as specified in the <span class="fixed1"><span style="font-family:Verdana;">Select…Case</span></span> statement and compares it against the values stored in each of the <span class="fixed1"><br />
<span style="font-family:Verdana;">Case</span></span> statements that follows as demonstrated in the following example. </span></font></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Select Case myNumber</font></span></b></pre>
<p><b><span style="font-family:Verdana;"><font size="2">Case &#8220;1&#8243;</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2"><span>  </span>MsgBox &#8220;The matching color is 1&#8243;</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">Case &#8220;2&#8243;</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2"><span>  </span>MsgBox &#8220;The matching color is 2&#8243;</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">Case &#8220;3&#8243;</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2"><span>  </span>MsgBox &#8220;The matching color is 3&#8243;</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">Case Else</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2"><span>  </span>MsgBox &#8220;No Number matches&#8221;</font></span></b><br />
<b><span style="font-family:Verdana;"><font size="2">End Select</font></span></b></p>
<p align="right"><a href="http://kuldeepse.wordpress.com/2008/02/05/4-looping-statement/"><font color="#000044">Next Step &#8211; Looping Statements </font></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kuldeepse.wordpress.com/118/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kuldeepse.wordpress.com/118/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kuldeepse.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kuldeepse.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kuldeepse.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kuldeepse.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kuldeepse.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kuldeepse.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kuldeepse.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kuldeepse.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kuldeepse.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kuldeepse.wordpress.com/118/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=118&subd=kuldeepse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kuldeepse.wordpress.com/2008/02/05/3-conditional-statements/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b37d5959686c283f564079068ff8246f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kuldeep</media:title>
		</media:content>
	</item>
		<item>
		<title>2: Operators</title>
		<link>http://kuldeepse.wordpress.com/2008/02/05/operators/</link>
		<comments>http://kuldeepse.wordpress.com/2008/02/05/operators/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 05:33:13 +0000</pubDate>
		<dc:creator>kuldeep kumar</dc:creator>
				<category><![CDATA[Learn VBScript for QTP (Descriptive Programming)]]></category>

		<guid isPermaLink="false">http://kuldeepse.wordpress.com/?p=117</guid>
		<description><![CDATA[Manipulating VBScript Variables with Operators
As you have already seen the VBScript = assignment operator is used to assign a value to a variable. When you are working with variables that contain numeric values, you can use any of the VBScript arithmetic operators, shown in Table, to change the value assigned to variables.


 Arithmetic Operators 

Operator
Description


^
Exponentiation


-
Negation


*
Multiplication


/
Division


\
Integer division


Mod
Modulus


+
Addition


-
Subtraction


&#38;
Concatenation




The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=117&subd=kuldeepse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><b><i><span style="font-size:10pt;font-family:Verdana;">Manipulating VBScript Variables with Operators</span></i></b><br />
<span style="font-family:Verdana;"><font size="2">As you have already seen the VBScript <span class="fixed1"><span style="font-family:Verdana;">=</span></span> assignment operator is used to assign a value to a variable. When you are working with variables that contain numeric values, you can use any of the VBScript arithmetic operators, shown in Table</font><font size="2">, to change the value assigned to variables.</font></span></p>
<table border="1" width="39%" cellPadding="0" style="width:39.7%;" class="MsoNormalTable">
<thead>
<td colSpan="2" width="98%" style="background:white;width:98.26%;border:#ece9d8;padding:0.75pt;"><span><strong><span style="font-size:10pt;color:windowtext;font-family:Verdana;"><span> </span>Arithmetic Operators</span> </strong></span></td>
<tr>
<td width="39%" vAlign="top" style="background:white;width:39.72%;border:#ece9d8;padding:0.75pt;"><b><span style="font-size:10pt;font-family:Verdana;">Operator</span></b></td>
<td width="57%" vAlign="top" style="background:white;width:57.7%;border:#ece9d8;padding:0.75pt;"><b><span style="font-size:10pt;font-family:Verdana;">Description</span></b></td>
</tr>
<tr>
<td width="39%" vAlign="top" style="width:39.72%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">^</span></td>
<td width="57%" vAlign="top" style="width:57.7%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Exponentiation</span></td>
</tr>
<tr>
<td width="39%" vAlign="top" style="width:39.72%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">-</span></td>
<td width="57%" vAlign="top" style="width:57.7%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Negation</span></td>
</tr>
<tr>
<td width="39%" vAlign="top" style="width:39.72%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">*</span></td>
<td width="57%" vAlign="top" style="width:57.7%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Multiplication</span></td>
</tr>
<tr>
<td width="39%" vAlign="top" style="width:39.72%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">/</span></td>
<td width="57%" vAlign="top" style="width:57.7%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Division</span></td>
</tr>
<tr>
<td width="39%" vAlign="top" style="width:39.72%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">\</span></td>
<td width="57%" vAlign="top" style="width:57.7%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Integer division</span></td>
</tr>
<tr>
<td width="39%" vAlign="top" style="width:39.72%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Mod</span></td>
<td width="57%" vAlign="top" style="width:57.7%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Modulus</span></td>
</tr>
<tr>
<td width="39%" vAlign="top" style="width:39.72%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">+</span></td>
<td width="57%" vAlign="top" style="width:57.7%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Addition</span></td>
</tr>
<tr>
<td width="39%" vAlign="top" style="width:39.72%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">-</span></td>
<td width="57%" vAlign="top" style="width:57.7%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Subtraction</span></td>
</tr>
<tr>
<td width="39%" vAlign="top" style="width:39.72%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">&amp;</span></td>
<td width="57%" vAlign="top" style="width:57.7%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Concatenation</span></td>
</tr>
</thead>
</table>
<p><span style="font-family:Verdana;"><font size="2"><br />
The following VBScript statements show how you can apply some of the operators.</font></span></p>
<pre><span style="font-family:Verdana;"><font size="2"><strong>Option Explicit</strong></font></span>   

<b><span style="font-family:Verdana;"><font size="2">Dim myExp</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2">myExp = 37</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2">WScript.Echo " myExp= " &amp; myAge</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b><b><span style="font-family:Verdana;"><font size="2">myExp = myExp + 3</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2">WScript.Echo " myExp = " &amp; myAge</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b> <b><span style="font-family:Verdana;"><font size="2">myExp = myExp - 10</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2">WScript.Echo " myExp = " &amp; myExp</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2"> </font></span></b>   

<b><span style="font-family:Verdana;"><font size="2">myExp = myExp * 2</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2">WScript.Echo " myExp = " &amp; myExp</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">If you were to save this script as part of a WSH VBScript and run it from the CScript.exe execution host then you’d see the output shown here.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">myExp = 37</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2">myExp = 40</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2">myExp = 30</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2">myExp = 60</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">VBScript performs arithmetic operations using a strict set of rules known as the order of operator precedence. </font></span></p>
<h3><span style="font-size:10pt;font-family:Verdana;">Comparison Operators</span></h3>
<p><span style="font-family:Verdana;"><font size="2">VBScript provides a collection of operators that you can use to compare the values of expressions within your VBScripts. These operators are listed inTable</font><font size="2">.</font><font size="2"> </font></span><span style="font-family:Verdana;"><font size="2"> </font></span></p>
<table border="1" width="317" cellPadding="0" style="width:317px;height:152px;" class="MsoNormalTable">
<thead>
<td colSpan="2" style="background:white;border:#ece9d8;padding:0.75pt;"><span><strong><span style="font-size:10pt;color:windowtext;font-family:Verdana;">Comparison Operators</span> </strong></span></td>
<tr>
<td width="50%" vAlign="top" style="background:white;width:50%;border:#ece9d8;padding:0.75pt;"><b><span style="font-size:10pt;font-family:Verdana;">Operator</span></b></td>
<td width="50%" vAlign="top" style="background:white;width:50%;border:#ece9d8;padding:0.75pt;"><b><span style="font-size:10pt;font-family:Verdana;">Description</span></b></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">=</span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Equal</span></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">&lt;&gt; </span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Not equal</span></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">&lt; </span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Less than</span></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">&gt; </span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Greater than</span></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">&lt;=</span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Less than or equal to</span></td>
</tr>
<tr>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">&gt;=</span></td>
<td width="50%" vAlign="top" style="width:50%;background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;font-family:Verdana;">Greater than or equal to</span></td>
</tr>
</thead>
</table>
<p><span style="font-family:Verdana;"><font size="2">Testing the values of variables in your scripts is something that you’ll find yourself doing again and again. When combined with conditional execution logic, which I’ll cover in just a bit, you’ll be able to write scripts that can test for certain conditions and then switch between multiple execution paths based on the results of those tests.</font></span><span style="font-family:Verdana;"><font size="2">Unlike arithmetic operators, there is no order of precedence to the execution of comparison operators. They are executed in the order in which they appear in a statement (e.g., they are evaluated starting from left to right).</font></span><span style="font-family:Verdana;"><font size="2">For example, the following statement tests to see if values of two variables are equal.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">Option Explicit</font></span></b> <b><span style="font-family:Verdana;"><font size="2">Dim myExp, yourExp</font></span></b><b><span style="font-family:Verdana;"><font size="2">If myExp = yourExp Then</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo "Congrates!!!"</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2">End If</font></span></b></pre>
<p><span style="font-family:Verdana;"><font size="2">Similarly, you can test for greater than or less than values.</font></span></p>
<pre><b><span style="font-family:Verdana;"><font size="2">If myExp &gt; yourExp Then</font></span></b><b><span style="font-family:Verdana;"><font size="2"> WScript.Echo "May I Check it?"</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2">End If</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2">If myExp &lt; yourExp Then</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2"> WScript.Echo "Would you like to Check it?"</font></span></b>   

<b><span style="font-family:Verdana;"><font size="2">End If</font></span></b></pre>
<p align="right"><a href="http://kuldeepse.wordpress.com/2008/02/05/3-conditional-statements/"><font color="#000044">Next Step &#8211; Conditional Statements</font></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kuldeepse.wordpress.com/117/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kuldeepse.wordpress.com/117/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kuldeepse.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kuldeepse.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kuldeepse.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kuldeepse.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kuldeepse.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kuldeepse.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kuldeepse.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kuldeepse.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kuldeepse.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kuldeepse.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kuldeepse.wordpress.com&blog=805460&post=117&subd=kuldeepse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kuldeepse.wordpress.com/2008/02/05/operators/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b37d5959686c283f564079068ff8246f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kuldeep</media:title>
		</media:content>
	</item>
	</channel>
</rss>