<?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>ASI &#187; array</title>
	<atom:link href="http://www.asi-test.com/ASI/tag/array/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.asi-test.com/ASI</link>
	<description>Automated Solutions, Inc. - Leadership in Software Development, Testing &#38; Test Automation</description>
	<lastBuildDate>Thu, 02 Feb 2012 17:38:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>VBScript: Overflow error using CInt function</title>
		<link>http://www.asi-test.com/ASI/vbscript-cint-overflow-error/</link>
		<comments>http://www.asi-test.com/ASI/vbscript-cint-overflow-error/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 17:18:05 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[QuickTest Pro]]></category>
		<category><![CDATA[Sample Code]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[cint]]></category>
		<category><![CDATA[clng]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[overflow]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[variable]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://www.asi-test.com/ASI/?p=598</guid>
		<description><![CDATA[Tips &#38; Tricks Series &#8211; Overflow error Ever get an &#8220;Overflow error&#8221; when using the CInt function?  You might encounter this error when you are doing some programming in your test script and doing some data manipulations or calculations.  Let&#8217;s review an example of a situation that could cause this to happen &#8211; a classic [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">Tips &amp; Tricks Series &#8211; Overflow error</p>
<p>Ever get an &#8220;Overflow error&#8221; when using the CInt function?  You might encounter this error when you are doing some programming in your test script and doing some data manipulations or calculations.  Let&#8217;s review an example of a situation that could cause this to happen &#8211; a classic example would be if you were processing a file where a number could be rather large. <span id="more-598"></span>  Here is a code snippet where the batch size of a data extract was retrieved and generated the Overflow error:</p>
<p><a href="http://www.asi-test.com/ASI/wp-content/uploads/2011/08/ExampleError.jpg"><img class="size-full wp-image-599 alignnone" title="Example VBScript CInt Error in QuickTest Pro" src="http://www.asi-test.com/ASI/wp-content/uploads/2011/08/ExampleError.jpg" alt="Example VBScript CInt Error in QuickTest Pro" width="587" height="517" /></a></p>
<p>&nbsp;</p>
<p>First thing is that in VBScript it only has one data type called Variant.  This can contain either a numeric or string in it and by default it will be a string if there are any other characters in the original value (which is very common).  There are sub-types available to use that you can convert a string or Variant to; they can be one of these:</p>
<table border="1">
<tbody>
<tr>
<td>Subtype</td>
<td>Description</td>
</tr>
<tr>
<td>Empty</td>
<td>Variant is uninitialized. Value is 0 for numeric variables or a zero-length string (&#8220;&#8221;) for string variables.</td>
</tr>
<tr>
<td>Null</td>
<td>Variant intentionally contains no valid data.</td>
</tr>
<tr>
<td>Boolean</td>
<td>Contains either True or False.</td>
</tr>
<tr>
<td>Byte</td>
<td>Contains integer in the range 0 to 255.</td>
</tr>
<tr>
<td>Integer</td>
<td>Contains integer in the range -32,768 to 32,767.</td>
</tr>
<tr>
<td>Currency</td>
<td>-922,337,203,685,477.5808 to 922,337,203,685,477.5807.</td>
</tr>
<tr>
<td>Long</td>
<td>Contains integer in the range -2,147,483,648 to 2,147,483,647.</td>
</tr>
<tr>
<td>Single</td>
<td>Contains a single-precision, floating-point number in the range -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values.</td>
</tr>
<tr>
<td>Double</td>
<td>Contains a double-precision, floating-point number in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.</td>
</tr>
<tr>
<td>Date (Time)</td>
<td>Contains a number that represents a date between January 1, 100 to December 31, 9999.</td>
</tr>
<tr>
<td>String</td>
<td>Contains a variable-length string that can be up to approximately 2 billion characters in length.</td>
</tr>
<tr>
<td>Object</td>
<td>Contains an object.</td>
</tr>
<tr>
<td>Error</td>
<td>Contains an error number.</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>Typically what you want to do in order to either add numbers together or compare two numbers in a conditional statement is to convert the variable to a numeric integer.  The way to do that is using the CInt() function.  However if you notice in the table above, an Integer is in the range of -32,768 to 32,767.  The problem is if you are working with an integer that is larger than 32,767.  Like in this example, if you look at the bottom in the Debug Viewer you will see that the Batch Size is actually 56,989 (which is not a surprise when dealing with data extracts).  So this is what is throwing the error because if you look above the error at the test script, you will see on line 103 that CInt is being used.  But if you know that a data element could be large, then use CLng() instead.  This will convert it to a Long which then accepts a range of -2,147,483,648 to 2,147,483,647 and works fine for our situation.</p>
<p>Now if you look at this second image, notice how line 103 now uses CLng and how we have paused on the next line, there is no error and the batch size is correct at 56,989 and notice the type is now &#8220;Long&#8221; to the right of the value.</p>
<p><a href="http://www.asi-test.com/ASI/wp-content/uploads/2011/08/CLngFix.jpg"><img class="size-full wp-image-600 alignnone" title="VBScript CLng Fix to CInt error in QuickTest Pro" src="http://www.asi-test.com/ASI/wp-content/uploads/2011/08/CLngFix.jpg" alt="VBScript CLng Fix to CInt error in QuickTest Pro" width="587" height="516" /></a></p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=282419851791791&amp;xfbml=1" type="text/javascript"></script>
<fb:like href="http://www.asi-test.com/ASI/vbscript-cint-overflow-error/" send="true" layout="button_count" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.asi-test.com/ASI/vbscript-cint-overflow-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redim a multi-dimensional array</title>
		<link>http://www.asi-test.com/ASI/redim-multidimensional-array/</link>
		<comments>http://www.asi-test.com/ASI/redim-multidimensional-array/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 11:59:20 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[ASI General]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[QuickTest Pro]]></category>
		<category><![CDATA[Sample Code]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dimensions]]></category>
		<category><![CDATA[multi-dimensional]]></category>
		<category><![CDATA[multiple]]></category>
		<category><![CDATA[redim]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://www.asi-test.com/ASI/?p=485</guid>
		<description><![CDATA[Did you know that when it comes to redimensionalizing a multi-dimensional array in VBScript, you can only redimensionalize the last element (which is the columns) not the first element (which is the rows)?  This is true and can be rather annoying and limiting in scope.  Unfortunately you are stuck dealing with it so what this [...]]]></description>
			<content:encoded><![CDATA[<p>Did you know that when it comes to redimensionalizing a multi-dimensional array in VBScript, you can only redimensionalize the last element (which is the columns) not the first element (which is the rows)?  This is true and can be rather annoying and limiting in scope.  Unfortunately you are stuck dealing with it so what this means is that you have to either plan out how large you think the array is, or adjust your structure accordingly. <span id="more-485"></span> What I find is that this is backwards from what I&#8217;m used to in other languages and causes me to have to adjust my vision of the array.  I usually think of the arrays as being similar to tables in a database where the rows are the dynamic elements (various data records) and the columns are the common data elements I&#8217;m tracking; which is also how the data table in QuickTest Pro is structured.  For example if we think of profile data I would envision it being like this:</p>
<p style="text-align: center;"><img class="size-full wp-image-486 aligncenter" title="TableProfileData" src="http://www.asi-test.com/ASI/wp-content/uploads/2011/07/1TableProfileData.jpg" alt="Data table containing profile data" width="539" height="103" /></p>
<p>But this doesn&#8217;t work if you are populating an array on the fly with data. In this example the data is the rows and this is what you would want to grow; but you can&#8217;t resize the row element. So what you really want to do is reverse your layout to make the rows be the fields you are tracking and make the columns your &#8220;individual records of data&#8221; like in this image (ignore the first column in the image as this is just a label so you know what I&#8217;m talking about; it&#8217;s not really part of the actual array):</p>
<p style="text-align: center;"> <img class="size-full wp-image-487 aligncenter" title="2TableReverseArray" src="http://www.asi-test.com/ASI/wp-content/uploads/2011/07/2TableReverseArray.jpg" alt="Data table with column/elements reversed for the array" width="535" height="183" /></p>
<p>Now keep in mind that this is only an issue when you have to redim an existing multi-dimensional array. However if you know the size of a multi-dimensional array then I would stick to the normal array layout where the rows are data records and the columns are the field elements.</p>
<p>The code that controls this would look similar to something like this:</p>
<table width="450" border="2" align="center" bgcolor="silver">
<tbody>
<tr>
<td><code><span style="color: black; font-size: small;">Dim arrProfileData()<br />
ReDim Preserve arrProfileData(7,1)<br />
arrProfileData(0,0)="Joe"<br />
arrProfileData(0,1)="Mary"<br />
arrProfileData(1,0)="Tester"<br />
arrProfileData(1,1)="Jones"<br />
ReDim Preserve arrProfileData(7,4)<br />
arrProfileData(0,2)="Billy"<br />
...etc</span></code></td>
</tr>
</tbody>
</table>
<p>**Note this doesn&#8217;t apply to a single-dimensional array. That you can redim any time since it is dealing with only one element.</p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=282419851791791&amp;xfbml=1" type="text/javascript"></script>
<fb:like href="http://www.asi-test.com/ASI/redim-multidimensional-array/" send="true" layout="button_count" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.asi-test.com/ASI/redim-multidimensional-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QTP: Send Outlook Email</title>
		<link>http://www.asi-test.com/ASI/qtp-send-outlook-email/</link>
		<comments>http://www.asi-test.com/ASI/qtp-send-outlook-email/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 16:32:19 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[QuickTest Pro]]></category>
		<category><![CDATA[Sample Code]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[createobject]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[subroutine]]></category>

		<guid isPermaLink="false">http://www.asi-test.com/ASI/?p=82</guid>
		<description><![CDATA[QuickTest Pro sample code &#8211; sending an email using Outlook This QuickTest Pro code sample shows how you can create a subroutine that will send an email using Microsoft Outlook.  The subroutine is defined and can either be placed at the top of your script (must be executed first before it is called in order for [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">QuickTest Pro sample code &#8211; sending an email using Outlook</p>
<p style="text-align: left;">This QuickTest Pro code sample shows how you can create a subroutine that will send an email using Microsoft Outlook.  The subroutine is defined and can either be placed at the top of your script (must be executed first before it is called in order for the script to know about the subroutine) or it can be placed in a Function Library and associated with the test script. </p>
<p><span id="more-82"></span> The reason to use a subroutine is to isolate the process code that creates and sends the Outlook email to a common subroutine in order to take advantage of reuse.  This way every time a test script needs to send an email it just needs to have the bottom three lines of code shown below in the code image (lines 35 &#8211; 37).  It utilizes the &#8220;CreateObject&#8221; to create an instance of the Outlook application in order to create the actual email.  The data used in the email is passed into the subroutine using an array and then each element is referenced within the subroutine code.</p>
<table style="height: 650px;" border="0" cellspacing="0" cellpadding="0" width="574" align="center">
<colgroup span="1">
<col span="1" width="235"></col>
</colgroup>
<tbody>
<tr height="20">
<td width="235" height="20"><img class="size-full wp-image-84 alignnone" title="Outlook email code" src="http://www.asi-test.com/ASI/wp-content/uploads/2010/01/Outlook-email-code.png" alt="Outlook email code" width="559" height="634" /></td>
</tr>
</tbody>
</table>
<p style="margin-left: 10px;">Here is the result of sending the email, the email was received and it looks like this:</p>
<table border="0" cellspacing="0" cellpadding="0" width="455" align="center">
<colgroup span="1">
<col span="1" width="235"></col>
</colgroup>
<tbody>
<tr height="20">
<td width="235" height="20"><img class="size-full wp-image-83 alignleft" title="Outlook sample email" src="http://www.asi-test.com/ASI/wp-content/uploads/2010/01/Outlook-sample-email.png" alt="Outlook sample email" width="470" height="305" /></td>
</tr>
</tbody>
</table>
<p style="margin-left: 10px;">This is kind of a neat feature that you may find a need for.</p>
<p style="margin-left: 10px;">In addition to the images above, here is a snippet of the code for easier readability and the ability to copy the code for your own use:</p>
<table border="2" width="680" align="center" bgcolor="silver">
<tbody>
<tr>
<td><code><br />
<span style="color: black; font-size: small;"><br />
Sub CreateEmail (emailInfo)</span></code><span style="color: black; font-size: small;">Dim objOutl, objMailMsg, objNameSpace, intRecipientCounter, strEmailAddress</span><span style="color: black; font-size: small;">Const olMailItem = 0      &#8217; Constants for new items<br />
Const olAppointmentItem = 1<br />
Const olContactItem = 2<br />
Const olTaskItem = 3<br />
Const olJournalItem = 4<br />
Const olNoteItem = 5<br />
Const olPostItem = 6</span><span style="color: black; font-size: small;">intRecipientCounter=1      &#8217;Start the email address counter at 1</span><span style="color: black; font-size: small;">Set objOutl=CreateObject (&#8220;Outlook.Application&#8221;)   &#8217;Create an Outlook object<br />
Set objMailMsg=objOutl.CreateItem(olMailItem)      &#8217;Create a new Outlook mail object<br />
objMailMsg.Recipients.Add(emailInfo(0))         &#8217;Add the email address to the recipient list of the message<br />
objMailMsg.Subject=emailInfo(1)            &#8217;Set the subject of the message<br />
objMailMsg.Body=emailInfo(2)            &#8217;Set the body of the mail message<br />
objMailMsg.Send               &#8217;Send the mail message</span><span style="color: black; font-size: small;">&#8216;Free up the memory<br />
Set objOutl=Nothing<br />
Set objMailMsg=Nothing</span><span style="color: black; font-size: small;">End Sub</span><span style="color: black; font-size: small;">&#8216;Script code to actually call the subroutine with data to be used in the email that will be sent<br />
Dim emailInfo<br />
emailInfo = Array(&#8220;test@hotmail.com&#8221;,&#8221;Subject: QTP Test email&#8221;,&#8221;Desc: This is a test email sent by QTP&#8221;)<br />
CreateEmail (emailInfo)<br />
</span></td>
</tr>
</tbody>
</table>
<p>Good Luck.</p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=282419851791791&amp;xfbml=1" type="text/javascript"></script>
<fb:like href="http://www.asi-test.com/ASI/qtp-send-outlook-email/" send="true" layout="button_count" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.asi-test.com/ASI/qtp-send-outlook-email/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

