Micro Focus QTP (UFT) Forums
Alternative to using .SetSelection - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Alternative to using .SetSelection (/Thread-Alternative-to-using-SetSelection)



Alternative to using .SetSelection - janriis - 11-23-2009

Hi all

When testing a VB6 application, I am using .SetSelection to select all text in a vbedit object and replacing with new value.

For some reason, the .SetSelection often fails and my script stops due to wrong value in the vbedit object.

Is there another way to select or even better, clear the values of a vbedit object ?


RE: Alternative to using .SetSelection - upadhyay40 - 11-23-2009

Code:
Dim EditToSearch
EditToSearch = "cc"
EditValueToSet = "urvalue"


'Create a description object to help retrieve all WebEdit objects in a specific page.
Set toDesc = Description.Create()
    toDesc("micclass").Value = "WebEdit"
    toDesc("html id").Value = "f"
    toDesc("html tag").Value = "g"
    toDesc("name").Value = "i"

'Retrieve all WebEdit objects in this page
Set EditCollection =Browser("title:=f").Page("title:=g.*").ChildObjects(toDesc)

NumberOfEdits = EditCollection.Count

'Search for a specific Linkobject and set its value
For i = 0 To NumberOfEdits - 1
    If EditCollection(i).GetROProperty("name") = EditToSearch Then
       EditCollection(i).Set EditValueToSet
           End If
Next

hi jnariss,

you need to just change your micclass as per you VBedit and try above code you an get your answer, please let me know if you need more help from my end

Thanks
Mahesh


RE: Alternative to using .SetSelection - janriis - 11-23-2009

Hi Mahesh

My app is not a web app, but a windows application written in VB6.0. What i need is a way to clear a vbedit field before entering new text.

Example. in my vbedit field "txtAge" i have the default value 65. My new value is 40. If i just just .type "40", the default value wont be erased.

Using setSelection 0,0,0,2 works sometimes, but is not reliable.


RE: Alternative to using .SetSelection - jsknight1969 - 11-24-2009

Did you try:
Code:
Vbedit("txtAge").Set "1"     <--- just to set focus to field
VbEdit("txtAge").Type micBack  <---backspace
Vbedit("txtAge").Set "40"   <----real value

You might also try using:
Code:
'use tab to get to the txtAge field
Vbedit("AnotherObject").Type micTab + micTab
Vbedit("txtAge").Type micBack
Vbedit("txtAge").Type "40"

Hope this works.


RE: Alternative to using .SetSelection - v_selvam - 11-24-2009

Try this.

Code:
text = VbWindow("Form1").VbEdit("Text1").getROProperty("text)
iLen = Len(text )
VbWindow("Form1").VbEdit("Text1").SetSelection 0, iLen
VbWindow("Form1").VbEdit("Text1").Set 40



RE: Alternative to using .SetSelection - Saket - 11-25-2009

an alternative of SetSelection could be using 'SendKeys'
try this
Code:
'Set Focus on edit box
VbWindow(" ").VbEdit(" ").Click
'Create Wscript.shell object
Set WshShell = CreateObject("WScript.Shell")
'Select the text already there in edit box sending
WshShell.SendKeys "+{HOME}"
'set the rrequired text in edit box using either of these two statements
WshShell.SendKeys "Your Text"
'Or
'VbWindow(" ").VbEdit(" ").Set "Your Text"



RE: Alternative to using .SetSelection - janriis - 12-08-2009

Thx for your input guys. For some reason, neither of above worked and my vbedit field was not cleared.


RE: Alternative to using .SetSelection - Saket - 12-09-2009

Can you paste what you have tried so far?


RE: Alternative to using .SetSelection - janriis - 12-09-2009

Hi Saket.

I've tried all of the above and all I did was changing the code to correspond to my objects. Still none of the solution worked.

What did work was using .setSelection 0,0 and then adding a handful of lines with .type micDel

This is not the best way to do it, but due to lack of time, I have to go with this solution