Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alternative to using .SetSelection
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
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 ?
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply
#3
Solved: 11 Years, 3 Months, 3 Weeks ago
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.
Reply
#4
Solved: 11 Years, 3 Months, 3 Weeks ago
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.
Reply
#5
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply
#6
Solved: 11 Years, 3 Months, 3 Weeks ago
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"

Reply
#7
Solved: 11 Years, 3 Months, 3 Weeks ago
Thx for your input guys. For some reason, neither of above worked and my vbedit field was not cleared.
Reply
#8
Solved: 11 Years, 3 Months, 3 Weeks ago
Can you paste what you have tried so far?

Reply
#9
Solved: 11 Years, 3 Months, 3 Weeks ago
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Alternative to Switch case- Multi Select with value match Aakansha_d 11 10,985 06-10-2008, 12:00 AM
Last Post: somisays

Forum Jump:


Users browsing this thread: 4 Guest(s)