<?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/"
	>

<channel>
	<title>Relevant Codes (by Anshoo Arora) &#187; VBScript</title>
	<atom:link href="http://relevantcodes.com/category/vbscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://relevantcodes.com</link>
	<description>A Resource for Test Automation Development</description>
	<lastBuildDate>Thu, 10 May 2012 10:32:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Testing Web Services using QTP, VBScript</title>
		<link>http://relevantcodes.com/working-with-webservices/</link>
		<comments>http://relevantcodes.com/working-with-webservices/#comments</comments>
		<pubDate>Fri, 16 Mar 2012 20:55:09 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[CreateXML]]></category>
		<category><![CDATA[CreateXMLFromFile]]></category>
		<category><![CDATA[Distance Matrix]]></category>
		<category><![CDATA[Get]]></category>
		<category><![CDATA[Google API]]></category>
		<category><![CDATA[LoadXML]]></category>
		<category><![CDATA[Post]]></category>
		<category><![CDATA[ResponseText]]></category>
		<category><![CDATA[WebService]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XMLDOM]]></category>
		<category><![CDATA[XMLHTTP]]></category>
		<category><![CDATA[XMLHTTPRequest]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=4994</guid>
		<description><![CDATA[This article was originally requested by one of our visitors - Dhup Chaya. It shows a way to work with Web Services (Google's Distance Matrix API) using XMLHTTPRequest (sending request &#038; receiving response) and parsing the response with both XMLUtil and XMLDOM.]]></description>
			<content:encoded><![CDATA[<p></p><p>W3C defines a Web service as &#8220;a standard means of interoperating between different software applications, running on a variety of platforms and/or frameworks&#8221;. In simple terms, a Web service can be used to integrate web applications. In this exchange of data, XML is used to tag data, SOAP is used to transfer data, WSDL is used to describe how data is exchanged and finally, UDDI lists the services available. For further reading, you can visit <a href="http://msdn.microsoft.com/en-us/library/ms996507.aspx">XML Web Services Basics</a>.</p>
<p>In this topic, we will be using 3 important objects and provide their overview before diving deep into this topic. They are:</p>
<ol>
<li>XMLUtil</li>
<li>XMLDOM</li>
<li>XMLHTTPRequest</li>
</ol>
<h3>XMLUtil</h3>
<p>XMLUtil object provided with QTP is used to access and return XML objects. In other words, XMLUtil can be used to access or expose the contents of an XML file. XMLUtil supports the following 2 methods to create and return an object of type XMLData:</p>
<ol>
<li>CreateXML Method</li>
<li>CreateXMLFromFile</li>
</ol>
<p>More information regarding XMLUtil can be located at QuickTest Professional Object Model Reference.</p>
<h3>XMLDOM</h3>
<p>Similar to XMLUtil object used in QTP, XMLDOM also provides methods and properties to access and return XML objects. I am more accustomed to using this object as opposed to XMLUtil, but they can be both used interchangeably. For further reading, you can visit <a href="http://msdn.microsoft.com/en-us/library/aa468547.aspx">A Beginner&#8217;s Guide to the XML DOM</a>. To create an instance of XMLDOM, CreateObject must be used.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Set</span> xmlParser = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Microsoft.XMLDOM&quot;</span>)</pre></div></div>

<h3>XMLHTTPRequest</h3>
<p>Unlike XMLUtil and XMLDOM, which are both XML parsers, the XMLHTTPRequest object is an API used to send HTTP or HTTPS requests directly to a Web Server and receiving the response using its Post, Send and Get methods. For further reading, you can visit <a href="http://msdn.microsoft.com/en-us/library/ie/ms535874%28v=vs.85%29.aspx">XMLHttpRequest object</a>. To create an instance of XMLHTTPRequest, CreateObject must be used.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Set</span> XMLHTTPRequest = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Microsoft.XMLHTTP&quot;</span>)</pre></div></div>

<h2>Google Maps &#8211; The Distance Matrix API</h2>
<p>The Google <a href="https://developers.google.com/maps/documentation/distancematrix/">Distance Matrix API</a> is a Web service used to provide travel distance and time for travel start (origins) and end points (destinations). The response from the API consists of rows containing data for each origin and destination pair.</p>
<p>To request information from the Distance Matrix API, the following URL with <code>output</code> type and input <code>parameters</code> must be used:</p>
<pre>http://maps.googleapis.com/maps/api/distancematrix/output?parameters</pre>
<h3>Output</h3>
<p>Output may be in either <code>JSON</code> or <code>XML</code>. In this topic, <code>XML</code> will be used.</p>
<h3>Parameters</h3>
<p>There is a total of 7 parameters that can be used to request information back from the API. 4 of these parameters are optional.</p>
<ol>
<li>Origins (required)</li>
<li>Destinations (required)</li>
<li>Mode (optional)</li>
<li>Language (optional)</li>
<li>Avoid (optional)</li>
<li>Units (optional)</li>
<li>Sensor (required)</li>
</ol>
<p>For more information, you can refer to the Distance Matrix API <a href="https://developers.google.com/maps/documentation/distancematrix/">documentation</a>.</p>
<p>I feel we&#8217;ve covered enough basics and its time to dig into exchanging data with the Distance Matrix API and then, parse it to get values we&#8217;re concerned with. Below are the values we will be using to request data:</p>
<ul>
<li>output = xml</li>
<li>origins = Atlanta, GA, USA</li>
<li>destinations = Dallas, TX, USA</li>
<li>units = imperial (in miles)</li>
<li>sensor = False</li>
</ul>
<p>The final URL string:</p>
<pre>http://maps.googleapis.com/maps/api/distancematrix/xml?origins=Atlanta+GA+USA&#038;destinations=Dallas+TX+USA&#038;units=imperial&#038;sensor=false</pre>
<p>I also computed the distance using the Google Maps UI (maps.google.com) and got the following result. The result below should match the result obtained from XMLHTTPRequest.</p>
<p><img alt="" class="imgborder" src="/Articles/WorkingWithWebServices/by_car.jpg" title="Google Maps output" class="aligncenter" width="319" height="335" /></p>
<h2>Requesting Information from Distance Matrix API</h2>
<p>In the following code, XMLHTTPRequest object is used to send the string above and receive the corresponding response from the Distance Matrix API.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">url = <span style="color: #800000;">&quot;http://maps.googleapis.com/maps/api/distancematrix/xml?&quot;</span> &amp; _
		<span style="color: #800000;">&quot;origins=Atlanta+GA+USA&amp;&quot;</span> &amp; _
		<span style="color: #800000;">&quot;destinations=Dallas+TX+USA&amp;&quot;</span> &amp; _
		<span style="color: #800000;">&quot;units=imperial&amp;&quot;</span> &amp; _
		<span style="color: #800000;">&quot;sensor=false&quot;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Set</span> oReq = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Microsoft.XMLHTTP&quot;</span>)
&nbsp;
oReq.<span style="color: #0600FF; font-weight: bold;">open</span> <span style="color: #800000;">&quot;POST&quot;</span>, url, <span style="color: #0600FF; font-weight: bold;">False</span>
oReq.send
&nbsp;
<span style="color: #008000;">'Response
</span>responseText = oReq.responseText
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Print</span> responseText</pre></div></div>

<h5>Output</h5>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DistanceMatrixResponse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>OK<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;origin_address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Atlanta, GA, USA<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/origin_address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;destination_address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Dallas, TX, USA<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/destination_address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>OK<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;duration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>47410<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>13 hours 10 mins<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/duration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;distance<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1254681<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>780 mi<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/distance<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DistanceMatrixResponse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Simple, isn&#8217;t it? Receiving the response is one thing, parsing it for data important to us is another. In the next part, parsing the above XML will be shown using both XMLUtil and XMLDOM objects.</p>
<h2>Parsing Information using XMLUtil, XMLDOM</h2>
<p>In the last section, we received some data from Google&#8217;s Distance Matrix API by using the <code>.responseText</code> method of XMLHTTPRequest. In this section, we will parse the ResponseText to retrieve the time taken and distance of travel. Below are the 2 nodes from the output above we&#8217;re concerned with:</p>
<pre>
DistanceMatrixResponse\row\element\duration\text
DistanceMatrixResponse\row\element\distance\text
</pre>
<p>I have used the method <code>GetValueByXPath</code> but you can also use <code>ChildElements</code> and <code>ChildElementsByPath</code> methods.</p>
<h5>XMLUtil</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">sNodeDistance = <span style="color: #800000;">&quot;row/element/distance/text&quot;</span>
sNodeDuration = <span style="color: #800000;">&quot;row/element/duration/text&quot;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Set</span> oParser = XMLUtil.CreateXML()
&nbsp;
<span style="color: #008000;">'Note: responseText comes from XMLHTTPRequest in the previous section
</span>oParser.Load responseText
&nbsp;
<span style="color: #008000;">'Using the XPath above to retrieve distance
</span>nodeDistance = oParser.GetRootElement.GetValueByXPath(sNodeDistance)
&nbsp;
<span style="color: #008000;">'Using the XPath above to retrieve duration
</span>nodeDuration = oParser.GetRootElement.GetValueByXPath(sNodeDuration)
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Print</span> nodeDistance
<span style="color: #0600FF; font-weight: bold;">Print</span> nodeDuration</pre></div></div>

<h5>Output</h5>
<p><img alt="" class="imgborder" src="/Articles/WorkingWithWebServices/output.jpg" title="Output" class="aligncenter" width="312" height="153" /></p>
<p>With XMLDOM, I have used the method <code>selectSingleNode</code> but you could also use <code>selectNodes</code>, <code>getElementsByTagName</code> etc. to drill down to the target node.</p>
<h5>XMLDOM</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">sNodeDistance = <span style="color: #800000;">&quot;row/element/distance/text&quot;</span>
sNodeDuration = <span style="color: #800000;">&quot;row/element/duration/text&quot;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Set</span> oParser = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Microsoft.XMLDOM&quot;</span>)
&nbsp;
<span style="color: #008000;">'Note: responseText comes from XMLHTTPRequest in the previous section
</span>oParser.loadXML(responseText)
&nbsp;
<span style="color: #008000;">'Distance node: comes from XPath above
</span><span style="color: #0600FF; font-weight: bold;">Set</span> nodeDistance = oParser.documentElement.selectSingleNode(sNodeDistance)
&nbsp;
<span style="color: #008000;">'Duration node: comes from XPath above
</span><span style="color: #0600FF; font-weight: bold;">Set</span> nodeDuration = oParser.documentElement.selectSingleNode(sNodeDuration)
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Print</span> nodeDistance.text
<span style="color: #0600FF; font-weight: bold;">Print</span> nodeDuration.text</pre></div></div>

<h5>Output</h5>
<p><img alt="" class="imgborder" src="/Articles/WorkingWithWebServices/output.png" title="Output" class="aligncenter" width="312" height="153" /></p>
<h2>Summary</h2>
<p>In this topic, we saw how to send a request and receive response using XMLHTTPRequest. Later, to parse the response, we used XMLDOM and XMLUtil to retrieve the results.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/working-with-webservices/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>ExcelUtil Class Library (MS Excel Utility Methods)</title>
		<link>http://relevantcodes.com/excelutil-class-library-excel-utility-methods/</link>
		<comments>http://relevantcodes.com/excelutil-class-library-excel-utility-methods/#comments</comments>
		<pubDate>Sat, 12 Mar 2011 20:34:45 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Excel Utility]]></category>
		<category><![CDATA[ExcelUtil]]></category>
		<category><![CDATA[ExcelUtil Class Library]]></category>
		<category><![CDATA[RelevantCodes]]></category>
		<category><![CDATA[RelevantCodes.ExcelUtil]]></category>
		<category><![CDATA[SetFile]]></category>
		<category><![CDATA[VBScript Excel]]></category>
		<category><![CDATA[VBScript ExcelUtil]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=4100</guid>
		<description><![CDATA[Over the past few years, I have read numerous threads and posts talking about working with Excel using VBScript. Not only have there been numerous threads, but also frameworks that use Excel as the input and/or driver engine. I wanted to work on this mini-project for a long time, and I finally have Version 1.0 of ExcelUtil ready for download! It comes with .CHM documentation.]]></description>
			<content:encoded><![CDATA[<p></p><p>
Over the past few years, I have read numerous threads and posts talking about working with Excel using VBScript. Not only have there been numerous threads, but also frameworks that use Excel as the input and/or driver engine. I wanted to work on this mini-project for a long time, and I finally have Version 1.0 of ExcelUtil ready for download! It comes with <a href="http://relevantcodes.com/Articles/ExcelUtil/Documentation.chm">.CHM documentation</a>.
</p>
<p>
I&#8217;m quite sure I have missed some methods that the community uses, which I have not been able to include in the 1st version. I, however, am open to suggestions and would gladly include your ideas for Version 2.0.
</p>
<p class="centeralign th-box download"><span style='font-weight:bold;'><a class="downloadlink" href="http://relevantcodes.com/wp-content/plugins/download-monitor/download.php?id=11" title="Version1.0 downloaded 1302 times" >Download RelevantCodes.ExcelUtil Class Library (1302)</a></span></p>
<p>
<strong>IMPORTANT:</strong> To use any method of ExcelUtil, <strong>be sure to use <code>SetFile</code></strong>. This will set the Excel WorkBook and WorkSheet ready for use. To use a different WorkBook or WorkSheet, <code>SetFile</code> will have to be called again.
</p>
<h3>SetFile Property</h3>
<h5>Value Type</h5>
<p class="info">Read only.  A [RelevantCodes.ExcelUtil] object.</p>
<h5>Description</h5>
<p class="info">Sets the region instances for Excel WorkBook and WorkSheet. These instances for the Excel source are created only once and used by other methods. <strong>NOTE: For any method to execute, SetFile must be executed first to set the WorkBook and WorkSheet.</strong></p>
<h5>Syntax</h5>
<pre>
ExcelUtil.SetFile WorkBookPath, WorkSheet
</pre>
<h5>Examples</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Example 1
</span>ExcelUtil.SetFile <span style="color: #800000;">&quot;C:\Student.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>
&nbsp;
<span style="color: #008000;">'Example 2:  Reading value directly from a file
</span>sCellValue = ExcelUtil.SetFile(<span style="color: #800000;">&quot;C:\Student.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>).GetCellValue(1, 1)
&nbsp;
<span style="color: #008000;">'Example 3:  Reading values from 2 different files - Approach 1
</span>ExcelUtil.SetFile <span style="color: #800000;">&quot;C:\Student.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>
var1 = ExcelUtil.GetCellValue(1, 1)
ExcelUtil.SetFile <span style="color: #800000;">&quot;C:\Teacher.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>
var2 = ExcelUtil.GetCellValue(1, 1)
&nbsp;
<span style="color: #008000;">'Example 4:  Reading values from 2 different files - Approach 2
</span>var1 = ExcelUtil.SetFile(<span style="color: #800000;">&quot;C:\Student.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>).GetCellValue(1, 1)
var2 = ExcelUtil.SetFile(<span style="color: #800000;">&quot;C:\Teacher.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>).GetCellValue(1, 1)</pre></div></div>

<h3>I found a Bug. What should I do next?</h3>
<p>
Reporting the bug in the comments section will ensure the next version of this class library is more robust! It may not be possible to release the fixed code immediately, but notifying me and the readers of all potential bugs will be highly appreciated! Thank you.
</p>
<h3>I have something cool I would like you to add to ExcelUtil.</h3>
<p>
I would love to hear all ideas and suggestions to improve or enhance this library. Please use the comments section to share them with me and the community. Thank you.
</p>
<p class="centeralign th-box download"><span style='font-weight:bold;'><a class="downloadlink" href="http://relevantcodes.com/wp-content/plugins/download-monitor/download.php?id=11" title="Version1.0 downloaded 1302 times" >Download RelevantCodes.ExcelUtil Class Library (1302)</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/excelutil-class-library-excel-utility-methods/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>IE Error: A script is causing IE to run slowly</title>
		<link>http://relevantcodes.com/ie-error-a-script-is-causing-ie-to-run-slowly/</link>
		<comments>http://relevantcodes.com/ie-error-a-script-is-causing-ie-to-run-slowly/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 03:55:25 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[IE Error]]></category>
		<category><![CDATA[MaxScriptStatements]]></category>
		<category><![CDATA[QTP Web]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=3973</guid>
		<description><![CDATA[This tip shows how to disable the Error message: "A script on this page is causing Internet Explorer to run slowly" with using VBScript.]]></description>
			<content:encoded><![CDATA[<p></p><p>
While testing a script on IE8, me and my colleague kept getting the error &#8220;A script on this page is causing Internet Explorer to run slowly&#8221;.  Below is a snapshot of the error:</p>
<p><img alt="" class="imgborder" src="http://relevantcodes.com/Articles/IEScriptRunningSlow/ie_error.JPG" title="IE Error: A script is causing IE to run slowly" class="aligncenter" width="340" height="155" /></p>
<p>After some research, I came across an article on MSDN which already had the solution: <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;175500">Microsoft KB # 175500</a>. The part we are concerned about is in the section &#8220;Let me fix it myself&#8221;:</p>
<p class="info">
1.Using a Registry Editor such as Regedt32.exe, open this key: <i>HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Styles</i><br />
Note: If the Styles key is not present, create a new key that is called Styles.<br />
2. Create a new DWORD value called &#8220;MaxScriptStatements&#8221; under this key and set the value to the desired number of script statements. If you are unsure of what value you need to set this to, you can set it to a DWORD value of 0xFFFFFFFF to completely avoid the dialog.
</p>
<p>
For the curious ones, the article states that, to encounter the error, the DWord value of <strong>0xFFFFFFFF</strong> must be added.  The value equates to -1, which is what has been used in the function below.
</p>
<h5>Code</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Sub</span> IE_ChangeScriptTimeOut()
	<span style="color: #0600FF; font-weight: bold;">Dim</span> Registry, sKeyPath, sValueName, dwValue, sComputer
	CONST HKEY_CURRENT_USER = &amp;H80000001
&nbsp;
	sKeyPath = <span style="color: #800000;">&quot;Software\Microsoft\Internet Explorer\Styles&quot;</span>
	sValueName = <span style="color: #800000;">&quot;MaxScriptStatements&quot;</span>
	dwValue = -1
	sComputer = <span style="color: #800000;">&quot;.&quot;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Resume</span> <span style="color: #0600FF; font-weight: bold;">Next</span>
		<span style="color: #0600FF; font-weight: bold;">Set</span> Registry = <span style="color: #0600FF; font-weight: bold;">GetObject</span>(<span style="color: #800000;">&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot;</span> &amp;_ 
				sComputer &amp; <span style="color: #800000;">&quot;\root\default:StdRegProv&quot;</span>)
&nbsp;
		Registry.CreateKey HKEY_CURRENT_USER, sKeyPath
		Registry.SetDWORDValue HKEY_CURRENT_USER, sKeyPath, sValueName, CLng(dwValue)
	<span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Goto</span> 0
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">Set</span> Registry = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span></pre></div></div>

<p>
Thanks for reading, and thanks for visiting Relevant Codes! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/ie-error-a-script-is-causing-ie-to-run-slowly/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>QTP GUI Objects, VBScript &amp; Try Catch Finally</title>
		<link>http://relevantcodes.com/gui-objects-vbscript-try-catch-finally/</link>
		<comments>http://relevantcodes.com/gui-objects-vbscript-try-catch-finally/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 06:31:17 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Catch]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Classes]]></category>
		<category><![CDATA[Error Handling]]></category>
		<category><![CDATA[Finally]]></category>
		<category><![CDATA[Module]]></category>
		<category><![CDATA[QTP Module]]></category>
		<category><![CDATA[Test Module]]></category>
		<category><![CDATA[Try]]></category>
		<category><![CDATA[Try..Catch..Finally]]></category>
		<category><![CDATA[Wrapper]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=3802</guid>
		<description><![CDATA[VBScript's error handling techniques have been quite limited to <code>On Error</code> statements, and even though they satisfy our needs to some extent, the lack of incorporating dynamic behavior with them has been a much bigger issue. In this article, I will implement a Try-Catch-Finally statement with QTP's GUI objects along with an On Error statement. This will enable dynamic behavior and enable us to easily divide flow depending on different error conditions.]]></description>
			<content:encoded><![CDATA[<p></p><p>
VBScript&#8217;s error handling techniques have been quite limited to <code>On Error</code> statements, and even though they satisfy our needs to some extent, the lack of incorporating dynamic behavior with them has been a much bigger issue. Lee Harvey <a href="http://my.opera.com/Lee_Harvey/blog/2007/04/21/try-catch-finally-in-vbscript-sure">here</a> shows how <code>Classes</code> can be extended to create simple Try-Catch-Finally statements with just a bit more work. I like this technique, and have been using it for the past few days with success. We know that this is not the best solution that is possible with a scripting language (JS does a lot better!), but its a start and a terrific workaround (thanks Lee!).
</p>
<h2>Creating Try-Catch-Finally Statements in VBScript</h2>
<p>
If you have already read Lee&#8217;s article, you can skip this part. Otherwise, a simple implementation is shown below:
</p>
<ol>
<li>As soon as the class executes, it enters Class_Initialize &#8211; Try statement</li>
<li>It encounters an error &#8211; Err.Raise 1002</li>
<li>As soon as it encounters an error, the Try statement (Class_Initialize) immediately ends execution</li>
<li>Because we&#8217;re releasing the Class reference using <code>Set NewTryCatchFinally = Nothing</code> right after initializing it, the Class enters Class_Terminate</li>
<li>Class_Terminate calls the Catch subroutine</li>
<li>When Catch runs in its entirety, Class_Terminate executes</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Resume</span> <span style="color: #0600FF; font-weight: bold;">Next</span>
&nbsp;
<span style="color: #6666CC; font-weight: bold;">Class</span> TryCatchFinally
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Initialize</span> <span style="color: #008000;">'Try
</span>        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Entering Try..&quot;</span> &amp; vbNewLine
&nbsp;
        Err.Raise 1002 <span style="color: #008000;">'Raise a Syntax Error
</span>        MsgBox <span style="color: #800000;">&quot;This line will not execute&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> Catch <span style="color: #008000;">'Catch
</span>        <span style="color: #0600FF; font-weight: bold;">If</span> Err.Number = 0 <span style="color: #0600FF; font-weight: bold;">Then</span> <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Entering Catch..&quot;</span>
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Error caught: &quot;</span> &amp; Err.Description  &amp; vbNewLine
&nbsp;
        Err.Clear
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Terminate</span> : Catch <span style="color: #008000;">'Finally
</span>        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Exiting..&quot;</span> 
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span>
&nbsp;
<span style="color: #008000;">'Enters Try (Error occurs)
</span><span style="color: #0600FF; font-weight: bold;">Set</span> NewTryCatchFinally = <span style="color: #0600FF; font-weight: bold;">New</span> TryCatchFinally 
&nbsp;
<span style="color: #008000;">'Enters Catch, then Finally
</span><span style="color: #008000;">'Catch will only execute if Error occured
</span><span style="color: #0600FF; font-weight: bold;">Set</span> NewTryCatchFinally = <span style="color: #0600FF; font-weight: bold;">Nothing</span></pre></div></div>

<p>
The output of executing the above code should be the following:
</p>
<div class="wp-caption aligncenter" style="width: 299px">
	<img alt="" src="http://relevantcodes.com/Articles/VBScriptTryCatchFinallyIntro/TryCatchPrintLog.png" title="Try Catch Finally Implementation in VBScript" width="299" height="221" />
	<p class="wp-caption-text">Try Catch Finally Implementation in VBScript</p>
</div>
<p>
We can see from the result that as soon as the Class executes, it enters <code>Class_Initialize</code>. When it encounters an error, it enters into <code>Class_Terminate</code> which contains (and executes) the <code>Catch</code> method. A simple yet such an elegant solution!
</p>
<h2>Utility Class &#038; Error Handler</h2>
<p>
In this article, I will try to implement the technique with QTP&#8217;s GUI objects. To begin, let&#8217;s create a simple Login class with the following methods:
</p>
<ol>
<li><code>CheckPage</code></li>
<li><code>CheckImage</code></li>
<li><code>Login</code></li>
</ol>
<p>
The Login Class outputs the result through the <code>Result</code> property:
</p>
<h5>A simple Login Class</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Resume</span> <span style="color: #0600FF; font-weight: bold;">Next</span>
&nbsp;
<span style="color: #6666CC; font-weight: bold;">Class</span> Login
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Get</span> Result
        Result = CheckPage <span style="color: #0600FF; font-weight: bold;">And</span> CheckImage <span style="color: #0600FF; font-weight: bold;">And</span> Login
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Function</span> CheckPage
        MsgBox <span style="color: #800000;">&quot;CheckPage&quot;</span> : CheckPage = <span style="color: #0600FF; font-weight: bold;">True</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Function</span> CheckImage
        CheckImage = <span style="color: #0600FF; font-weight: bold;">False</span>
&nbsp;
        Browser(<span style="color: #800000;">&quot;title:=Welcome.*&quot;</span>).WebElement(<span style="color: #800000;">&quot;text:=Relevant Codes&quot;</span>).Click <span style="color: #008000;">'Error here!
</span>
        MsgBox <span style="color: #800000;">&quot;Error!&quot;</span> <span style="color: #008000;">'This will not execute
</span>    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
    <span style="color: #008000;">'This will not execute
</span>    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Function</span> Login
        MsgBox <span style="color: #800000;">&quot;Login&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Dim</span> NewLogin : <span style="color: #0600FF; font-weight: bold;">Set</span> NewLogin = <span style="color: #0600FF; font-weight: bold;">New</span> Login</pre></div></div>

<p class="info">
Above, the Result property of the Login Class is called, which first executes CheckPage, then CheckImage and finally Login. Note that Login will only execute if CheckImage runs without any errors.
</p>
<p>
Let&#8217;s create another class that calls the methods of the original Login class, but with the error handling capabilities of a Try-Catch-Finally statement. This is also the Class that will always execute the original Login class because that&#8217;s where the actual error handling using Try-Catch-Finally exists.
</p>
<h5>Try..Catch..Finally with Class_Initialize &#038; Class_Terminate</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #6666CC; font-weight: bold;">Class</span> LoginHandler <span style="color: #008000;">'LoginHandler start
</span>
    <span style="color: #0600FF; font-weight: bold;">Public</span> bResult
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Initialize</span>
         <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Entering Try..&quot;</span> &amp; vbNewLine
         bResult = NewLogin.Result
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> CatchErr
        <span style="color: #0600FF; font-weight: bold;">If</span> Err.Number = 0 <span style="color: #0600FF; font-weight: bold;">Then</span> <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Entering Catch..&quot;</span>
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Error: &quot;</span> &amp; Err.Description &amp; vbNewLine
&nbsp;
        Err.Clear
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Terminate</span> : CatchErr
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Exiting..&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span> <span style="color: #008000;">'LoginHandler end
</span>
<span style="color: #008000;">'NewLoginHnder executes the Login Class in 'try'
</span><span style="color: #0600FF; font-weight: bold;">Set</span> NewLoginHandler = <span style="color: #0600FF; font-weight: bold;">New</span> LoginHandler
&nbsp;
<span style="color: #008000;">'Releasing the instances invokes CatchErr, then Class_Terminate()
</span><span style="color: #0600FF; font-weight: bold;">Set</span> NewLoginHandler = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
&nbsp;
<span style="color: #008000;">'Release NowLogin instance
</span><span style="color: #0600FF; font-weight: bold;">Set</span> NewLogin = <span style="color: #0600FF; font-weight: bold;">Nothing</span></pre></div></div>

<p class="info">
The <code>Class_Initialize</code> method of the class calls the Result property of the Login class. Once Result is called, it executes all the methods called by the Result property. If any error occurs, CatchErr is immediately called by <code>Class_Terminate</code> and later, all code inside the Class_Terminate method is executed.
</p>
<p>
Output of executing Login Class &#038; LoginHandler:
</p>
<div class="wp-caption aligncenter" style="width: 500px">
	<img alt="" src="http://relevantcodes.com/Articles/VBScriptTryCatchFinallyIntro/PrintLog1.png" title="Print Log" width="500" height="199" />
	<p class="wp-caption-text">QTP Print Log</p>
</div>
<h2>Method Containing the Error?</h2>
<p>
By including the name of each method in the very first line, we can also find out where exactly the error occurred. This, however, I agree is quite time consuming and repetitive work. The only alternative to this has been shown by PowerDebug Beta. However, if you would like to extend the above approach in VBScript, this *may be* the only possible approach. I&#8217;ve been wrong before, and would love to see a technique which simplifies the method naming approach used below.
</p>
<h5>Login Class with Method Names</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Resume</span> <span style="color: #0600FF; font-weight: bold;">Next</span>
&nbsp;
<span style="color: #6666CC; font-weight: bold;">Class</span> Login <span style="color: #008000;">'Login start
</span>
    <span style="color: #0600FF; font-weight: bold;">Public</span> sMethod
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Get</span> Result
        Result = CheckPage <span style="color: #0600FF; font-weight: bold;">And</span> CheckImage <span style="color: #0600FF; font-weight: bold;">And</span> Login
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Function</span> CheckPage
        Me.sMethod = <span style="color: #800000;">&quot;CheckPage&quot;</span>
&nbsp;
        MsgBox <span style="color: #800000;">&quot;CheckPage&quot;</span> : CheckPage = <span style="color: #0600FF; font-weight: bold;">True</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Function</span> CheckImage
        Me.sMethod = <span style="color: #800000;">&quot;CheckImage&quot;</span>
&nbsp;
        CheckImage = <span style="color: #0600FF; font-weight: bold;">False</span>
        Browser(<span style="color: #800000;">&quot;title:=Welcome.*&quot;</span>).WebElement(<span style="color: #800000;">&quot;text:=Relevant Codes&quot;</span>).Click <span style="color: #008000;">'Error here!
</span>        
        MsgBox <span style="color: #800000;">&quot;Error!&quot;</span> <span style="color: #008000;">'This will not execute
</span>    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Function</span> Login <span style="color: #008000;">'This will not execute
</span>        Me.sMethod = <span style="color: #800000;">&quot;Login&quot;</span>
&nbsp;
        Msgbox <span style="color: #800000;">&quot;Login&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span> <span style="color: #008000;">'Login end
</span><span style="color: #0600FF; font-weight: bold;">Dim</span> NewLogin : <span style="color: #0600FF; font-weight: bold;">Set</span> NewLogin = <span style="color: #0600FF; font-weight: bold;">New</span> Login</pre></div></div>

<h5>LoginHandler (Outputs Method Names)</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #6666CC; font-weight: bold;">Class</span> LoginHandler <span style="color: #008000;">'LoginHandler start
</span>
    <span style="color: #0600FF; font-weight: bold;">Public</span> bResult
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Initialize</span>
         <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Entering Try..&quot;</span> &amp; vbNewLine
         bResult = NewLogin.Result
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> CatchErr
        <span style="color: #0600FF; font-weight: bold;">If</span> Err.Number = 0 <span style="color: #0600FF; font-weight: bold;">Then</span> <span style="color: #0600FF; font-weight: bold;">Exit</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Entering Catch..&quot;</span>
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Error occured in: &quot;</span> &amp; NewLogin.sMethod
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Error: &quot;</span> &amp; Err.Description &amp; vbNewLine
&nbsp;
        Err.Clear
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Terminate</span> : CatchErr
        <span style="color: #0600FF; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Exiting..&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span> <span style="color: #008000;">'LoginHandler end
</span>
<span style="color: #0600FF; font-weight: bold;">Set</span> NewLoginHandler = <span style="color: #0600FF; font-weight: bold;">New</span> LoginHandler
<span style="color: #0600FF; font-weight: bold;">Set</span> NewLoginHandler = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
<span style="color: #0600FF; font-weight: bold;">Set</span> NewLogin = <span style="color: #0600FF; font-weight: bold;">Nothing</span></pre></div></div>

<p>
View <a href="http://relevantcodes.com/Articles/VBScriptTryCatchFinallyIntro/Example2.txt">code</a>.
</p>
<p>
Output of executing Login Class &#038; LoginHandler:
</p>
<div class="wp-caption aligncenter" style="width: 502px">
	<img alt="" src="http://relevantcodes.com/Articles/VBScriptTryCatchFinallyIntro/PrintLog2.png" title="Print Log" width="502" height="211" />
	<p class="wp-caption-text">QTP Print Log</p>
</div>
<h2>Notes</h2>
<p>
After using this technique for several days and manipulating it a bit from the original work, I have found some success. However, implementing Handler classes when the scope of the utility class increases can be quite challenging, and time consuming. I still believe its a start to something that we haven&#8217;t witnessed in QTP (yet). To be honest, I still prefer the old way of doing things where I can branch out most of my GUI code in conditional statements &#8211; which has enabled me to always create more comprehensive reporting.</p>
<p>
My recommendation would be to use this approach with VBScript code instead of using it for QTP&#8217;s GUI objects, ofcourse, until absolutely necessary. Most of my usage for the above technique has been with pure VBScript code which has enabled me to create better error handling. In an upcoming article, I will show how this technique will be used to handle Excel errors and recover from them in the <code>CatchErr</code> method using a Select Case block. Including Try-Catch-Finally statements within Try-Catch-Finally statements is quite easily done in .NET, but its very complex to perform the same operation with VBScript. I&#8217;m still happy to have a start though.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/gui-objects-vbscript-try-catch-finally/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Eval Function &amp; Execute Statement</title>
		<link>http://relevantcodes.com/eval-function-execute-statement/</link>
		<comments>http://relevantcodes.com/eval-function-execute-statement/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 20:24:29 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Eval]]></category>
		<category><![CDATA[Eval Function]]></category>
		<category><![CDATA[Execute]]></category>
		<category><![CDATA[Execute Statement]]></category>
		<category><![CDATA[QTP Eval Function]]></category>
		<category><![CDATA[QTP Execute]]></category>
		<category><![CDATA[QTP Execute Statement]]></category>
		<category><![CDATA[VBScript Eval]]></category>
		<category><![CDATA[VBScript Eval Function]]></category>
		<category><![CDATA[VBScript Execute]]></category>
		<category><![CDATA[VBScript Execute Statement]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=3447</guid>
		<description><![CDATA[This topic covers the concepts of the <code>Eval</code> function and <code>Execute</code> statement in depth. The function Eval is used to evaluate a string and return the result of the string expression. The Execute statement on the other hand, executes one or more statements in a string expression and enables creation of dynamic code. Multiple statements can be executed at once by using colons or line breaks to separate them.]]></description>
			<content:encoded><![CDATA[<p></p><p>
This topic covers the concepts of the <code>Eval</code> function and <code>Execute</code> statement in depth. The function Eval is used to evaluate a string and return the result of the string expression. The Execute statement on the other hand, executes one or more statements in a string expression and enables creation of dynamic code. Multiple statements can be executed at once by using colons or line breaks to separate them.
</p>
<p>If you have had a chance to use <a href="http://relevantcodes.com/relevantcodes1one-qtp-automation-framework/">RelevantCodes[1]One</a> and went over the function libraries, you would find that all the events are controlled through <code>Execute</code> statement &#8211; data is retrieved from the Excel Table and parsed by the function libraries into string statements. Once parsed, these string statements are then executed in the same manner as QTP code.
</p>
<h5>Eval Syntax</h5>
<pre>
Eval(expression)
</pre>
<h5>Execute Syntax</h5>
<pre>
Execute statement
</pre>
<h2>Difference between Eval &#038; Execute</h2>
<p>
In the syntax above, both <code>expression</code> and <code>statement</code> arguments are string statements. Both expressions can be derived from VBScript or QTP code; the difference lies in the fact that Eval will always return the result of the string evaluation whereas Execute will execute a string statement for execution and will not retrieve the result (but there are workarounds). The following example demonstrates the main difference between the 2 functions:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">x = 9
y = 10
&nbsp;
bIsEqual = Eval(<span style="color: #800000;">&quot;x = y&quot;</span>)
Execute <span style="color: #800000;">&quot;x = y&quot;</span>
&nbsp;
MsgBox <span style="color: #800000;">&quot;bIsEqual: &quot;</span> &amp; bIsEqual
MsgBox <span style="color: #800000;">&quot;X is no longer 9. It is: &quot;</span> &amp; x</pre></div></div>

<table style='text-align:center; margin-left:auto; margin-right:auto;'>
<tr>
<td><div class="wp-caption alignnone" style="width: 104px">
	<img alt="bIsEqual" src="/Articles/EvalExecute/bIsEqual.png" title="bIsEqual" width="104" height="107" />
	<p class="wp-caption-text">Eval Function</p>
</div></td>
<td><div class="wp-caption alignnone" style="width: 146px">
	<img alt="New x" src="/Articles/EvalExecute/NewX.png" title="New x" width="146" height="107" />
	<p class="wp-caption-text">Execute Statement</p>
</div></td>
</tr>
</table>
<p>
Note that Eval returned a Boolean value whereas Execute function performed a variable assignment. This article will cover the usage of both techniques in depth through both VBS and QTP code.
</p>
<p>
You must be wondering why the syntax for Eval and Execute is different. The reason is that, Eval is a function. Execute is not. That means, the following statement for Eval: <code>bIsEqual = Eval("x = y")</code>, when written for Execute will return a Null value for bResult (but assignment will be performed for <code>x</code>):
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">bResult = Execute(<span style="color: #800000;">&quot;x = y&quot;</span>)
MsgBox bResult
MsgBox <span style="color: #800000;">&quot;x: &quot;</span> &amp; x</pre></div></div>

<table style="margin-left:auto; margin-right:auto; text-align:center;">
<tr>
<td><div class="wp-caption aligncenter" style="width: 104px">
	<img alt="Null Output" src="/Articles/EvalExecute/Null.png" title="Null Output" width="104" height="95" />
	<p class="wp-caption-text">Null Output</p>
</div></td>
<td><div class="wp-caption alignnone" style="width: 104px">
	<img alt="Value Assigned" src="/Articles/EvalExecute/X.png" title="Value Assigned" width="104" height="107" />
	<p class="wp-caption-text">X = 10</p>
</div></td>
</tr>
</table>
<p>
With that said, let me share the workaround that can be used with Execute to return the evaluation just like we did with <code>Eval</code>. Here&#8217;s how:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">x = 9
y = 10
&nbsp;
Execute <span style="color: #800000;">&quot;z = (x = y)&quot;</span>
MsgBox <span style="color: #800000;">&quot;z: &quot;</span> &amp; z</pre></div></div>

<div class="wp-caption aligncenter" style="width: 104px">
	<img alt="Return Z (False)" src="/Articles/EvalExecute/ZFalse.png" title="Return Z (False)" width="104" height="107" />
	<p class="wp-caption-text">Return Z (False)</p>
</div>
<p>
More on this concept will be covered in the section <span class="emphasis_u">Evaluating Statements</span>.
</p>
<h2>Creating Variables</h2>
<p>
Let&#8217;s assume a scenario where you need to create the following variables: <code>var_1</code>, &#8230; , <code>var_5</code>. One way is to manually create the variables:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">var_1 = 1 : var_2 = 2 : var_3 = 3 : var_4 = 4: var_5 = 5</pre></div></div>

<p>
A quicker, and more dynamic way to achieve the same is through Execute statement:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">For</span> ix = 1 <span style="color: #0600FF; font-weight: bold;">to</span> 5
    Execute <span style="color: #800000;">&quot;var_&quot;</span> &amp; ix &amp; <span style="color: #800000;">&quot; = &quot;</span> &amp; ix
<span style="color: #0600FF; font-weight: bold;">Next</span></pre></div></div>

<h2>Option Explicit</h2>
<p>
Using the Execute statement also has a direct impact if the <code>Option Explicit</code> statement is ON. If a variable is not explicitly declared, an error will be occurred:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Option</span> <span style="color: #0600FF; font-weight: bold;">Explicit</span>
&nbsp;
iNumber = 9</pre></div></div>

<p><img alt="" src="/Articles/EvalExecute/OptionExplicit.png" title="Option Explicit" class="aligncenter" width="411" height="172" /></p>
<p>
When the same variable is created through Execute, the error will not occur and the variable will be created and value assigned successfully.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Option</span> <span style="color: #0600FF; font-weight: bold;">Explicit</span>
&nbsp;
Execute <span style="color: #800000;">&quot;iNumber = 9&quot;</span></pre></div></div>

<h2>Evaluating Statements</h2>
<p>
Instead of equating variables and values, we will evaluate statements using Eval. A quick example using <code>IsObject</code> is demonstrated below:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Set</span> dicObject = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>)
&nbsp;
<span style="color: #0600FF; font-weight: bold;">If</span> Eval(<span style="color: #800000;">&quot;IsObject(dicObject)&quot;</span>) <span style="color: #0600FF; font-weight: bold;">Then</span>
    MsgBox <span style="color: #800000;">&quot;Object created.&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">Set</span> dicObject = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span></pre></div></div>

<p>
Similarly, the above code can be broken into a <code>Select Case</code> block and variables can be evaluated by their type:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Sub</span> RetType(<span style="color: #0600FF; font-weight: bold;">ByVal</span> var)
	<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #0600FF; font-weight: bold;">Case</span> Eval(<span style="color: #800000;">&quot;TypeName(var)&quot;</span>)
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;Integer&quot;</span> : MsgBox <span style="color: #800000;">&quot;Integer&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;Dictionary&quot;</span> : MsgBox <span style="color: #800000;">&quot;Dictionary&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;Nothing&quot;</span> : MsgBox <span style="color: #800000;">&quot;Nothing&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;String&quot;</span> : MsgBox <span style="color: #800000;">&quot;String&quot;</span>
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Select</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(<span style="color: #0600FF; font-weight: bold;">Nothing</span>)
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(<span style="color: #800000;">&quot;Test&quot;</span>)
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(<span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>))
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(1)</pre></div></div>

<p>
Upon execution, the following results will be retrieved:
</p>
<table style='text-align:center; margin-left:auto; margin-right:auto;'>
<tr>
<td><div class="wp-caption alignnone" style="width: 104px">
	<img alt="Nothing" src="/Articles/EvalExecute/Nothing.png" title="Nothing" width="104" height="107" />
	<p class="wp-caption-text">RetType(Nothing)</p>
</div></td>
<td><div class="wp-caption alignnone" style="width: 104px">
	<img alt="String" src="/Articles/EvalExecute/String.png" title="String" width="104" height="107" />
	<p class="wp-caption-text">RetType('Test')</p>
</div></td>
<td><div class="wp-caption alignnone" style="width: 104px">
	<img alt="Dictionary" src="/Articles/EvalExecute/Dict.png" title="Dictionary" width="104" height="107" />
	<p class="wp-caption-text">RetType(CreateObject)</p>
</div></td>
<td><div class="wp-caption alignnone" style="width: 104px">
	<img alt="Integer" src="/Articles/EvalExecute/Integer.png" title="Integer" width="104" height="107" />
	<p class="wp-caption-text">RetType(1)</p>
</div></td>
</tr>
</table>
<p>
The same function above can be written through Execute. However, with Execute, we cannot directly retrieve the result (it is not a function, unlike Eval). Therefore, we will create a variable and store the result with the variable; the variable will then be used as the <code>Select Case</code> condition.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Sub</span> RetType(<span style="color: #0600FF; font-weight: bold;">ByVal</span> var)
	<span style="color: #0600FF; font-weight: bold;">Dim</span> bResult
&nbsp;
	Execute <span style="color: #800000;">&quot;bResult = TypeName(var)&quot;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">Select</span> <span style="color: #0600FF; font-weight: bold;">Case</span> bResult
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;Integer&quot;</span> : MsgBox <span style="color: #800000;">&quot;Integer&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;Dictionary&quot;</span> : MsgBox <span style="color: #800000;">&quot;Dictionary&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;Nothing&quot;</span> : MsgBox <span style="color: #800000;">&quot;Nothing&quot;</span>
		<span style="color: #0600FF; font-weight: bold;">Case</span> <span style="color: #800000;">&quot;String&quot;</span> : MsgBox <span style="color: #800000;">&quot;String&quot;</span>
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Select</span>
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(<span style="color: #0600FF; font-weight: bold;">Nothing</span>)
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(<span style="color: #800000;">&quot;Test&quot;</span>)
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(<span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>))
<span style="color: #0600FF; font-weight: bold;">Call</span> RetType(1)</pre></div></div>

<p>
In short then, with Execute, bResult is represented within the string statement:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Execute <span style="color: #800000;">&quot;bResult = TypeName(var)&quot;</span></pre></div></div>

<p>
With Eval, bResult is an actual variable that holds the result like below:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">bResult = Eval(<span style="color: #800000;">&quot;TypeName(var)&quot;</span>)</pre></div></div>

<h2>Creating Functions</h2>
<p>
I have seen this approach rarely used, but its important to know all the possibilities nonetheless. Yes, we can create Functions (really!) at run-time, as long as everything is a string and new lines are separated by colons or a line feed. This approach is generally fine for small functions, but it can get really confusing and hard to debug as the lines of code increase.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">sFunc = <span style="color: #800000;">&quot;Function ExecuteTest&quot;</span>
sFunc = sFunc &amp; vbLf
sFunc = sFunc &amp; <span style="color: #800000;">&quot;MsgBox &quot;</span><span style="color: #800000;">&quot;ExecuteTest executed.&quot;</span><span style="color: #800000;">&quot;&quot;</span>
sFunc = sFunc &amp; vbLf
sFunc = sFunc &amp; <span style="color: #800000;">&quot;End Function&quot;</span>
&nbsp;
Execute sFunc
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Call</span> ExecuteTest()</pre></div></div>

<p><img alt="" src="/Articles/EvalExecute/ExecuteTest.png" title="Execute Test output" class="aligncenter" width="140" height="107" /></p>
<p>
We can write the same code above using colons (<code>:</code>) as well:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Execute <span style="color: #800000;">&quot;Function ExecuteTest : MsgBox &quot;</span><span style="color: #800000;">&quot;ExecuteTest executed.&quot;</span><span style="color: #800000;">&quot; : End Function&quot;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Call</span> ExecuteTest()</pre></div></div>

<h2>Executing QTP Statements</h2>
<p>
This is where the Execute statement absolutely shines. As stated before, <a href="http://relevantcodes.com/relevantcodes1one-qtp-automation-framework/">RelevantCodes[1]One</a> executes all keywords through Execute statement. It retrieves keywords from the Excel Table as strings at runtime, creates the relevant hierarchies, and executes the hierarchies with chosen events. The concept here and the concepts covered by previous examples will remain the same: we create action strings and execute them. The last example in this topic will show how different strings can be joined together to implement events on supplied test-objects (as strings).
</p>
<p>
Let&#8217;s start with a quick example to check if our target browser exists:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">strBrowser = <span style="color: #800000;">&quot;Browser(&quot;</span><span style="color: #800000;">&quot;title:=Google&quot;</span><span style="color: #800000;">&quot;)&quot;</span>
&nbsp;
Execute <span style="color: #800000;">&quot;MsgBox &quot;</span> &amp; strBrowser &amp; <span style="color: #800000;">&quot;.Exist(0)&quot;</span></pre></div></div>

<p>
The above code can also be written with Eval as well, enabling us to retrieve the value directly instead of using the workaround approach if we were to use Execute:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">strBrowser = <span style="color: #800000;">&quot;Browser(&quot;</span><span style="color: #800000;">&quot;title:=Google&quot;</span><span style="color: #800000;">&quot;)&quot;</span>
&nbsp;
bExist = Eval(strBrowser &amp; <span style="color: #800000;">&quot;.Exist(0)&quot;</span>)</pre></div></div>

<p>
The above statement when executed does the same operation as it would when you would verify the browser existence using an inline DP statement: <code>Msgbox Browser("title:=Google").Exist(0)</code>. Let&#8217;s consider another example where we create an event on a WebEdit object by creating an object hierarchy through strings at run time.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">strBrowser = <span style="color: #800000;">&quot;Browser(&quot;</span><span style="color: #800000;">&quot;title:=Google&quot;</span><span style="color: #800000;">&quot;)&quot;</span>  <span style="color: #008000;">'Browser(&quot;title:=Google&quot;)
</span>strPage    = <span style="color: #800000;">&quot;Page(&quot;</span><span style="color: #800000;">&quot;title:=Google&quot;</span><span style="color: #800000;">&quot;)&quot;</span>     <span style="color: #008000;">'Page(&quot;title:=Google&quot;)
</span>strText    = <span style="color: #800000;">&quot;WebEdit(&quot;</span><span style="color: #800000;">&quot;name:=q&quot;</span><span style="color: #800000;">&quot;)&quot;</span>        <span style="color: #008000;">'WebEdit(&quot;name:=q&quot;)
</span>strEvent   = <span style="color: #800000;">&quot;Set &quot;</span><span style="color: #800000;">&quot;Execute Test&quot;</span><span style="color: #800000;">&quot;&quot;</span>        <span style="color: #008000;">'Set &quot;Execute Test&quot;
</span>
Execute strBrowser &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strPage &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strText &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strEvent</pre></div></div>

<p>
It does look interesting, doesn&#8217;t it? The same approach can be used if you are using Object Repository instead of Descriptive Programming; simply replace the Programmatic Descriptions with the Logical Descriptions in your OR, parse everything in a string and Execute it!
</p>
<p>
The example below shows how QTP code can be executed into succession through strings. The last 4 statements show how all strings are combined together to 1. Enter the search terms, 2. Click Search Button, 3. Synchronize and 4. Navigate back to the Google search page.
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">strBrowser = <span style="color: #800000;">&quot;Browser(&quot;</span><span style="color: #800000;">&quot;title:=.*Google.*&quot;</span><span style="color: #800000;">&quot;)&quot;</span>      <span style="color: #008000;">'Browser(&quot;title:=Google&quot;)
</span>strPage    = <span style="color: #800000;">&quot;Page(&quot;</span><span style="color: #800000;">&quot;title:=.*Google.*&quot;</span><span style="color: #800000;">&quot;)&quot;</span>         <span style="color: #008000;">'Page(&quot;title:=Google&quot;)
</span>strText    = <span style="color: #800000;">&quot;WebEdit(&quot;</span><span style="color: #800000;">&quot;name:=q&quot;</span><span style="color: #800000;">&quot;)&quot;</span>                <span style="color: #008000;">'WebEdit(&quot;name:=q&quot;)
</span>strButton  = <span style="color: #800000;">&quot;WebButton(&quot;</span><span style="color: #800000;">&quot;value:=Google Search&quot;</span><span style="color: #800000;">&quot;)&quot;</span> <span style="color: #008000;">'WebButton(&quot;value:=Google Search&quot;)
</span>strEvent   = <span style="color: #800000;">&quot;Set &quot;</span><span style="color: #800000;">&quot;Execute Test&quot;</span><span style="color: #800000;">&quot;&quot;</span>                <span style="color: #008000;">'Set &quot;Execute Test&quot;
</span>strClick   = <span style="color: #800000;">&quot;Click&quot;</span>                               <span style="color: #008000;">'Click
</span>strSync    = <span style="color: #800000;">&quot;Sync&quot;</span>                                <span style="color: #008000;">'Sync
</span>strBack    = <span style="color: #800000;">&quot;Back&quot;</span>                                <span style="color: #008000;">'Back
</span>
Execute strBrowser &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strPage &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strText &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strEvent
Execute strBrowser &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strPage &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strButton &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strClick
Execute strBrowser &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strSync
Execute strBrowser &amp; <span style="color: #800000;">&quot;.&quot;</span> &amp; strBack</pre></div></div>

<p>
The above strings are equivalent to the following QTP code:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">Browser(<span style="color: #800000;">&quot;title:=.*Google.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=.*Google.*&quot;</span>).WebEdit(<span style="color: #800000;">&quot;name:=q&quot;</span>).<span style="color: #0600FF; font-weight: bold;">Set</span> <span style="color: #800000;">&quot;Execute Test&quot;</span>
Browser(<span style="color: #800000;">&quot;title:=.*Google.*&quot;</span>).Page(<span style="color: #800000;">&quot;title:=.*Google.*&quot;</span>).WebButton(<span style="color: #800000;">&quot;value:=Google Search&quot;</span>).Click
Browser(<span style="color: #800000;">&quot;title:=.*Google.*&quot;</span>).Sync
Browser(<span style="color: #800000;">&quot;title:=.*Google.*&quot;</span>).Back</pre></div></div>

<h2>Closing Remarks</h2>
<p>
I hope this article has covered most of the common (and uncommon) uses of Eval and Execute. I&#8217;m sure you&#8217;ll find areas in your framework where these 2 techniques will make things cleaner and more dynamic. If there is something I have omitted, please feel free to share it with us. I hope you guys find this article useful :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/eval-function-execute-statement/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
		<item>
		<title>VBScript: Compare 2 Excel Files</title>
		<link>http://relevantcodes.com/vbscript-compare-2-excel-files/</link>
		<comments>http://relevantcodes.com/vbscript-compare-2-excel-files/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 18:31:29 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Check Differences Between Excel Sheets]]></category>
		<category><![CDATA[Compare]]></category>
		<category><![CDATA[Compare 2 Excel Sheets]]></category>
		<category><![CDATA[Compare Excel]]></category>
		<category><![CDATA[Compare Excel Books]]></category>
		<category><![CDATA[Compare Two Excel Sheets]]></category>
		<category><![CDATA[Excel.Application]]></category>
		<category><![CDATA[VBScript Excel]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=3215</guid>
		<description><![CDATA[This post shows a quick and easy way to compare 2 Excel files. I know there are several code snippets on the inter-webs that show how to compare 2 Excel files, but what makes this technique different is performance. I know faster techniques are possible, but after much experiment, this was the one that continuously worked at the best speed in comparison to other methods.]]></description>
			<content:encoded><![CDATA[<p></p><p>
This post shows a quick and easy way to compare 2 Excel files. I know there are several code snippets on forums that show how to compare do this, so you may ask the following question: how is this technique any different? What makes this technique different is performance. I know there may be faster ways to achieve this, but after much experiment, this was the one that continuously worked at the best speed in comparison to other methods.
</p>
<p>
The main concept of this technique is performing all validations through a <code>range object</code>, instead of traversing all cells of an Excel sheet (which takes a little longer). Below is the skeleton of how the class is arranged, with documentation. Please use one of the download links above to download this class. There is a usage example shown at the end of this article.
</p>
<h5>Class clsExcelComparer</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #6666CC; font-weight: bold;">Class</span> clsComparer
	<span style="color: #008000;">'[--- Region Private Variables Start ---]
</span>
	<span style="color: #0600FF; font-weight: bold;">Private</span> oExcel		<span style="color: #008000;">'Excel.Application
</span>	<span style="color: #0600FF; font-weight: bold;">Private</span> arrRangeUno	<span style="color: #008000;">'Range.Value (array) of the Primary Excel spreadsheet
</span>	<span style="color: #0600FF; font-weight: bold;">Private</span> arrRangeDos	<span style="color: #008000;">'Range.Value (array) of the Secondary Excecl spreadsheet
</span>	<span style="color: #0600FF; font-weight: bold;">Private</span> oDict		<span style="color: #008000;">'Scripting.Dictionary containing unmatched cells
</span>
	<span style="color: #008000;">'[--- Region Private Variables End ---]
</span>
&nbsp;
	<span style="color: #008000;">'[--- Region Public Variables Start ---]
</span>
	<span style="color: #0600FF; font-weight: bold;">Public</span> Operation	<span style="color: #008000;">'0: Only Compare   1: Compare &amp; Highlight Differences
</span>
	<span style="color: #008000;">'[--- Region Public Variables End ---]
</span>
&nbsp;
	<span style="color: #008000;">'--------------------------------------------------------
</span>	<span style="color: #008000;">' Name: Function Compare [Public]
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Remarks: N/A
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Purpose: Compares differences between 2 Excel Spreadsheets
</span>	<span style="color: #008000;">'	
</span>	<span style="color: #008000;">' Arguments:
</span>	<span style="color: #008000;">'	sWorkBookUno: Primary Excel WorkBook (with complete path)
</span>	<span style="color: #008000;">'	vSheetUno: Primary Excel Spreadsheet Name
</span>	<span style="color: #008000;">'	sWorkBookDos: Secondary Excel WorkBook (with complete path)
</span>	<span style="color: #008000;">'	vSheetDos: Secondary Excel Spreadsheet Name
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Return: Boolean
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Author: Anshoo Arora, Relevant Codes
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Date: 03/17/2010
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' References: N/A
</span>	<span style="color: #008000;">'--------------------------------------------------------
</span>	<span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Function</span> <span style="color: #0600FF; font-weight: bold;">Compare</span>(sWorkBookUno, vSheetUno, sWorkBookDos, vSheetDos)
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
	<span style="color: #008000;">'--------------------------------------------------------
</span>	<span style="color: #008000;">' Name: Function CellsFound [Private]
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Remarks: N/A
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Purpose: Finds the dissimilar cells between 2 sheets
</span>	<span style="color: #008000;">'	
</span>	<span style="color: #008000;">' Arguments: N/a
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Return: Integer
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Author: Anshoo Arora, Relevant Codes
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Date: 03/17/2010
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' References: N/A
</span>	<span style="color: #008000;">'--------------------------------------------------------
</span>	<span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Function</span> CellsFound()
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
	<span style="color: #008000;">'--------------------------------------------------------
</span>	<span style="color: #008000;">' Name: Sub Class_Terminate [Private]
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Remarks: N/A
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Purpose: Disposes the Excel.Application object
</span>	<span style="color: #008000;">'	
</span>	<span style="color: #008000;">' Arguments: N/A
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Author: Anshoo Arora, Relevant Codes
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' Date: 03/17/2010
</span>	<span style="color: #008000;">'
</span>	<span style="color: #008000;">' References: N/A
</span>	<span style="color: #008000;">'--------------------------------------------------------
</span>	<span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Terminate</span>()
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span>
&nbsp;
<span style="color: #008000;">'--------------------------------------------------------
</span><span style="color: #008000;">' Name: Function CompareExcelSheets
</span><span style="color: #008000;">'
</span><span style="color: #008000;">' Remarks: N/A
</span><span style="color: #008000;">'
</span><span style="color: #008000;">' Purpose: Constructor for Class clsComparer
</span><span style="color: #008000;">'	
</span><span style="color: #008000;">' Arguments:
</span><span style="color: #008000;">'	sWorkBookUno: Primary Excel WorkBook (with complete path)
</span><span style="color: #008000;">'	vSheetUno: Primary Excel Spreadsheet Name
</span><span style="color: #008000;">'	sWorkBookDos: Secondary Excel WorkBook (with complete path)
</span><span style="color: #008000;">'	vSheetDos: Secondary Excel Spreadsheet Name
</span><span style="color: #008000;">'	Operation: 0: Compare Only   1: Compare &amp; Highlight Differences
</span><span style="color: #008000;">'
</span><span style="color: #008000;">' Return: Boolean
</span><span style="color: #008000;">'
</span><span style="color: #008000;">' Author: Anshoo Arora, Relevant Codes
</span><span style="color: #008000;">'
</span><span style="color: #008000;">' Date: 03/17/2010
</span><span style="color: #008000;">'
</span><span style="color: #008000;">' References: N/A
</span><span style="color: #008000;">'--------------------------------------------------------
</span><span style="color: #0600FF; font-weight: bold;">Function</span> CompareExcelSheets(sWorkBookUno, vSheetUno, sWorkBookDos, vSheetDos, Operation)
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span></pre></div></div>

<p class="th-box download centeralign"><a class="downloadlink" href="http://relevantcodes.com/wp-content/plugins/download-monitor/download.php?id=4" title="Version1.0 downloaded 771 times" >Download clsComparer (771)</a> | <a class="downloadlink" href="http://relevantcodes.com/wp-content/plugins/download-monitor/download.php?id=5" title="Version1.0 downloaded 722 times" >View clsComparer (722)</a></p>
<h2>Usage (Example)</h2>
<p>
Consider the following 2 Excel Sheets, with a few dissimilar cells:
</p>
<p><div class="wp-caption aligncenter" style="width: 585px">
	<img alt="Sheet #1 Original" src="http://relevantcodes.com/Articles/CompareExcelSheets/SheetUno.png" title="Sheet #1 Original" width="585" height="120" />
	<p class="wp-caption-text">Sheet #1 Original</p>
</div>  <div class="wp-caption aligncenter" style="width: 585px">
	<img alt="Sheet #2 Original" src="http://relevantcodes.com/Articles/CompareExcelSheets/SheetDos.png" title="Sheet #2 Original" width="585" height="120" />
	<p class="wp-caption-text">Sheet #2 Original</p>
</div></p>
<p>
There are 2 main operations that can be done through our code. <code>1.</code> We can simply check if both Excel Sheets are similar and <code>2.</code> we can check as well as highlight the differences between the two. To only compare the 2 sheets, without highlighting the differences the <code>Operation</code> argument will have a value of <code>0</code>. On the other hand, to compare as well as highlight the values, the <code>Operation</code> argument will have a value of <code>1</code>. Let&#8217;s first consider a case where the 2 sheets are only to be compared:
</p>
<h5>Compare Only</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Only Compare:
</span>MsgBox CompareExcelSheets(<span style="color: #800000;">&quot;C:\Test1.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>, <span style="color: #800000;">&quot;C:\Test2.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>, 0)</pre></div></div>

<p>
Because the 2 sheets are not similar, the following will be the output upon execution of the above statement:
</p>
<div class="wp-caption aligncenter" style="width: 107px">
	<img alt="Compare Only" src="http://relevantcodes.com/Articles/CompareExcelSheets/CompareOnly.png" title="Compare Only" width="107" height="109" />
	<p class="wp-caption-text">Compare Only</p>
</div>
<p>
Also, the 2 sheets will remain unchanged.
</p>
<p>
When changing the value of <code>Operation</code> to 1, we will notice that, not only does the code compare the 2 sheets, but also highlights the differences.
</p>
<h5>Compare and Highlight Differences</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'Compare and highlight differences:
</span>MsgBox CompareExcelSheets(<span style="color: #800000;">&quot;C:\Test1.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>, <span style="color: #800000;">&quot;C:\Test2.xls&quot;</span>, <span style="color: #800000;">&quot;Sheet1&quot;</span>, 1)</pre></div></div>

<p>
Upon execution of the above statement, the following 2 sheets will be highlighed in areas where they differ:
</p>
<p><div class="wp-caption aligncenter" style="width: 584px">
	<img alt="Sheet #1 With Highlighted Differences" src="http://relevantcodes.com/Articles/CompareExcelSheets/SheetUnoHighlighted.png" title="Sheet #1 With Highlighted Differences" width="584" height="121" />
	<p class="wp-caption-text">Sheet #1 With Highlighted Differences</p>
</div>  <div class="wp-caption aligncenter" style="width: 585px">
	<img alt="Sheet #2 with Highlighted Differences" src="http://relevantcodes.com/Articles/CompareExcelSheets/SheetDosHighlighted.png" title="Sheet #2 with Highlighted Differences" width="585" height="120" />
	<p class="wp-caption-text">Sheet #2 with Highlighted Differences</p>
</div></p>
<h2>Limitations</h2>
<p>
1. This code will work with Excel Sheets with the same number of rows and columns in each (like ranges).
</p>
<h2>Update: RelevantCodes.Comparer COM DLL</h2>
<p></p>
<p class="th-box download centeralign">
<a href="http://relevantcodes.com/Articles/RelevantCodes.Comparer/RelevantCodes.zip" rel="nofollow">Download RelevantCodes.Comparer</a>
</p>
<p>
Snapshot of the assembly can be found <a href="http://relevantcodes.com/Articles/RelevantCodes.Comparer/RelevantCodes.Comparer.png" rel="nofollow">here</a>.
</p>
<p>
To register the assembly to your PC, the following code can be used:
</p>
<pre>
RegAsm C:\RelevantCodes.dll /codebase
</pre>
<p>
or
</p>
<pre>
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe C:\RelevantCodes.dll /codebase
</pre>
<p>
Once done, the code can be used in QTP like this:
</p>
<pre>
Set oCompare = CreateObject("RelevantCodes.Comparer")
</pre>
<p>
<code>oCompare.</code> should give you the proper intellisense to use all methods. The assembly compares the following items:</p>
<ol>
<li>Arrays</li>
<li>Excel Sheets</li>
<li>Images</li>
<li>Integers</li>
<li>Strings</li>
<li>TextFiles</li>
</ol>
<p>
I hope you find this useful :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/vbscript-compare-2-excel-files/feed/</wfw:commentRss>
		<slash:comments>75</slash:comments>
		</item>
		<item>
		<title>CDO: Send Email from Yahoo, Hotmail, Live, AOL or GMail</title>
		<link>http://relevantcodes.com/cdo-send-email-from-yahoo-hotmail-live-aol-or-gmail/</link>
		<comments>http://relevantcodes.com/cdo-send-email-from-yahoo-hotmail-live-aol-or-gmail/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 21:52:09 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[CDO]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[Email QTP]]></category>
		<category><![CDATA[QTP AOL]]></category>
		<category><![CDATA[QTP Check Email]]></category>
		<category><![CDATA[QTP Email]]></category>
		<category><![CDATA[QTP GMail]]></category>
		<category><![CDATA[QTP Hotmail]]></category>
		<category><![CDATA[QTP Live]]></category>
		<category><![CDATA[QTP Yahoo]]></category>
		<category><![CDATA[Send Email]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=97</guid>
		<description><![CDATA[This article discusses 2 ways of sending e-mail from your Yahoo, Hotmail, Gmail, Live or AOL e-mail accounts using the ‘clsSendMail’ class:
]]></description>
			<content:encoded><![CDATA[<p></p><p>This article discusses 2 ways of sending e-mail from your Yahoo, Hotmail, Gmail, Live or AOL e-mail accounts using the &#8216;EmailSender&#8217; class:</p>
<ol>
<li>Calling the Method with the Body Message</li>
<li>Retrieve body-messages from text files</li>
</ol>
<p>This can be quite handy during regression cycles &#8211; you can use this code to send yourself an e-mail whenever a step in the test process fails. You can even keep a count of the number of times this procedure executes in your script and even <a href="http://abouttesting.blogspot.com/2009/03/test-framework-stop-if-too-many-errors.html">stop your test if too many steps fail</a>.</p>
<h2>Calling the Method with the Body Message</h2>
<p>The code snippets below shows the syntax to send an HTML and plain text e-mails:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'TEXT
</span>SendMail <span style="color: #800000;">&quot;myEmailID@AOL.com&quot;</span>, <span style="color: #800000;">&quot;myPassword&quot;</span>, <span style="color: #800000;">&quot;recipient@Gmail.com&quot;</span>, _
        <span style="color: #800000;">&quot;&quot;</span>, <span style="color: #800000;">&quot;Subject&quot;</span>, <span style="color: #800000;">&quot;Hello, this is a test mail.&quot;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">'HTML
</span>SendMail <span style="color: #800000;">&quot;myEmailID@AOL.com&quot;</span>, <span style="color: #800000;">&quot;myPassword&quot;</span>, <span style="color: #800000;">&quot;recipient@Gmail.com&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, _
        <span style="color: #800000;">&quot;Subject&quot;</span>, <span style="color: #800000;">&quot;&lt;h1&gt;Hello&lt;/h1&gt;&lt;p&gt;Test Mail&lt;/p&gt;&quot;</span></pre></div></div>

<h2>Retrieve body-messages from text files</h2>
<p>
You can create a text file with the body message, and use the file path in the method to send the e-mail. Below is an example of an HTML body inserted into a text file:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">SendMailFromFile <span style="color: #800000;">&quot;myEmailID@AOL.com&quot;</span>, <span style="color: #800000;">&quot;myPassword&quot;</span>, <span style="color: #800000;">&quot;recipient@Gmail.com&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>, _
        <span style="color: #800000;">&quot;Subject&quot;</span>, <span style="color: #800000;">&quot;C:\MyTestMail.txt&quot;</span></pre></div></div>

<div class="wp-caption aligncenter" style="width: 533px">
	<a href="http://www.relevantcodes.com/Articles/CDO/MyTestMail.jpg"><img alt="Sample Text File" src="http://www.relevantcodes.com/Articles/CDO/MyTestMail.jpg" title="Sample Text File" width="533" height="120" /></a>
	<p class="wp-caption-text">Sample Text File</p>
</div>
<p>Similarly, mails can be sent to multiple recipients using &#8220;;&#8221; between Recipient&#8217;s emails. Example:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;">SendMail <span style="color: #800000;">&quot;myEmailID@AOL.com&quot;</span>, <span style="color: #800000;">&quot;myPassword&quot;</span>, <span style="color: #800000;">&quot;recipient1@Gmail.com;recipient2@Yahoo.Com&quot;</span>, _
    <span style="color: #800000;">&quot;CC@YouCC.Com;CC@MeCC.Com&quot;</span>, <span style="color: #800000;">&quot;Test Subject&quot;</span>, <span style="color: #800000;">&quot;Test Message&quot;</span></pre></div></div>

<p>You can find the download links to this class towards the end of this post.</p>
<h5>Code: Class SendMail</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #6666CC; font-weight: bold;">Class</span> EmailSender
&nbsp;
<span style="color: #008000;">'#region Public Variables
</span>
    <span style="color: #0600FF; font-weight: bold;">Public</span> Body  <span style="color: #008000;">'Message body
</span>    <span style="color: #0600FF; font-weight: bold;">Public</span> From  <span style="color: #008000;">'Sender's EmailID
</span>
&nbsp;
<span style="color: #008000;">'#region Private Variables
</span>
    <span style="color: #0600FF; font-weight: bold;">Private</span> CDOMessage  <span style="color: #008000;">'CDO.Message Object
</span>    <span style="color: #0600FF; font-weight: bold;">Private</span> strFrom     <span style="color: #008000;">'Sender's Email ID: XX@YY.COM
</span>    
&nbsp;
<span style="color: #008000;">'#region Public Methods
</span>    
    <span style="color: #008000;">' Purpose: Send Email Using CDO
</span>    <span style="color: #008000;">' Args:
</span>    <span style="color: #008000;">'    sEmailID: Sender's Mail ID String
</span>    <span style="color: #008000;">'    sPassword: Sender's Password String
</span>    <span style="color: #008000;">'    sTo: Recipient's Mail ID String (Primary)
</span>    <span style="color: #008000;">'    sCC: Recipient's Mail ID String (CC)
</span>    <span style="color: #008000;">'    sSubject: Subject String
</span>    <span style="color: #008000;">'    sBody: Body Message String
</span>    <span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> Send(sEMailID, sPassword, sTo, sCC, sSubject, sBody)
        <span style="color: #0600FF; font-weight: bold;">Dim</span> oRegExp     <span style="color: #008000;">'RegEx Object
</span>        <span style="color: #0600FF; font-weight: bold;">Dim</span> sDetails    <span style="color: #008000;">'Report Details
</span>        <span style="color: #0600FF; font-weight: bold;">Dim</span> intStatus   <span style="color: #008000;">'Report Status
</span>        <span style="color: #0600FF; font-weight: bold;">Dim</span> sStepName   <span style="color: #008000;">'Report Step
</span>
        Me.From = sEmailID
        intStatus = micPass
        sStepName = <span style="color: #800000;">&quot; Sent&quot;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Set</span> oRegExp = <span style="color: #0600FF; font-weight: bold;">New</span> RegExp
        oRegExp.Global = <span style="color: #0600FF; font-weight: bold;">True</span>
        oRegExp.Pattern = <span style="color: #800000;">&quot;&lt;\w&gt;|&lt;\w\w&gt;|&lt;\w\d&gt;&quot;</span>
        <span style="color: #0600FF; font-weight: bold;">Set</span> oMatches = oRegExp.Execute( Me.Body )
&nbsp;
        <span style="color: #008000;">'Build Message
</span>        <span style="color: #0600FF; font-weight: bold;">With</span> CDOMessage
            .Subject = sSubject
            .From = sEmailID
            .<span style="color: #0600FF; font-weight: bold;">To</span> = sTo
            .CC = sCC
            <span style="color: #008000;">'.BCC = sBCC  'BCC Property can be added as well
</span>            
            <span style="color: #008000;">'If HTML Tags found, use .HTMLBody
</span>            <span style="color: #0600FF; font-weight: bold;">If</span> oMatches.Count &gt; 0 <span style="color: #0600FF; font-weight: bold;">Then</span>
                .HTMLBody = Me.Body
            <span style="color: #0600FF; font-weight: bold;">Else</span>
                .TextBody = Me.Body
            <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">With</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Set</span> oMatches = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
        <span style="color: #0600FF; font-weight: bold;">Set</span> oRegExp = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">With</span> CDOMessage.Configuration.Fields
            <span style="color: #008000;">'Sender's Mail ID
</span>            .Item(<span style="color: #800000;">&quot;http://schemas.microsoft.com/cdo/configuration/&quot;</span> &amp;_
            <span style="color: #800000;">&quot;sendusername&quot;</span>) = sEmailID
            <span style="color: #008000;">'Sender's Password
</span>            .Item(<span style="color: #800000;">&quot;http://schemas.microsoft.com/cdo/configuration/&quot;</span> &amp;_
            <span style="color: #800000;">&quot;sendpassword&quot;</span>) = sPassword
            <span style="color: #008000;">'Name/IP of SMTP Server
</span>            .Item(<span style="color: #800000;">&quot;http://schemas.microsoft.com/cdo/configuration/&quot;</span> &amp;_
            <span style="color: #800000;">&quot;smtpserver&quot;</span>) = cdoSMTPServer
            <span style="color: #008000;">'Server Port
</span>            .Item(<span style="color: #800000;">&quot;http://schemas.microsoft.com/cdo/configuration/&quot;</span> &amp;_
            <span style="color: #800000;">&quot;smtpserverport&quot;</span>) = cdoOutgoingMailSMTP
            <span style="color: #008000;">'Send Using: (1) Local SMTP Pickup Service (2) Use SMTP Over Network
</span>            .Item(<span style="color: #800000;">&quot;http://schemas.microsoft.com/cdo/configuration/&quot;</span> &amp;_
            <span style="color: #800000;">&quot;sendusing&quot;</span>) = cdoSendUsing
            <span style="color: #008000;">'Authentication Used: (1) None (2) Basic (3) NTLM
</span>            .Item(<span style="color: #800000;">&quot;http://schemas.microsoft.com/cdo/configuration/&quot;</span> &amp;_
            <span style="color: #800000;">&quot;smtpauthenticate&quot;</span>) = cdoAuthenticationType
            <span style="color: #008000;">'SMTP Server Requires SSL/STARTTLS: Boolean
</span>            .Item(<span style="color: #800000;">&quot;http://schemas.microsoft.com/cdo/configuration/&quot;</span> &amp;_
            <span style="color: #800000;">&quot;smtpusessl&quot;</span>) = cdoUseSSL
            <span style="color: #008000;">'Maximum Time in Seconds CDO will try to Establish Connection
</span>            .Item(<span style="color: #800000;">&quot;http://schemas.microsoft.com/cdo/configuration/&quot;</span> &amp;_
            <span style="color: #800000;">&quot;smtpconnectiontimeout&quot;</span>) = cdoTimeout
            <span style="color: #008000;">'Update Configuration Entries
</span>            .Update
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">With</span>
&nbsp;
        <span style="color: #008000;">'Report Details
</span>        sDetails = <span style="color: #800000;">&quot;SMTP Server: &quot;</span> &amp; cdoSMTPServer &amp; vbLf
        sDetails = sDetails &amp; <span style="color: #800000;">&quot;Sender: &quot;</span> &amp; sEMailID &amp; vbLf
        sDetails = sDetails &amp; <span style="color: #800000;">&quot;Recipient: &quot;</span> &amp; sTo &amp; vbLf
        sDetails = sDetails &amp; <span style="color: #800000;">&quot;Server Port: &quot;</span> &amp; cdoOutgoingMailSMTP &amp; vbLf
        sDetails = sDetails &amp; <span style="color: #800000;">&quot;SSL Used: &quot;</span> &amp; cdoUseSSL &amp; vbLf
        sDetails = sDetails &amp; <span style="color: #800000;">&quot;Authentication Type: &quot;</span> &amp; cdoAuthenticationType &amp; vbLf
        sDetails = sDetails &amp; <span style="color: #800000;">&quot;SMTP Service Type: &quot;</span> &amp; cdoSendUsing &amp; vbLf &amp; vbLf
        sDetails = sDetails &amp; <span style="color: #800000;">&quot;Subject: &quot;</span> &amp; sSubject &amp; vbLf &amp; vbLf
        sDetails = sDetails &amp; <span style="color: #800000;">&quot;Body: &quot;</span> &amp; sBody
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Resume</span> <span style="color: #0600FF; font-weight: bold;">Next</span>
            CDOMessage.Send  <span style="color: #008000;">'Send Message
</span>            
            <span style="color: #0600FF; font-weight: bold;">If</span> Err.Number &lt;&gt; 0 <span style="color: #0600FF; font-weight: bold;">Then</span>
                intStatus = micFail
                sStepName = <span style="color: #800000;">&quot; Not Sent&quot;</span>
                sDetails = sDetails &amp; vbLf &amp; <span style="color: #800000;">&quot;Error Description: &quot;</span> &amp; Err.Description
            <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
        <span style="color: #0600FF; font-weight: bold;">On</span> <span style="color: #0600FF; font-weight: bold;">Error</span> <span style="color: #0600FF; font-weight: bold;">Goto</span> 0
&nbsp;
        <span style="color: #008000;">'If you're not using QTP, please disable the statement below:
</span>        Reporter.ReportEvent intStatus, <span style="color: #800000;">&quot;EMail&quot;</span> &amp; sStepName, sDetails
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #008000;">' Purpose: Loads BodyText from a Text File
</span>    <span style="color: #008000;">' Args:
</span>    <span style="color: #008000;">'    sCompleteFilePath: Complete Path to the Text File (Eg: &quot;C:\MyDocs\MyMail.txt&quot;)
</span>    <span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Let</span> LoadBodyMessage( sCompleteFilePath ) <span style="color: #008000;">'ReadOnly Property LoadBodyMessage
</span>        CONST ForReading = 1 
        <span style="color: #0600FF; font-weight: bold;">Dim</span> oFSO, oFile
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Set</span> oFSO = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>( <span style="color: #800000;">&quot;Scripting.FileSystemObject&quot;</span> )
        <span style="color: #0600FF; font-weight: bold;">Set</span> oFile = oFSO.OpenTextFile( sCompleteFilePath, ForReading )
        Me.Body = oFile.ReadAll
        oFile.<span style="color: #0600FF; font-weight: bold;">Close</span>: <span style="color: #0600FF; font-weight: bold;">Set</span> oFile = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">Set</span> oFSO = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
&nbsp;
&nbsp;
<span style="color: #008000;">'#region Private Gets
</span>
    <span style="color: #008000;">' Purpose: Readonly property configuration for SMTP Service'
</span>    <span style="color: #008000;">' Return: Integer
</span>    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Get</span> CDOSendUsing  <span style="color: #008000;">'As Integer
</span>        CDOSendUsing = 2    <span style="color: #008000;">'Use SMTP Over The Network
</span>        <span style="color: #008000;">'CDOSendUsing = 1    'Use Local SMTP Service Pickup Directory
</span>    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
&nbsp;
    <span style="color: #008000;">' Purpose: Maximum time in seconds CDO will try to establish a connection
</span>    <span style="color: #008000;">' Return: Integer
</span>    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Get</span> CDOTimeout  <span style="color: #008000;">'As Integer
</span>        <span style="color: #008000;">'CDOTimeout = 15    'Seconds
</span>        CDOTimeout = 45    <span style="color: #008000;">'Seconds
</span>        <span style="color: #008000;">'CDOTimeout = 75    'Seconds
</span>    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
&nbsp;
    <span style="color: #008000;">' Purpose: Type of Authentication to be used
</span>    <span style="color: #008000;">' Return: Integer
</span>    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Get</span> CDOAuthenticationType  <span style="color: #008000;">'As Integer
</span>        <span style="color: #008000;">'CDOAuthenticationType = 0    'No Authentication
</span>        CDOAuthenticationType = 1    <span style="color: #008000;">'Basic Authentication
</span>        <span style="color: #008000;">'CDOAuthenticationType = 2    'NTML Authentication
</span>    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
&nbsp;
    <span style="color: #008000;">' Purpose: Server Port
</span>    <span style="color: #008000;">' Return: Integer
</span>    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Get</span> CDOOutgoingMailSMTP  <span style="color: #008000;">'As Integer
</span>        <span style="color: #0600FF; font-weight: bold;">If</span> InStr(1, Lcase(Me.From), <span style="color: #800000;">&quot;@gmail&quot;</span>) &lt;&gt; 0 <span style="color: #0600FF; font-weight: bold;">Then</span>
            CDOOutgoingMailSMTP = 465
        <span style="color: #0600FF; font-weight: bold;">ElseIf</span> InStr(1, LCase(Me.From), <span style="color: #800000;">&quot;@aol&quot;</span>) &lt;&gt; 0 <span style="color: #0600FF; font-weight: bold;">Then</span>
            CDOOutgoingMailSMTP = 587
        <span style="color: #0600FF; font-weight: bold;">Else</span>
            CDOOutgoingMailSMTP = 25
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
&nbsp;
    <span style="color: #008000;">' Purpose: Name/IP of SMTP Server
</span>    <span style="color: #008000;">' Return: Integer
</span>    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Get</span> CDOSMTPServer  <span style="color: #008000;">'As String
</span>        <span style="color: #0600FF; font-weight: bold;">If</span> InStr(1, LCase(Me.From), <span style="color: #800000;">&quot;@yahoo&quot;</span>) &lt;&gt; 0 <span style="color: #0600FF; font-weight: bold;">Then</span>
            CDOSMTPServer = <span style="color: #800000;">&quot;smtp.mail.yahoo.com&quot;</span>
        <span style="color: #0600FF; font-weight: bold;">ElseIf</span> InStr(1, LCase(Me.From), <span style="color: #800000;">&quot;@gmail&quot;</span>) &lt;&gt; 0 <span style="color: #0600FF; font-weight: bold;">Then</span>
            CDOSMTPServer = <span style="color: #800000;">&quot;smtp.gmail.com&quot;</span>
        <span style="color: #0600FF; font-weight: bold;">ElseIf</span> InStr(1, LCase(Me.From), <span style="color: #800000;">&quot;@hotmail&quot;</span>) &lt;&gt; 0 <span style="color: #0600FF; font-weight: bold;">Or</span> _
               InStr(1, LCase(Me.From), <span style="color: #800000;">&quot;@live&quot;</span>) &lt;&gt; 0 <span style="color: #0600FF; font-weight: bold;">Then</span>
            CDOSMTPServer = <span style="color: #800000;">&quot;smtp.live.com&quot;</span>
        <span style="color: #0600FF; font-weight: bold;">ElseIf</span> InStr(1, LCase(Me.From), <span style="color: #800000;">&quot;@aol&quot;</span>) &lt;&gt; 0 <span style="color: #0600FF; font-weight: bold;">Then</span>
            CDOSMTPServer = <span style="color: #800000;">&quot;smtp.aol.com&quot;</span>
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>    
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
&nbsp;
    <span style="color: #008000;">' Purpose: Setting for SMTP Server's use of SSL (Boolean)
</span>    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Property</span> <span style="color: #0600FF; font-weight: bold;">Get</span> CDOUseSSL  <span style="color: #008000;">'As Boolean
</span>        CDOUseSSL = <span style="color: #0600FF; font-weight: bold;">True</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">If</span> InStr(1, LCase(Me.From), <span style="color: #800000;">&quot;@aol&quot;</span>) &lt;&gt; 0 <span style="color: #0600FF; font-weight: bold;">Then</span>
            CDOUseSSL = <span style="color: #0600FF; font-weight: bold;">False</span>
        <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">If</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Property</span>
&nbsp;
&nbsp;
<span style="color: #008000;">'#region Initialization and Termination
</span>    
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Initialize</span>()
        <span style="color: #0600FF; font-weight: bold;">Set</span> CDOMessage = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;CDO.Message&quot;</span>)
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Private</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> <span style="color: #6666CC; font-weight: bold;">Class_Terminate</span>()
        <span style="color: #0600FF; font-weight: bold;">Set</span> CDOMessage = <span style="color: #0600FF; font-weight: bold;">Nothing</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #6666CC; font-weight: bold;">Class</span></pre></div></div>

<h5>Code: Function SendMail</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Purpose: Sends an Email Using CDO to a recipient
</span><span style="color: #008000;">' Args:
</span><span style="color: #008000;">'    sEmailID: Sender's Mail ID String
</span><span style="color: #008000;">'    sPassword: Sender's Password String
</span><span style="color: #008000;">'    sTo: Recipient's Mail ID String
</span><span style="color: #008000;">'    sSubject: Subject String
</span><span style="color: #008000;">'    sBody: Body Message String
</span><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> SendMail(EmailID, Password, Recipient, CC, Subject, Body)
    <span style="color: #0600FF; font-weight: bold;">Dim</span> oEmailSender : <span style="color: #0600FF; font-weight: bold;">Set</span> oEmailSender = <span style="color: #0600FF; font-weight: bold;">New</span> EmailSender
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">With</span> oEmailSender
        .Send EmailID, Password, Recipient, CC, Subject, Body
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">with</span> 
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span></pre></div></div>

<h5>Code: Function SendMailFromFile</h5>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' Purpose: Sends an Email Using CDO to a recipient
</span><span style="color: #008000;">' Args:
</span><span style="color: #008000;">'    sEmailID: Sender's Mail ID String
</span><span style="color: #008000;">'    sPassword: Sender's Password String
</span><span style="color: #008000;">'    sTo: Recipient's Mail ID String
</span><span style="color: #008000;">'    sSubject: Subject String
</span><span style="color: #008000;">'    sCompleteFilePath: Text File containing the Body Message
</span><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> SendMailFromFile(EmailID, Password, Recipient, CC, Subject, sCompleteFilePath)
    <span style="color: #0600FF; font-weight: bold;">Dim</span> oEmailSender : <span style="color: #0600FF; font-weight: bold;">Set</span> oEmailSender = <span style="color: #0600FF; font-weight: bold;">New</span> EmailSender
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">With</span> oEmailSender
        .LoadBodyMessage = sCompleteFilePath
        .Send EmailID, Password, Recipient, CC, Subject, <span style="color: #800000;">&quot;&quot;</span>
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">with</span> 
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span></pre></div></div>

<p>You can use this code as a .VBS file, but, please remember to remove/comment the Reporter.ReportEvent statement on Line 113.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/cdo-send-email-from-yahoo-hotmail-live-aol-or-gmail/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Retrieve Server Response using XMLHTTP</title>
		<link>http://relevantcodes.com/retrieve-response-using-xmlhttp/</link>
		<comments>http://relevantcodes.com/retrieve-response-using-xmlhttp/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 21:42:26 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP/Web]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Get]]></category>
		<category><![CDATA[Post]]></category>
		<category><![CDATA[QTP XMLHTTP]]></category>
		<category><![CDATA[VBScript XMLHTTP]]></category>
		<category><![CDATA[XMLHTTP]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=80</guid>
		<description><![CDATA[This topic outlines the use of XMLHTTP object in VBSCript. It will show how to retrieve Server-side response without physically opening the page.]]></description>
			<content:encoded><![CDATA[<p></p><p>I recently received the following question in my mailbox yesterday: <i>Is it possible to retrieve the text of a page without physically opening it?</i></p>
<p>Yes, it&#8217;s possible to retrieve the document text without physically opening the page. It can be done though an XMLHTTP Request. XMLHTTP is short for <b>E</b>xtensible <b>M</b>arkup <b>L</b>anguage <b>H</b>yper<b>T</b>ext <b>T</b>ransfer <b>P</b>rotocol. &#8220;The XMLHttpRequest object implements an interface exposed by a scripting engine that allows scripts to perform HTTP client functionality, such as submitting form data or loading data from a server.&#8221;<sup>1</sup></p>
<p>In the snippet below, I&#8217;ve created a simple mechanism to retrieve server response from this blog. The &#8216;OPEN&#8217; method is used to assign a method (GET, POST, HEAD) of the pending request. The &#8216;SEND&#8217; method  sends the request (as detailed in the Open method) to the server.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Dim</span> oXMLHTTP
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Set</span> oXMLHTTP = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Microsoft.XMLHttp&quot;</span>)
&nbsp;
<span style="color: #0600FF; font-weight: bold;">With</span> oXMLHTTP
    .<span style="color: #0600FF; font-weight: bold;">open</span> <span style="color: #800000;">&quot;GET&quot;</span>, <span style="color: #800000;">&quot;http://www.relevantcodes.com&quot;</span>, <span style="color: #0600FF; font-weight: bold;">False</span>
    .send
&nbsp;
    Reporter.ReportEvent micInfo, <span style="color: #800000;">&quot;Status&quot;</span>, .statusText
    Reporter.ReportEvent micInfo, <span style="color: #800000;">&quot;Response&quot;</span>, .responseText
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">with</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Set</span> oXMLHTTP = <span style="color: #0600FF; font-weight: bold;">Nothing</span></pre></div></div>

<div class="wp-caption aligncenter" style="width: 500px">
	<a href="http://www.relevantcodes.com/Articles/XMLHTTP/Status.JPG"><img alt="XMLHTTP Request Status" src="http://www.relevantcodes.com/Articles/XMLHTTP/Status.JPG" title="XMLHTTP Request Status" width="500" height="127" /></a>
	<p class="wp-caption-text">XMLHTTP Request Status</p>
</div>
<div class="wp-caption aligncenter" style="width: 500px">
	<a href="http://www.relevantcodes.com/Articles/XMLHTTP/Response.JPG"><img alt="XMLHTTP Request Response" src="http://www.relevantcodes.com/Articles/XMLHTTP/Response.JPG" title="XMLHTTP Request Response" width="500" height="145" /></a>
	<p class="wp-caption-text">XMLHTTP Request Response</p>
</div>
<h2>References</h2>
<ol>
<li><a href="http://www.w3.org/TR/XMLHttpRequest/">The XMLHTTPRequest Object</a></li>
<li><a href="http://www.w3schools.com/XML/xml_http.asp">The XMLHTTPRequest Object</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/retrieve-response-using-xmlhttp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Passing Multiple Values from Functions</title>
		<link>http://relevantcodes.com/passing-multiple-values-from-functions/</link>
		<comments>http://relevantcodes.com/passing-multiple-values-from-functions/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 21:41:43 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[ByRef]]></category>
		<category><![CDATA[ByVal ByRef]]></category>
		<category><![CDATA[Dictionary]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[QTP ByVal ByRef]]></category>
		<category><![CDATA[VBScript ByVal ByRef]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=78</guid>
		<description><![CDATA[In this topic we will learn how to pass 2 or more values from function using Global Variables, Arrays, Dictionary Objects, Concatenated Strings and with the use of ByRef.]]></description>
			<content:encoded><![CDATA[<p></p><p>There are several ways to return multiple values from functions. In this topic, we&#8217;re going to look over the 5 most common techniques to pass 2 or more values from functions. The 5 techniques are:</p>
<ol>
<li>Returning variables in Global scope</li>
<li>Returning a Collection</li>
<li>Returning Arrays</li>
<li>Using Concatenated Strings</li>
<li>Passing through the use of ByRef</li>
</ol>
<h2>Returning variables in Global scope</h2>
<p>
This can be achieved by declaring the variables outside the scope of the function. Here, we don&#8217;t need to pass the values through the function; but we can simply manipulate them within the function&#8217;s scope. Please note that if the same string is declared within the function, it loses its global scope &#8211; as it becomes local to the function. These variables can come from a function library or from the test script as long as they are outside the scope of the calling method. Code snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Dim</span> intNumber_1: intNumber_1 = 40
<span style="color: #0600FF; font-weight: bold;">Dim</span> intNumber_2: intNumber_2 = 80
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> PassValues
    intNumber_1 = intNumber_1/4
    intNumber_2 = intNumber_2/4
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
PassValues
&nbsp;
MsgBox <span style="color: #800000;">&quot;intNumber_1 = &quot;</span> &amp; intNumber_1 &amp;_
    vbLf &amp; <span style="color: #800000;">&quot;intNumber_2 = &quot;</span> &amp; intNumber_2</pre></div></div>

<h5>Demo</h5>
<p><img alt="Use of Global Variables" src="http://relevantcodes.com/Articles/PassMultipleValuesFromFn/UsingGlobalVars.jpg" class="aligncenter" width="161" height="169" title="Use of Global Variables" /></p>
<h2>Returning a Collection</h2>
<p>
Another way to pass multiple values from a function is through the using of creating and passing Collections. We can use a collection object to store multiple values as keys/items. Code snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Function</span> PassValues(<span style="color: #0600FF; font-weight: bold;">ByVal</span> Num_1, <span style="color: #0600FF; font-weight: bold;">ByVal</span> Num_2)
    <span style="color: #0600FF; font-weight: bold;">Set</span> oDict = <span style="color: #0600FF; font-weight: bold;">CreateObject</span>( <span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span> )
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">With</span> oDict
        .Add <span style="color: #800000;">&quot;Num_1&quot;</span>, Num_1/4
        .Add <span style="color: #800000;">&quot;Num_2&quot;</span>, Num_2/2
    <span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">With</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">Set</span> PassValues = oDict
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Set</span> colNumbers = PassValues(40,80)
&nbsp;
MsgBox <span style="color: #800000;">&quot;intNumber_1 = &quot;</span> &amp; colNumbers.Item(<span style="color: #800000;">&quot;Num_1&quot;</span>) &amp;_
    vbLf &amp; <span style="color: #800000;">&quot;intNumber_2 = &quot;</span> &amp; colNumbers.Item(<span style="color: #800000;">&quot;Num_2&quot;</span>)</pre></div></div>

<h5>Demo</h5>
<p><img alt="Use of Scripting.Dictionary" src="http://relevantcodes.com/Articles/PassMultipleValuesFromFn/UsingGlobalVars.jpg" class="aligncenter" width="161" height="169" title="Use of Scripting.Dictionary" /></p>
<h2>Returning Arrays</h2>
<p>
This is quite a common technique. Each element in the array stores a variable that is then passed through the function. Code snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Function</span> PassValues(<span style="color: #0600FF; font-weight: bold;">ByVal</span> Num_1, <span style="color: #0600FF; font-weight: bold;">ByVal</span> Num_2)
    <span style="color: #0600FF; font-weight: bold;">Dim</span> arrArray: <span style="color: #0600FF; font-weight: bold;">ReDim</span> arrArray(2)
&nbsp;
    arrArray(0) = Num_1/4
    arrArray(1) = Num_2/2
&nbsp;
    PassValues = arrArray
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
arrNew = PassValues(40,80)
&nbsp;
MsgBox <span style="color: #800000;">&quot;intNumber_1 = &quot;</span> &amp; arrNew(0) &amp;_
    vbLf &amp; <span style="color: #800000;">&quot;intNumber_2 = &quot;</span> &amp; arrNew(1)</pre></div></div>

<h5>Demo</h5>
<p><img alt="Use of Arrays" src="http://relevantcodes.com/Articles/PassMultipleValuesFromFn/UsingGlobalVars.jpg" class="aligncenter" width="161" height="169" title="Use of Arrays" /></p>
<h2>Concatenated Strings</h2>
<p>
I have seen the usage of this technique almost as frequently as the use of arrays. Here, two or more concatenated numbers/strings can be passed through the function with the help of a delimiter. Code snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Function</span> PassValues(<span style="color: #0600FF; font-weight: bold;">ByVal</span> Num_1, <span style="color: #0600FF; font-weight: bold;">ByVal</span> Num_2)
    Num_1 = Num_1/4
    Num_2 = Num_2/2
&nbsp;
    PassValues = Num_1 &amp; <span style="color: #800000;">&quot;,&quot;</span> &amp; Num_2
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
sNum = PassValues(40,80)
&nbsp;
MsgBox <span style="color: #800000;">&quot;intNumber_1 = &quot;</span> &amp; Split(sNum, <span style="color: #800000;">&quot;,&quot;</span>)(0) &amp;_
    vbLf &amp; <span style="color: #800000;">&quot;intNumber_2 = &quot;</span> &amp; Split(sNum, <span style="color: #800000;">&quot;,&quot;</span>)(1)</pre></div></div>

<h5>Demo</h5>
<p><img alt="Using Concatenated Strings" src="http://relevantcodes.com/Articles/PassMultipleValuesFromFn/UsingGlobalVars.jpg" class="aligncenter" width="161" height="169" title="Using Concatenated Strings" width="408" height="351" /></p>
<p>Note above that, concatenated string was passed, it must be broken by using one of the delimiting techniques (split, left, right etc.)</p>
<h2>Using ByRef to Pass Multiple Values</h2>
<p>
Please refer to the article <a href="http://relevantcodes.com/passing-parameters-byref-byval/" >Passing Parameters ByRef and ByVal</a> for a detailed explanation of this technique. It can be used to pass multiple values in the following manner:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Dim</span> intNumber_1: intNumber_1 = 40
<span style="color: #0600FF; font-weight: bold;">Dim</span> intNumber_2: intNumber_2 = 80
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #0600FF; font-weight: bold;">Sub</span> PassValues(<span style="color: #0600FF; font-weight: bold;">ByRef</span> Num_1, <span style="color: #0600FF; font-weight: bold;">ByRef</span> Num_2)
    Num_1 = Num_1/4
    Num_2 = Num_2/2
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Sub</span>
&nbsp;
PassValues intNumber_1, intNumber_2
&nbsp;
MsgBox <span style="color: #800000;">&quot;intNumber_1 = &quot;</span> &amp; intNumber_1 &amp;_
    vbLf &amp; <span style="color: #800000;">&quot;intNumber_2 = &quot;</span> &amp; intNumber_2</pre></div></div>

<h5>Demo</h5>
<p><img alt="Using ByRef" src="http://relevantcodes.com/Articles/PassMultipleValuesFromFn/UsingGlobalVars.jpg" title="Using ByRef" class="aligncenter" width="161" height="169" /></p>
<p>I hope you found this article helpful. Thanks for visiting Relevant Codes :)</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/passing-multiple-values-from-functions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Passing Parameters ByRef &amp; ByVal (Revised)</title>
		<link>http://relevantcodes.com/passing-parameters-byref-byval/</link>
		<comments>http://relevantcodes.com/passing-parameters-byref-byval/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 21:41:16 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[ByRef]]></category>
		<category><![CDATA[ByVal]]></category>
		<category><![CDATA[ByVal ByRef]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[QTP ByVal ByRef]]></category>
		<category><![CDATA[VBScript ByVal ByRef]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=76</guid>
		<description><![CDATA[This article demonstrates the differences between ByRef and ByVal in VBScript. It will also provide the pros and cons and excellent examples to get you started immediately.]]></description>
			<content:encoded><![CDATA[<p></p><p>In VBScript, there are two ways values can be passed: ByVal and ByRef. Using ByVal, we can pass arguments as values whereas with the use of ByRef, we can pass arguments are references. This is the obvious bit, but, how do these 2 differ in practice?
</p>
<p>Let&#8217;s find out!</p>
<h2>Passing Parameters By Value</h2>
<p>
Consider the following code snippet:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> GetValue( <span style="color: #0600FF; font-weight: bold;">ByVal</span> var )
    var = var + 1
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Dim</span> x: x = 5
&nbsp;
<span style="color: #008000;">'Pass the variable x to the GetValue function ByVal
</span>GetValue x
&nbsp;
MsgBox <span style="color: #800000;">&quot;x = &quot;</span> &amp; x</pre></div></div>

<p>
When you run the block of code above, you will get the following output:
</p>
<p><img alt="" src="http://relevantcodes.com/Articles/ByValByRef/x=5.JPG" title="By Value" class="aligncenter" width="154" height="154" /></p>
<p>
In other words, when we passed the variable &#8216;x&#8217; (ByVal) to the function &#8216;GetValue&#8217;, we were simply passing a copy of the variable &#8216;x&#8217;. When GetValue executes, &#8216;var&#8217; stores a copy of the variable &#8216;x&#8217; and increments itself by 1. Therefore, because what we are passing to GetValue is a copy of &#8216;x&#8217;, it cannot be modified.
</p>
<p>
Now, let&#8217;s look at another way of passing variables: By Reference.
</p>
<h2>Passing Parameters By Reference</h2>
<p>
Consider the following code snippet that takes arguments ByReference:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> GetReference( <span style="color: #0600FF; font-weight: bold;">ByRef</span> var )
    var = var + 1
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Dim</span> x: x = 5
&nbsp;
<span style="color: #008000;">'Pass the variable x to the GetReference function ByRef
</span>GetReference x
&nbsp;
MsgBox x</pre></div></div>

<p>
You must already be aware what&#8217;s going to happen when the above code is executed. Let&#8217;s see the snapshot:
</p>
<p><img title="Passing Parameter By Reference" src="http://relevantcodes.com/Articles/ByValByRef/x=6.JPG" class="aligncenter" alt="Passing Parameter By Reference" /></p>
<p>
Yes, variable &#8216;x&#8217; was increment by 1. But why was &#8216;x&#8217; incremented? Only &#8216;var&#8217; must have incremented by 1, and not &#8216;x&#8217;? Well, that is the core concept behind passing variables by reference.
</p>
<p>
When the function &#8216;getReference&#8217; executes, &#8216;var&#8217; becomes a reference of &#8216;x&#8217;, and therefore, any changes made to &#8216;var&#8217; would impact &#8216;x&#8217;. So if var increments itself by 1, so would x. If var becomes 0 (zero), so would x.
</p>
<p>
Let&#8217;s see another example:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> GetReference( <span style="color: #0600FF; font-weight: bold;">ByRef</span> arrArray )
    <span style="color: #0600FF; font-weight: bold;">ReDim</span> <span style="color: #0600FF; font-weight: bold;">Preserve</span> arrArray(<span style="color: #0600FF; font-weight: bold;">UBound</span>(arrArray)+1)
    arrArray(<span style="color: #0600FF; font-weight: bold;">UBound</span>(arrArray)) = 2
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Dim</span> newArray: newArray = Array(0, 1)
GetReference newArray</pre></div></div>

<p>
Will the size of &#8216;newArray&#8217; increase? Let&#8217;s see:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #008000;">' new size: 2
</span>MsgBox <span style="color: #0600FF; font-weight: bold;">UBound</span>(newArray)
&nbsp;
<span style="color: #008000;">' new elements: 0, 1, 2
</span><span style="color: #0600FF; font-weight: bold;">For</span> x = <span style="color: #0600FF; font-weight: bold;">LBound</span>(newArray) <span style="color: #0600FF; font-weight: bold;">To</span> <span style="color: #0600FF; font-weight: bold;">UBound</span>(newArray)
    MsgBox newArray(x)
<span style="color: #0600FF; font-weight: bold;">Next</span></pre></div></div>

<p>
Since &#8216;newArray&#8217; was passed as a reference to the GetReference function, the change made to &#8216;arrArray&#8217; was reflected upon &#8216;newArray&#8217; as well. Thus, sizes of both arrays incremented by 1.
</p>
<p>
Is there a way to pass variables byRef and still avoid this? Yes, there is. The answer lies in <em>passing temporary variables (see footnotes below).</em>
</p>
<h2>ByRef &#038; Temporary Variables</h2>
<p>
The advantage of using this approach is that you can pass temporary variables to <em>n</em> number of functions accepting arguments as reference, without having the base (original) variables modified. This is a good (and recommended) approach, since your original variables stay intact and you do not lose track of them when working with extensive function libraries. Please see a simple demonstration of this approach below:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:Consolas,Monaco,Courier,Verdana;"><span style="color: #0600FF; font-weight: bold;">Function</span> GetReference( <span style="color: #0600FF; font-weight: bold;">ByRef</span> var )
 var = var + 1
<span style="color: #0600FF; font-weight: bold;">End</span> <span style="color: #0600FF; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">Dim</span> x: x = 5
<span style="color: #0600FF; font-weight: bold;">Dim</span> y: y = x
&nbsp;
GetReference y
&nbsp;
MsgBox x   <span style="color: #008000;">'Returns 5 (x remains unchanged)
</span>MsgBox y   'Returns 6</pre></div></div>

<p>
Above, you will notice that as <em>y</em> became a temporary variable and was passed to GetReference, only it was modified. The variable <em>x</em> was unchanged. Thus, it&#8217;s recommended to use temporary variables when passing variables as reference.
</p>
<h2>Summary</h2>
<ul>
<li>(ByVal) Arguments do not change when passed by value.</li>
<li>(ByRef) If the function parameter is modified, it will have the same impact on the parameter that was passed by reference.</li>
<li>(ByRef) Because the passed parameters can be changed, we can pass multiple values from functions.</li>
<li>(ByRef) In a huge function library, it can be hard to tell where the value was changed and what function the variable was supposed to perform.</li>
</ul>
<p><strong>*</strong> Credits go to <a href="http://www.vivit-worldwide.org">Christopher J. Schärer</a> for pointing out the error in this statement.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/passing-parameters-byref-byval/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 10/56 queries in 0.038 seconds using disk: basic
Object Caching 811/957 objects using disk: basic
Content Delivery Network via N/A

Served from: relevantcodes.com @ 2012-05-19 10:53:07 -->
