Saturday, 6 August 2011

(Dot net factory) Now create radio button in windows form


Set MyRadioButton1 = DotNetFactory.CreateInstance("System.Windows.Forms.RadioButton", "System.Windows.Forms")

Check the following example :

Set MyForm = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
Set MyRadioButton1 = DotNetFactory.CreateInstance("System.Windows.Forms.RadioButton", "System.Windows.Forms")
Set MyRadioButton2 = DotNetFactory.CreateInstance("System.Windows.Forms.RadioButton", "System.Windows.Forms")
Set MyButton = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
Set Pos = DotNetFactory.CreateInstance("System.Drawing.Point","System.Drawing",x,y)
With Pos
.X = 90
.Y = 100
End With
With MyRadioButton1
.Location = Pos
.Text = "Option 1"
.Name = "optRadioButton1"
End With
With Pos
.X = 90
.Y = 130
End With
With MyRadioButton2
.Location = Pos
.Text = "Option 2"
.Name = "optRadioButton1"
End With
With Pos
.X = 90
.Y = 160
End With
With MyButton
.Location = Pos
.Text = "Close"
End With
With MyForm
.Controls.Add MyRadioButton1
.Controls.Add MyRadioButton2
.Controls.Add MyButton
.CancelButton = MyButton
.Text = "My Custom User Form"
.ShowDialog
End With
If MyRadioButton1.Checked Then
msgbox "You have selected - Option 1"
elseif MyRadioButton2.Checked then
msgbox "You have selected - Option 2"
else
msgbox "No Options Selected"
End If
Set MyRadioButton1 = Nothing
Set MyRadioButton2 = Nothing
Set Button = Nothing
Set Pos = Nothing
Set MyForm = Nothing



(Dot net factory) Now check checkbox with a button and passing the controls accordingly


Set Form = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
Set Checkbox = DotNetFactory.CreateInstance("System.Windows.Forms.CheckBox", "System.Windows.Forms")
Set Pos = DotNetFactory.CreateInstance("System.Drawing.Point","System.Drawing",x,y)
Set Button = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
With Pos
.X = 90
.Y = 100
End With
With CheckBox
.Location = Pos
.Text = "My Check Box"
.Name = "chkCheckBox"
End With
With Pos
.X = 100
.Y = 130
End With
With Button
.Location = Pos
.Text = "Close"
End With
With Form
.Controls.Add CheckBox
.Controls.Add Button
.CancelButton = Button
.Text = "My Custom User Form"
.ShowDialog
End With
If CheckBox.Checked then
         msgbox "Check box Checked"
         else
        msgbox "Check box unchecked"
end if
Set CheckBox = Nothing
Set Button = Nothing
Set Pos = Nothing
Set Form = Nothing


If check box checked then

If checked box not checked 



(Dot net factory) Now Create Checkbox in windows form


Using following class
Set Checkbox = DotNetFactory.CreateInstance("System.Windows.Forms.CheckBox", "System.Windows.Forms")

Form With checkbox

Set Form = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
Set Checkbox = DotNetFactory.CreateInstance("System.Windows.Forms.CheckBox", "System.Windows.Forms")
Set Pos = DotNetFactory.CreateInstance("System.Drawing.Point","System.Drawing",x,y)
With Pos
.X = 90
.Y = 100
End With
With CheckBox
.Location = Pos
.Text = "My Check Box"
.Name = "chkCheckBox"
End With
With Form
.Controls.Add CheckBox
.Text = "My Custom User Form"
.ShowDialog
End With
Set CheckBox = Nothing
Set Pos = Nothing
Set Form = Nothing

Output will be as follows


(Dot net factory) Now we are having a form having textbox ,button and what ever the value we will give in the text box will display in the msgbox


Set Form = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
Set Text = DotNetFactory.CreateInstance("System.Windows.Forms.TextBox", "System.Windows.Forms")
Set Button = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
Set Pos = DotNetFactory.CreateInstance("System.Drawing.Point","System.Drawing",x,y)
Pos.X = 90
Pos.Y = 100
Text.Location = Pos
Text.Width = 100
Pos.X = 100
Pos.Y = 130
Button.Location = Pos
Button.Text = "Close"
Form.Controls.Add Text
Form.Controls.Add Button
Form.CancelButton = Button
Form.ShowDialog
Msgbox Text.Text
Set Text = Nothing
Set Button = Nothing
Set Pos = Nothing
Set Form = Nothing

Msgbox display will be


Add text box control to the forms : (Dot net factory)



Set Form = DotNetFactory.CreateInstance("System.Windows.Forms.Form","System.Windows.Forms")
Set Text = DotNetFactory.CreateInstance("System.Windows.Forms.TextBox", "System.Windows.Forms")
Form.Controls.Add Text
Form.ShowDialog






Now we can change the position using (DotNetFactory.CreateInstance("System.Drawing.Point","System.Drawing",x,y)) class

Set Pos = DotNetFactory.CreateInstance("System.Drawing.Point","System.Drawing",x,y)
Pos.X = 10
Pos.Y = 20
Text.Location = Pos




So the full code for the text box a required position will be :

Set Form = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
Set Text = DotNetFactory.CreateInstance("System.Windows.Forms.TextBox", "System.Windows.Forms")
Set Pos = DotNetFactory.CreateInstance("System.Drawing.Point","System.Drawing",x,y)
Pos.X = 100
Pos.Y = 100
Text.Location = Pos
Text.Width = 150
Form.Controls.Add Text
Form.ShowDialog



Two controls on the same forms :(Dot Net Factory)


Set Form = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
Set Button1 = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
Set Button2 = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
Set dResult = DotNetFactory.CreateInstance("System.Windows.Forms.DialogResult", "System.Windows.Forms")
Set Pos = DotNetFactory.CreateInstance("System.Drawing.Point","System.Drawing",x,y)
With Pos
.X = 50
.Y = 100
End With
With Button1
.Text = "Close"
.Location = Pos
.DialogResult = dResult.Cancel
End With
With Pos
.X = 150
.Y = 100
End With
With Button2
.Text = "OK"
.Location = Pos
.DialogResult = dResult.OK
End With
With Form
.Controls.Add Button1
.Controls.Add Button2
.Text = "My Custom User Form"
.ShowDialog
End With
If Form.DialogResult = dResult.OK Then
  msgbox "OK Button Pressed"
else
  msgbox "Close Button Pressed"
End If
Set Form = Nothing
Set Button1 = Nothing
Set Button2 = Nothing
Set dResult = Nothing
Set Pos = Nothing


If click on OK then it will launch the following msgbox



If click on close button then it will through following msgbox 




Friday, 5 August 2011

Get Transaction time of QTP Script

1.Using QTP feature StartTransaction and EndTransaction given in the Insert toolbar options

Services.StartTransaction "str"
msgbox "I"
msgbox "am"
msgbox "Learning"
msgbox "QTP"
Services.EndTransaction "str"

2.Using MercuryTimers Function and we can give any thing in place of time in the following code it will give total time taken in seconds . 

MercuryTimers("Time").Start
  msgbox "I"
msgbox "am"
msgbox "Learning"
msgbox "QTP"
  TimeTaken=MercuryTimers("Time").Elapsedtime
       msgbox TimeTaken

3.Using Vbs will not heve any dependency on QTP what we need to do over here is we just need to the Hour,minute and second from the time and manipulate it to get the total trasaction time .

StartHour = Hour(now)
StartMin = Minute(now)
StartSec = Second(now)
msgbox "I"
msgbox "am"
msgbox "Learning"
msgbox "QTP"

EndHour = Hour(now)
EndMin = Minute(now)
EndSec = Second(now)
StartingSeconds = (StartSec + (StartMin * 60) + (StartHour * 60))
EndingSeconds = (EndSec + (EndMin * 60) + (EndHour * 60))
CallTimeSeconds = EndingSeconds - StartingSeconds
MsgBox CallTimeSeconds