<?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; DOTNetFactory</title>
	<atom:link href="http://relevantcodes.com/category/dotnetfactory/feed/" rel="self" type="application/rss+xml" />
	<link>http://relevantcodes.com</link>
	<description>A Test Development Resource for HP QuickTest Professional.</description>
	<lastBuildDate>Fri, 30 Dec 2011 07:07:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>QTP: Accessing Custom DLL Methods Through DOTNetFactory</title>
		<link>http://relevantcodes.com/qtp-custom-dlls-through-dotnetfactory/</link>
		<comments>http://relevantcodes.com/qtp-custom-dlls-through-dotnetfactory/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 16:03:48 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[All]]></category>
		<category><![CDATA[DOTNetFactory]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[Classes]]></category>
		<category><![CDATA[Custom DLL]]></category>
		<category><![CDATA[DLL]]></category>
		<category><![CDATA[DLL DOTNetFactory]]></category>
		<category><![CDATA[QTP DLL]]></category>
		<category><![CDATA[QTP DLL DOTNetFactory]]></category>
		<category><![CDATA[QTP DOTNetFactory]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=2444</guid>
		<description><![CDATA[This article shows a quick and easy way to use DLLs in QTP and access their methods with the help of DOTNetFactory. It also shows a working example of a DLL created in Visual Basic .NET and its methods accessed in QTP.]]></description>
			<content:encoded><![CDATA[<p></p><p>
In the past few weeks, I have seen a lot of new topics on the use of custom DLLs. VBScript&#8217;s lack of certain functionality and slow performance, more and more QTP Engineers are turning towards their custom DLLs to simplify and speed-up and simplify part of their framework design. This article shows how the DLLs can be loaded to QTP and their methods accessed with the help of DOTNetFactory.
</p>
<p class="info">
The DOTNetFactory Object was introduced with QuickTest Professional version 9.1. If you are using version 9.0 or less, the below code may not work <sup><a href="http://relevantcodes.com/qtp-custom-dlls-through-dotnetfactory/#comment-2871">1</a></sup> [Credits go to <a href="http://blogs.e-gineering.com/Christian/">Christian</a> for this update].
</p>
<p>
I have used VB.NET for this article, but the same principles should apply for any DLL you create. Below is a snapshot of my code in VS:
</p>
<div class="wp-caption aligncenter" style="width: 520px">
	<img alt="VB.NET Code" src="http://relevantcodes.com/Articles/DLL_DOTNetFactory/Code.PNG" title="VB.NET Code" width="520" height="356" />
	<p class="wp-caption-text">VB.NET Code</p>
</div>
<p>
There are 2 outputs I can retrieve from the code above: <code>myInteger</code> and <code>myString</code> as they are both public methods of the Class.
</p>
<p>
After building the Project and referencing the DLL saved in one of the Project&#8217;s folders (bin or debug), I copied the DLL to my D drive:
</p>
<div class="wp-caption aligncenter" style="width: 700px">
	<a href="http://relevantcodes.com/Articles/DLL_DOTNetFactory/DLLFolder.PNG"><img alt="DLL File Created" src="http://relevantcodes.com/Articles/DLL_DOTNetFactory/DLLFolder.PNG" title="DLL File Created" width="700" height="170" /></a>
	<p class="wp-caption-text">DLL File Created</p>
</div>
<p>
I can now call the methods of the DLL using the following code:
</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:consolas, monospace;"><span style="color: #0000A6;">Dim</span> oCustom 
&nbsp;
<span style="color: #0000A6;">Set</span> oCustom = DOTNetFactory.CreateInstance(<span style="color: #800000;">&quot;oNamespace.PublicClass&quot;</span>, <span style="color: #800000;">&quot;D:\\RelevantCodes.dll&quot;</span>)
&nbsp;
MsgBox oCustom.myInteger
MsgBox oCustom.myString</pre></div></div>

<p>
Snapshot of the above code in my QTP window:
</p>
<div class="wp-caption aligncenter" style="width: 700px">
	<img alt="QTP Code" src="http://relevantcodes.com/Articles/DLL_DOTNetFactory/QTPCode.PNG" title="QTP Code" width="700" height="212" />
	<p class="wp-caption-text">QTP Code</p>
</div>
<p>
Upon running the above code, I will have the following 2 outputs:
</p>
<div class="wp-caption aligncenter" style="width: 200px">
	<img alt="myInteger" src="http://relevantcodes.com/Articles/DLL_DOTNetFactory/myInteger.PNG" title="myInteger" width="104" height="107" />
	<p class="wp-caption-text">oNamespace -&gt; PublicClass -&gt; myInteger</p>
</div>
<div class="wp-caption aligncenter" style="width: 200px">
	<img alt="myString" src="http://relevantcodes.com/Articles/DLL_DOTNetFactory/myString.PNG" title="myString" width="170" height="107" />
	<p class="wp-caption-text">oNamespace -&gt; PublicClass -&gt; myString</p>
</div>
<p>
I hope you find this article useful :)
</p>
<p class="alert">If you have any questions, please ask them in the comments section. If your query is confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/qtp-custom-dlls-through-dotnetfactory/feed/</wfw:commentRss>
		<slash:comments>105</slash:comments>
		</item>
		<item>
		<title>QTP DOTNetFactory (6): Adding a RadioButton Control</title>
		<link>http://relevantcodes.com/qtp-dotnetfactory-6-adding-a-radiobutton-control/</link>
		<comments>http://relevantcodes.com/qtp-dotnetfactory-6-adding-a-radiobutton-control/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 23:42:24 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[DOTNetFactory]]></category>
		<category><![CDATA[QTP]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=536</guid>
		<description><![CDATA[Like the previous article, this will also be a little fast-paced and will cover how to create a Custom form and add a RadioButton control to it. ]]></description>
			<content:encoded><![CDATA[<p></p><div class="photo_right"><a href="http://www.flickr.com/photos/23185236@N03/3027917815/" title="MobileRadio.hk 紀念襟章"><img src="http://farm4.static.flickr.com/3063/3027917815_7650c17182_m.jpg" alt="MobileRadio.hk 紀念襟章" /></a><br /><small><a href="http://creativecommons.org/licenses/by-sa/2.0/" title="Attribution-ShareAlike License" ><img src="http://relevantcodes.com/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" width="16" height="16" /></a> <a href="http://www.photodropper.com/photos/">photo</a> credit: <a href="http://www.flickr.com/photos/23185236@N03/3027917815/" title="jonathansin">jonathansin</a></small></div>
<p>This is the 6th article in the DOTNetFactory Series. The first 5 articles cover the basics of creating a user form and adding a control to it. Like the previous article, this will also be a little fast-paced and will cover how to create a Custom form and add a RadioButton control to it. If you have any doubts with the content in this article, or the previous, please post your comments and I will try to answer them as soon as possible.</p>
<p>Similar to creating a Form, a Text Box and a Button Control, we will use .CreateInstance to create an instance of RadioButton Control as well.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oRadioButton <span style="color: #008000;">=</span> DOTNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.RadioButton&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Similar to the objects we&#8217;ve worked in the preceeding lessons, we will again have to define a point where the RadioButton will be placed.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oPoint <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Drawing.Point&quot;</span>, <span style="color: #808080;">&quot;System.Drawing&quot;</span>, x, y<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0600FF;">With</span> oPoint
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
oRadioButton.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint</pre></div></div>

<p>Also, we must add some Text to the RadioButton so its easily distinguishable. It can be done by using the .Text method:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;">oRadioButton.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;RadioButton&quot;</span></pre></div></div>

<p class="custPostHeading">Putting it all together</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oForm <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Form&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Set</span> oButton <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Button&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Set</span> oRadioButton <span style="color: #008000;">=</span> DOTNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.RadioButton&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #FF8000;">Set</span> oPoint <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Drawing.Point&quot;</span>, <span style="color: #808080;">&quot;System.Drawing&quot;</span>, x, y<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'RadioButton Location</span>
<span style="color: #0600FF;">With</span> oPoint
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'RadioButton Properties</span>
<span style="color: #0600FF;">With</span> oRadioButton
	.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;RadioButton&quot;</span>
	<span style="color: #008080; font-style: italic;">'Give the RadioButton a name property</span>
	.<span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;btnSample&quot;</span>
	.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Button Location</span>
<span style="color: #0600FF;">With</span> oPoint
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">50</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Button Properties</span>
<span style="color: #0600FF;">With</span> oButton
	.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint
	.<span style="color: #0600FF;">Width</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span>
	.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Close Form&quot;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">with</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Add Controls</span>
<span style="color: #0600FF;">With</span> oForm
	.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span> oRadioButton
	<span style="color: #008080; font-style: italic;">'Adding a Cancel Button</span>
	.<span style="color: #0000FF;">CancelButton</span> <span style="color: #008000;">=</span> oButton
	.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span> oButton
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">with</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Show Dialog</span>
oForm.<span style="color: #0000FF;">ShowDialog</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Output the entered Text:</span>
<span style="color: #0600FF;">MsgBox</span> <span style="color: #808080;">&quot;RadioButton Selected: &quot;</span> <span style="color: #008000;">&amp;</span> oRadioButton.<span style="color: #0000FF;">Checked</span></pre></div></div>

<p>Executing the code above will display a form control like below:</p>
<div class="wp-caption aligncenter" style="width: 300px">
	<a href="http://relevantcodes.com/Articles/DOTNetFactory/RadioButton/RadioButton.JPG"><img alt="DOTNetFactory: Adding a Radio Button Control" src="http://relevantcodes.com/Articles/DOTNetFactory/RadioButton/RadioButton.JPG" title="DOTNetFactory: Adding a Radio Button Control" width="300" height="300" /></a>
	<p class="wp-caption-text">DOTNetFactory: Adding a Radio Button Control</p>
</div>
<p>I had the RadioButton selected and after clicking the WebButton, I received the following output from QTP:</p>
<div class="wp-caption aligncenter" style="width: 161px">
	<a href="http://relevantcodes.com/Articles/DOTNetFactory/RadioButton/QTPOutput.JPG"><img alt="QTP Output for a Selected RadioButton" src="http://relevantcodes.com/Articles/DOTNetFactory/RadioButton/QTPOutput.JPG" title="QTP Output for a Selected RadioButton" width="161" height="100" /></a>
	<p class="wp-caption-text">QTP Output for a Selected RadioButton</p>
</div>
<p>In the next topic in this series, we will learn how to create a ComboBox control using DOTNetFactory.</p>
<p class="custPostHeading">In this Series</p>
<ol>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form/" >QTP &#038; DOTNetFactory &#8211; Creating a Custom Form</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-text-box-control/" >QTP &#038; DOTNetFactory &#8211; Adding a Text Box Control</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-button-control/" >QTP &#038; DOTNetFactory &#8211; Adding a Button Control</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-checkbox-control/" >QTP &#038; DOTNetFactory &#8211; Adding a CheckBox Control</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form-with-multiple-objects/">QTP &#038; DOTNetFactory &#8211; Creating a Custom Form with Multiple Objects</a></li>
<li>QTP &#038; DOTNetFactory &#8211; Adding a RadioButton <i>{Currently Viewed}</i></li>
<li>QTP &#038; DOTNetFactory &#8211; Adding a ComboBox &#8211; Coming Soon!</li>
</ol>
<p class="alert">If you have any questions, please ask them in the comments section. If your query is confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/qtp-dotnetfactory-6-adding-a-radiobutton-control/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>QTP DOTNetFactory (5): Creating a Custom Form with Multiple Objects</title>
		<link>http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form-with-multiple-objects/</link>
		<comments>http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form-with-multiple-objects/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 00:08:40 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[DOTNetFactory]]></category>
		<category><![CDATA[QTP]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=363</guid>
		<description><![CDATA[In this article, we will see how we can add and use multiple objects in a user form. It will cover the concepts discussed in the previous 4 articles.]]></description>
			<content:encoded><![CDATA[<p></p><p>In this article, we will see how we can add and use multiple objects in a user form and the code below will pretty much sum it up.. It will cover the concepts discussed in the previous 4 articles. If you have any doubts on this topic or any topics in the earlier chapters, please ask :)</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #0600FF;">With</span> DOTNetFactory
	<span style="color: #008080; font-style: italic;">'Form</span>
	<span style="color: #FF8000;">Set</span> oForm <span style="color: #008000;">=</span> .<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Form&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-style: italic;">'Button</span>
	<span style="color: #FF8000;">Set</span> oButton <span style="color: #008000;">=</span> .<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Button&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-style: italic;">'CheckBox</span>
	<span style="color: #FF8000;">Set</span> oCheckBox <span style="color: #008000;">=</span> .<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.CheckBox&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-style: italic;">'TextBox</span>
	<span style="color: #FF8000;">Set</span> oTextBox <span style="color: #008000;">=</span> .<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.TextBox&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">'Point</span>
	<span style="color: #FF8000;">Set</span> oPoint <span style="color: #008000;">=</span> .<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Drawing.Point&quot;</span>, <span style="color: #808080;">&quot;System.Drawing&quot;</span>, x, y<span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #0600FF;">CONST</span> txtWidth <span style="color: #008000;">=</span> <span style="color: #FF0000;">150</span>
<span style="color: #0600FF;">CONST</span> pntStart <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'TextBox</span>
<span style="color: #0600FF;">With</span> oPoint
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> pntStart
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> pntStart
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
<span style="color: #0600FF;">With</span> oTextBox
	.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint
	.<span style="color: #0600FF;">Width</span> <span style="color: #008000;">=</span> txtWidth
	.<span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;txtSample&quot;</span>
	.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Enter a value&quot;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'CheckBox</span>
<span style="color: #0600FF;">With</span> oPoint
	<span style="color: #008080; font-style: italic;">'Place the CheckBox to the right of the TextBox</span>
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> pntStart <span style="color: #008000;">+</span> txtWidth <span style="color: #008000;">+</span> <span style="color: #FF0000;">20</span>
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
<span style="color: #0600FF;">With</span> oCheckBox
	.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint
	.<span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;chkSample&quot;</span>
	.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;CheckBox&quot;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Button</span>
<span style="color: #0600FF;">With</span> oPoint
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> pntStart
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> pntStart <span style="color: #008000;">+</span> <span style="color: #FF0000;">40</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
<span style="color: #0600FF;">With</span> oButton
	.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint
	.<span style="color: #0600FF;">Width</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CInt</span><span style="color: #000000;">&#40;</span>oForm.<span style="color: #0600FF;">Width</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #008000;">*</span>pntStart<span style="color: #000000;">&#41;</span>
	.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Close Form&quot;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Form</span>
<span style="color: #0600FF;">With</span> oForm
	<span style="color: #008080; font-style: italic;">'Set Form Height</span>
	.<span style="color: #0000FF;">Height</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">200</span>
	.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span> oTextBox
	.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span> oCheckBox
	<span style="color: #008080; font-style: italic;">'Adding a Cancel Button</span>
	.<span style="color: #0000FF;">CancelButton</span> <span style="color: #008000;">=</span> oButton
	.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span> oButton
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">with</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Show Dialog</span>
oForm.<span style="color: #0000FF;">ShowDialog</span>
&nbsp;
<span style="color: #0600FF;">With</span> oTextBox
	<span style="color: #0600FF;">If</span> <span style="color: #0600FF;">LCase</span><span style="color: #000000;">&#40;</span>.<span style="color: #0000FF;">Text</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;enter a value&quot;</span> <span style="color: #FF8000;">Then</span>
		<span style="color: #0600FF;">MsgBox</span> <span style="color: #808080;">&quot;You did not enter a value in the Text Box Control&quot;</span>
	<span style="color: #FF8000;">Else</span>
		<span style="color: #0600FF;">MsgBox</span> <span style="color: #808080;">&quot;New Text Box value: &quot;</span> <span style="color: #008000;">&amp;</span> .<span style="color: #0000FF;">Text</span>
	<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">with</span>
&nbsp;
<span style="color: #0600FF;">With</span> oCheckBox
	<span style="color: #0600FF;">Dim</span> sStatus
	sStatus <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;ON&quot;</span>
	<span style="color: #0600FF;">If</span> <span style="color: #0600FF;">CBool</span><span style="color: #000000;">&#40;</span>.<span style="color: #0000FF;">Checked</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span> <span style="color: #FF8000;">Then</span> sStatus <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;OFF&quot;</span>
	<span style="color: #0600FF;">MsgBox</span> <span style="color: #808080;">&quot;CheckBox Status: &quot;</span> <span style="color: #008000;">&amp;</span> sStatus
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">with</span></pre></div></div>

<p>Executing the code above will display a form control:</p>
<div class="wp-caption aligncenter" style="width: 300px">
	<a href="http://relevantcodes.com/Articles/DOTNetFactory/CombinedForm/Form.JPG"><img alt="A DOTNetFactory Form" src="http://relevantcodes.com/Articles/DOTNetFactory/CombinedForm/Form.JPG" title="A DOTNetFactory Form" width="300" height="200" /></a>
	<p class="wp-caption-text">A DOTNetFactory Form</p>
</div>
<p>In the next topics in this series, ComboBox and RadioButtons will be covered.</p>
<p>I hope you find this article useful.</p>
<p class="custPostHeading">In this Series</p>
<ol>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form/" >QTP &#038; DOTNetFactory &#8211; Creating a Custom Form</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-text-box-control/" >QTP &#038; DOTNetFactory &#8211; Adding a Text Box Control</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-button-control/" >QTP &#038; DOTNetFactory &#8211; Adding a Button Control</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-checkbox-control/" >QTP &#038; DOTNetFactory &#8211; Adding a CheckBox Control</a></li>
<li>QTP &#038; DOTNetFactory &#8211; Creating a Custom Form with Multiple Objects <i>{Currently viewing}</i></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-6-adding-a-radiobutton-control/" >QTP &#038; DOTNetFactory &#8211; Adding a RadioButton</a></li>
<li>QTP &#038; DOTNetFactory &#8211; Adding a ComboBox &#8211; Coming Soon!</li>
</ol>
<p class="alert">If you have any questions, please ask them in the comments section. If your information is to be treated as confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form-with-multiple-objects/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>QTP DOTNetFactory (4): Adding a CheckBox Control</title>
		<link>http://relevantcodes.com/qtp-dotnetfactory-adding-a-checkbox-control/</link>
		<comments>http://relevantcodes.com/qtp-dotnetfactory-adding-a-checkbox-control/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 00:05:14 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[DOTNetFactory]]></category>
		<category><![CDATA[QTP]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=360</guid>
		<description><![CDATA[This article will cover the basics of DOTNetFactory with QTP and demonstrate the technique of adding a CheckBox Control to a Custom Form.]]></description>
			<content:encoded><![CDATA[<p></p><p>This is the 4th article in the DOTNetFactory Series. The first 3 articles cover the basics of creating a user form and adding a control to it. This article will be a little more fast-paced and will cover how to create a Custom form and add a CheckBox control to it.</p>
<p>Similar to creating a Form, a Text Box and a Button Control, we will use .CreateInstance to create a CheckBox Control as well.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oCheckBox <span style="color: #008000;">=</span> DOTNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.CheckBox&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Also, just like a Text Box and a Button, the CheckBox will have to be positioned somewhere in the form, thus, we will again define a Point object:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oPoint <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Drawing.Point&quot;</span>, <span style="color: #808080;">&quot;System.Drawing&quot;</span>, x, y<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0600FF;">With</span> oPoint
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
oCheckBox.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint</pre></div></div>

<p>Also, we must add some Text to the CheckBox so its easy to identify if we should check or, or keep it unchecked. It can be done by using the .Text method:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;">oCheckBox.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;CheckBox&quot;</span></pre></div></div>

<p class="custPostHeading">Putting it all together</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oForm <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Form&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Set</span> oButton <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Button&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Set</span> oCheckBox <span style="color: #008000;">=</span> DOTNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.CheckBox&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #FF8000;">Set</span> oPoint <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Drawing.Point&quot;</span>, <span style="color: #808080;">&quot;System.Drawing&quot;</span>, x, y<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'CheckBox Location</span>
<span style="color: #0600FF;">With</span> oPoint
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'CheckBox Properties</span>
<span style="color: #0600FF;">With</span> oCheckBox
	.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;CheckBox&quot;</span>
	<span style="color: #008080; font-style: italic;">'Give the checkbox a name property</span>
	.<span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;chkSample&quot;</span>
	.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Button Location</span>
<span style="color: #0600FF;">With</span> oPoint
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">50</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Button Properties</span>
<span style="color: #0600FF;">With</span> oButton
	.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint
	.<span style="color: #0600FF;">Width</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span>
	.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Close Form&quot;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">with</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Add Controls</span>
<span style="color: #0600FF;">With</span> oForm
	.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span> oCheckBox
	<span style="color: #008080; font-style: italic;">'Adding a Cancel Button</span>
	.<span style="color: #0000FF;">CancelButton</span> <span style="color: #008000;">=</span> oButton
	.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span> oButton
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">with</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Show Dialog</span>
oForm.<span style="color: #0000FF;">ShowDialog</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Output the entered Text:</span>
<span style="color: #0600FF;">MsgBox</span> <span style="color: #808080;">&quot;CheckBox Selected: &quot;</span> <span style="color: #008000;">&amp;</span> oCheckBox.<span style="color: #0000FF;">Checked</span></pre></div></div>

<p>Executing the code above will display a form control:</p>
<div class="wp-caption aligncenter" style="width: 300px">
	<a href="http://relevantcodes.com/Articles/DOTNetFactory/CheckBox/CheckBox.JPG"><img alt="DOTNetFactory: Adding a CheckBox" src="http://relevantcodes.com/Articles/DOTNetFactory/CheckBox/CheckBox.JPG" title="DOTNetFactory: Adding a CheckBox" width="300" height="300" /></a>
	<p class="wp-caption-text">DOTNetFactory: Adding a CheckBox</p>
</div>
<p>I had the checkbox in the &#8220;ON&#8221; position and after clicking the button, I received the following output from QTP:</p>
<div class="wp-caption aligncenter" style="width: 149px">
	<a href="http://relevantcodes.com/Articles/DOTNetFactory/CheckBox/QTPOutput.JPG"><img alt="Adding a CheckBox Control: QTP Output" src="http://relevantcodes.com/Articles/DOTNetFactory/CheckBox/QTPOutput.JPG" title="Adding a CheckBox Control: QTP Output" width="149" height="100" /></a>
	<p class="wp-caption-text">Adding a CheckBox Control: QTP Output</p>
</div>
<p>In the next topic in this series, we will learn how to create a CheckBox control using DOTNetFactory.</p>
<p>I hope you find this article useful.</p>
<p class="custPostHeading">In this Series</p>
<ol>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form/" >QTP &#038; DOTNetFactory &#8211; Creating a Custom Form</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-text-box-control/" >QTP &#038; DOTNetFactory &#8211; Adding a Text Box Control</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-button-control/" >QTP &#038; DOTNetFactory &#8211; Adding a Button Control</a></li>
<li>QTP &#038; DOTNetFactory &#8211; Adding a CheckBox Control <i>{Currently viewing}</i></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form-with-multiple-objects/">QTP &#038; DOTNetFactory &#8211; Creating a Custom Form with Multiple Objects</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-6-adding-a-radiobutton-control/" >QTP &#038; DOTNetFactory &#8211; Adding a RadioButton</a></li>
<li>QTP &#038; DOTNetFactory &#8211; Adding a ComboBox &#8211; Coming Soon!</li>
</ol>
<p class="alert">If you have any questions, please ask them in the comments section. If your information is to be treated as confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/qtp-dotnetfactory-adding-a-checkbox-control/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>QTP DOTNetFactory (3): Adding a Button Control</title>
		<link>http://relevantcodes.com/qtp-dotnetfactory-adding-a-button-control/</link>
		<comments>http://relevantcodes.com/qtp-dotnetfactory-adding-a-button-control/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 00:03:24 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[DOTNetFactory]]></category>
		<category><![CDATA[QTP]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=358</guid>
		<description><![CDATA[This article will cover the basics of DOTNetFactory with QTP and demonstrate the technique of adding a Button Control to a Custom Form.]]></description>
			<content:encoded><![CDATA[<p></p><p>The last 2 articles in this series discussed creation of a <a href="http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form/">Custom Form</a> and addition of a <a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-text-box-control/">Text Box Control</a> to the form. This article shows how to add a Button control to the form using DOTNetFactory. Since most of the basics have been discussed in the previous articles, this one will be quite fast-paced.</p>
<p>Similar to creating a Form and Text Box, we will use .CreateInstance to create a Button Control.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oButton <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Button&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Also, just like a Text Box, the button will have to be positioned somewhere in the form, thus, we will again define a Point object:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oPoint <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Drawing.Point&quot;</span>, <span style="color: #808080;">&quot;System.Drawing&quot;</span>, x, y<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0600FF;">With</span> oPoint
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">50</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
oButton.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint</pre></div></div>

<p>When adding a Button, you might also want to add some Text to it, so its easily distinguishable:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;">oButton.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Close Form&quot;</span></pre></div></div>

<p>In this example, the button we are adding will be a <i>Cancel</i> button type that will exit the form once clicked.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;">oForm.<span style="color: #0000FF;">CancelButton</span> <span style="color: #008000;">=</span> oButton</pre></div></div>

<p class="custPostHeading">Putting it all together</p>
<p>Let&#8217;s add a <a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-text-box-control/" >Text Box Control</a>, and use QTP to output the entered Text using MsgBox.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oForm <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Form&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Set</span> oButton <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Button&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Set</span> oText <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.TextBox&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #FF8000;">Set</span> oPoint <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Drawing.Point&quot;</span>, <span style="color: #808080;">&quot;System.Drawing&quot;</span>, x, y<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Text Box</span>
<span style="color: #0600FF;">With</span> oPoint
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #0600FF;">With</span> oText
	.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint
	.<span style="color: #0600FF;">Width</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Button</span>
<span style="color: #0600FF;">With</span> oPoint
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">50</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #0600FF;">With</span> oButton
	.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint
	.<span style="color: #0600FF;">Width</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span>
	.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Close Form&quot;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">with</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Add Controls</span>
<span style="color: #0600FF;">With</span> oForm
	.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span> oText
	<span style="color: #008080; font-style: italic;">'Adding a Cancel Button</span>
	.<span style="color: #0000FF;">CancelButton</span> <span style="color: #008000;">=</span> oButton
	.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span> oButton
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">with</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Show Dialog</span>
oForm.<span style="color: #0000FF;">ShowDialog</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Output the entered Text:</span>
<span style="color: #0600FF;">MsgBox</span> oText.<span style="color: #0000FF;">Text</span></pre></div></div>

<p>Executing the code above will display a form control:</p>
<div class="wp-caption aligncenter" style="width: 300px">
	<a href="http://relevantcodes.com/Articles/DOTNetFactory/Button/Button.JPG"><img alt="Adding a Button Control to a Custom Form" src="http://relevantcodes.com/Articles/DOTNetFactory/Button/Button.JPG" title="Adding a Button Control to a Custom Form" width="300" height="300" /></a>
	<p class="wp-caption-text">Adding a Button Control to a Custom Form</p>
</div>
<p>I entered <i>Relevant Codes</i> in the text box and clicked the button to get the following output from QTP:</p>
<div class="wp-caption aligncenter" style="width: 104px">
	<a href="http://relevantcodes.com/Articles/DOTNetFactory/Button/QTPOutput.JPG"><img alt="Button Control Example: QTP Output" src="http://relevantcodes.com/Articles/DOTNetFactory/Button/QTPOutput.JPG" title="Button Control Example: QTP Output" width="104" height="100" /></a>
	<p class="wp-caption-text">Button Control Example: QTP Output</p>
</div>
<p>In the next topic in this series, we will learn how to create a CheckBox control using DOTNetFactory.</p>
<p>I hope you find this article useful.</p>
<p class="custPostHeading">In this Series</p>
<ol>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form/" >QTP &#038; DOTNetFactory &#8211; Creating a Custom Form</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-text-box-control/" >QTP &#038; DOTNetFactory &#8211; Adding a Text Box Control</a></li>
<li>QTP &#038; DOTNetFactory &#8211; Adding a Button Control <i>{Currently viewing}</i></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-checkbox-control/" >QTP &#038; DOTNetFactory &#8211; Adding a CheckBox Control</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form-with-multiple-objects/">QTP &#038; DOTNetFactory &#8211; Creating a Custom Form with Multiple Objects</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-6-adding-a-radiobutton-control/" >QTP &#038; DOTNetFactory &#8211; Adding a RadioButton</a></li>
<li>QTP &#038; DOTNetFactory &#8211; Adding a ComboBox &#8211; Coming Soon!</li>
</ol>
<p class="alert">If you have any questions, please ask them in the comments section. If your information is to be treated as confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/qtp-dotnetfactory-adding-a-button-control/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>QTP DOTNetFactory (2): Adding a Text Box Control</title>
		<link>http://relevantcodes.com/qtp-dotnetfactory-adding-a-text-box-control/</link>
		<comments>http://relevantcodes.com/qtp-dotnetfactory-adding-a-text-box-control/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 00:01:37 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[DOTNetFactory]]></category>
		<category><![CDATA[QTP]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=356</guid>
		<description><![CDATA[This article will cover the basics of DOTNetFactory with QTP and demonstrate the technique of adding a TextBox Control to a Custom Form.]]></description>
			<content:encoded><![CDATA[<p></p><p>In this article, we will discuss how to add the Text Box control to the user form we created in the previous article, <a href="http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form/" >Creating a Custom Form</a>. CreateInstance has also been discussed in the <a href="http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form/">previous article</a>, and just like a Form, we will use .CreateInstance again for the Text Box control.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oText <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.TextBox&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Above, the TypeName is System.Windows.Forms.TextBox. This means, just like the Form Control, a TextBox is also a part of the System.Windows.Forms namespace. Unlike the Form Control however, we cannot use .Show and .ShowDialog methods. Instead, we will insert the Text Box in the Form Control.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oForm <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Form&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Set</span> oText <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.TextBox&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
oForm.<span style="color: #0000FF;">ShowDialog</span></pre></div></div>

<p>After executing the statements above, you will notice that the text box didn&#8217;t appear in the Form? Well, that is because even though we created an edit box object, we have not yet added it to the Form (oForm) Control. We have not even defined the size and where it will be located on the form. Before we add the oText objec to the form, we must first understand the System.Drawing namespace.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oPoint <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Drawing.Point&quot;</span>, <span style="color: #808080;">&quot;System.Drawing&quot;</span>, x, y<span style="color: #000000;">&#41;</span></pre></div></div>

<p>Now, oPoint will enable us to place individual controls to be added to the form on given <i>x</i> and <i>y</i> coordinates. Below is a demonstration of how to place the Text Box control 20 points from the left, and 20 points to the top of the form:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oPoint <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Drawing.Point&quot;</span>, <span style="color: #808080;">&quot;System.Drawing&quot;</span>, x, y<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0600FF;">With</span> oPoint
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Our Text Control will now have the coordinates added above</span>
oText.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint</pre></div></div>

<p>and executing the following statement will add the Text Box control to the form:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;">oForm.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span> oText</pre></div></div>

<p>When we add the Text Box control to the form, it will be placed on the stated <i>x</i> and <i>y</i> coordinates. Finally, when we put all the pieces together, we will have the following code and form:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oForm <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Form&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Set</span> oText <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.TextBox&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'System.Drawing.Point Instance</span>
<span style="color: #FF8000;">Set</span> oPoint <span style="color: #008000;">=</span> DotNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Drawing.Point&quot;</span>, <span style="color: #808080;">&quot;System.Drawing&quot;</span>, x, y<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Text Box Location </span>
<span style="color: #0600FF;">With</span> oPoint
	.<span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
	.<span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Text Box Properties</span>
<span style="color: #0600FF;">With</span> oText
	.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> oPoint
	.<span style="color: #0600FF;">Width</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">With</span>
&nbsp;
oForm.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span> oText
&nbsp;
oForm.<span style="color: #0000FF;">ShowDialog</span></pre></div></div>

<p>Form:</p>
<div class="wp-caption aligncenter" style="width: 300px">
	<a href="http://relevantcodes.com/Articles/DOTNetFactory/TextBox/TextBox.JPG"><img alt="Text Box Control added to a Custom Form" src="http://relevantcodes.com/Articles/DOTNetFactory/TextBox/TextBox.JPG" title="Text Box Control added to a Custom Form" width="300" height="300" /></a>
	<p class="wp-caption-text">Text Box Control added to a Custom Form</p>
</div>
<p>In the next topic in this series, we will learn how to create and add a Button control using DOTNetFactory.</p>
<p>I hope you find this article useful.</p>
<p class="custPostHeading">In this Series</p>
<ol>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form/" >QTP &#038; DOTNetFactory &#8211; Creating a Custom Form</a></li>
<li>QTP &#038; DOTNetFactory &#8211; Adding a Text Box Control <i>{Currently viewing}</i></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-button-control/" >QTP &#038; DOTNetFactory &#8211; Adding a Button Control</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-checkbox-control/" >QTP &#038; DOTNetFactory &#8211; Adding a CheckBox Control</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form-with-multiple-objects/">QTP &#038; DOTNetFactory &#8211; Creating a Custom Form with Multiple Objects</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-6-adding-a-radiobutton-control/" >QTP &#038; DOTNetFactory &#8211; Adding a RadioButton</a></li>
<li>QTP &#038; DOTNetFactory &#8211; Adding a ComboBox &#8211; Coming Soon!</li>
</ol>
<p class="alert">If you have any questions, please ask them in the comments section. If your information is to be treated as confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/qtp-dotnetfactory-adding-a-text-box-control/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>QTP DOTNetFactory (1): Creating a Custom Form</title>
		<link>http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form/</link>
		<comments>http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 00:44:35 +0000</pubDate>
		<dc:creator>Anshoo Arora</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[DOTNetFactory]]></category>
		<category><![CDATA[QTP]]></category>
		<category><![CDATA[DotNetFactory Custom Form]]></category>

		<guid isPermaLink="false">http://relevantcodes.com/?p=333</guid>
		<description><![CDATA[In this series of articles, we will discover how to use the DOTNetFactory to create a user form and how to add different object types to it. ]]></description>
			<content:encoded><![CDATA[<p></p><p>Recently, I worked on a requirement in which I was asked to create a custom user-form that lets users choose how they want automated tests to be run. I first thought of creating a windows application using VB.NET, but, after some consideration I decided to use DOTNetFactory instead. This was quite a good choice since I did not need Visual Basic or Visual Studio installed on the PC where I develop my framework. In this series of articles, we will discover how to use the DOTNetFactory to create a user form and how to add different object types to it.</p>
<p>When we use DOTNetFactory, we must first create a COM interface using the CreateInstance method. This interface is passed as an argument (object) which has several methods that we&#8217;re going to use in this series.</p>
<p>According to book Scripting QTP, Chapter 14, by Dani Vainstein, the syntax for creating an instance of .NET is:</p>
<blockquote><p>
Set var_CreateInstance = DOTNetFactory.CreateInstance (TypeName [,Assembly] [,args])
</p></blockquote>
<blockquote><p>
TypeName: The full name of the object type, for example, System.Windows.Forms.Form.
</p></blockquote>
<blockquote><p>
Assembly: Optional. If the assembly is preloaded in the registry, you do not need to enter it. Otherwise, you should enter the full path name, for example, System.Windows.Forms. If you want to create an instance of a type in the GAC (Global Assembly Cache), you can enter the short name, for example, Forms.
</p></blockquote>
<blockquote><p>
args: Optional. The required arguments, if any, for the specified TypeName and/or Assembly
</p></blockquote>
<p>Let&#8217;s use .CreateInstance to create a simple user form using System.Windows.Forms.Form as the TypeName. A Form object in .NET is part of the System.Windows.Forms namespace. .NET namespaces are beyond the scope of this article, and will be discussed in detail in an upcoming article on VB.NET.</p>
<p>In QTP, we can retrieve the COM interface created by the .CreateInstance method using the &#8216;Set&#8217; statement:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oForm <span style="color: #008000;">=</span> DOTNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Form&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>We have just created a user form using DOTNetFactory!</p>
<p>You might wonder though, if we have really created a user form, where is it? Why doesn&#8217;t it display when we execute the above statement? That is because, as I mentioned earlier that the returned COM interface will have several methods. The above form has .Show and .ShowDialog methods which enable the form to be displayed:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oForm <span style="color: #008000;">=</span> DOTNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Form&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
oForm.<span style="color: #0000FF;">Show</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:consolas, monospace;"><span style="color: #FF8000;">Set</span> oForm <span style="color: #008000;">=</span> DOTNetFactory.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;System.Windows.Forms.Form&quot;</span>, <span style="color: #808080;">&quot;System.Windows.Forms&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'Adds a title to the form</span>
oForm.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Sample Custom Form&quot;</span>
&nbsp;
oForm.<span style="color: #0000FF;">ShowDialog</span></pre></div></div>

<div class="wp-caption aligncenter" style="width: 300px">
	<a href="http://relevantcodes.com/Articles/DOTNetFactory/CustomForm/Form.JPG"><img alt="An Empty Form" src="http://relevantcodes.com/Articles/DOTNetFactory/CustomForm/Form.JPG" title="An Empty Form" width="300" height="300" /></a>
	<p class="wp-caption-text">An Empty Form</p>
</div>
<p>Both methods will display the form on your desktop. However, there is a slight difference between the two. When you execute <i>oForm.Show</i>, you will note that the form will be displayed and the test executing will immediately move on to the next line. However, with <i>oForm.ShowDialog</i>, QTP will wait until we perform an event on the form before execution moves on to the next statement in our test. This is the method we&#8217;re interested in, because we will be provided QTP with several inputs using these form. In this series, we will be using .ShowDialog extensively.</p>
<p>In the next topic in this series, we will learn how to create a Text Box using DOTNetFactory.</p>
<p>I hope you find this article useful.</p>
<p class="custPostHeading">References</p>
<ol>
<li><a href="http://www.advancedqtp.com/wp-content/uploads/ScriptingQTP/Scripting%20QTP%20-%20CH14%20-%20DotNetFactory.pdf">Scripting QTP by Dani Vainstein &#8211; Chapter 14 &#8211; DOTNetFactory</a></li>
</ol>
<p class="custPostHeading">In this Series</p>
<ol>
<li>QTP &#038; DOTNetFactory &#8211; Creating a Custom Form <i>{Currently viewing}</i></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-text-box-control/" >QTP &#038; DOTNetFactory &#8211; Adding a Text Box Control</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-button-control/" >QTP &#038; DOTNetFactory &#8211; Adding a Button Control</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-adding-a-checkbox-control/" >QTP &#038; DOTNetFactory &#8211; Adding a CheckBox Control</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form-with-multiple-objects/">QTP &#038; DOTNetFactory &#8211; Creating a Custom Form with Multiple Objects</a></li>
<li><a href="http://relevantcodes.com/qtp-dotnetfactory-6-adding-a-radiobutton-control/" >QTP &#038; DOTNetFactory &#8211; Adding a RadioButton</a></li>
<li>QTP &#038; DOTNetFactory &#8211; Adding a ComboBox &#8211; Coming Soon!</li>
</ol>
<p class="alert">If you have any questions, please ask them in the comments section. If your query is confidential, please use the <a href="http://relevantcodes.com/contact/">Contact Form</a> to send me an e-mail instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://relevantcodes.com/qtp-dotnetfactory-creating-a-custom-form/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

