Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, that article is good to show the power of DotNetFactory with QTP. However it's not a solution I would use to create forms. Especially if you are intending to have more than a couple of fields on that form. </p> <p>I would rather create the form using Visual Studio as it is much easier to create and maintain a form using a rich IDE, by mostly using point and click. It would only take about 5 minutes to create something like below. (If you don't have Visual Studio license, you can use SharpDevelop or Visual Studio Express).</p> <p>The example below is done in VB.Net, one can just as easily use C# or any other .net language they are more comfortable with. (Sorry, I wanted to add Visual Studio screenshots of the form to make this clearer but not able to do so as I'm new user on stackoverflow and don't have enough reputation)</p> <p>VB.Net Form Code Snippet:</p> <pre><code>Public Class EnvironmentDataForm Private strServerName As String Private strUsername As String Private strPassword As String Public Property DBServerName() As String Get DBServerName = strServerName End Get Set(ByVal value As String) strServerName = value TextBox_DBServer.Text = strServerName End Set End Property Public Property DBUsername() As String Get DBUsername = strUsername End Get Set(ByVal value As String) strUsername = value TextBox_DBUsername.Text = strUsername End Set End Property Private Sub CloseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click strServerName = TextBox_DBServer.Text strUsername = TextBox_DBUsername.Text strPassword = TextBox_DBPassword.Text Me.Close() End Sub End Class </code></pre> <p>I haven't gone into detail of explaining how to use Visual Studio (I'm sure there are lot's of sources for this on the net), but basically the steps you need to follow to create a solution for QTP that takes in user input from a nice looking for, are:</p> <ol> <li>Design a form and corresponding code in Visual Studio. (Note, choose a class library project rather than WinForms project, as you want to compile this into a dll afterwards)</li> <li>Load the library using DotNetFactory in QTP.</li> <li>Invoke the form in QTP using .ShowDialog().</li> <li>Use the properties values captured by the form.</li> </ol> <p>Corresponding QTP Code: </p> <pre><code>Set objEnvDataForm = DotNetFactory.CreateInstance(_ "EnvironmentData.EnvironmentDataForm",_ "C:\EnvironmentData.dll") 'This step will block QTP execution until the form is closed. 'Also, make sure the form is designed to save the field data before closing: ' See Button1_Click() in the .Net code above objEnvDataForm.Showdialog() strConnString = "DRIVER={Microsoft ODBC for Oracle};" &amp;_ "Server="&amp; objEnvDataForm.DBServername &amp;_ ";Uid="&amp; objEnvDataForm.DBUsername &amp;_ ";Pwd="&amp; objEnvDataForm.DBPassword Set objCon = CreateObject("ADODB.Connection") objCon.Open strConnString </code></pre> <p>Hope that helps. Let me know if you need any more info on any of the steps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload