Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automation like in VBS won't work in VFP

Status
Not open for further replies.

JackTheC

Programmer
Feb 25, 2002
325
NL
I want to set the focus and the cursor in a specific inputbox of a website. Example Ebay's login.

In a VBS script that will work with something like this code:

Code:
Set ie = CreateObject("InternetExplorer.Application")
ie.navigate "[URL unfurl="true"]https://signin.ebay.com/ws/eBayISAPI.dll?SignIn&ru=http%3A%2F%2Fwww.ebay.com%2F"[/URL]
ie.Visible = True

do while ie.readystate<>4
loop

ie.document.getElementbyId("pass").focus()
ie.document.getElementbyId("pass").select()

The same kind of code in VFP won't work. No errors but the focus stays in the default field.

Code:
ieo=createobject("InternetExplorer.Application")
ieo.navigate("[URL unfurl="true"]https://signin.ebay.com/ws/eBayISAPI.dll?SignIn&ru=http%3A%2F%2Fwww.ebay.com%2F")[/URL]
ieo.visible=.t.

do while ieo.readystate<>4
     =inkey(0.1)
enddo

ieo.document.getElementbyId("pass").focus()
ieo.document.getElementbyId("pass").select()

How come? And is it possible to let it work properly directly in VFP? Of course I can execute a VBS from within VFP with ShellExecute but is it possible to make the above VFP code work?
 
Obviously there is a difference between objects created within VFP with CreateObject() and objects created within VBScript(VBS file) with CreateObject().

The VFP code in the first entry of this topic did only work on machines with IE8 (Don't know about IE7 and older). Yesterday I had a testmachine with Win7/IE8 and the VFP code ran OK. Than I updated only IE to IE11, and focus() and select() in de VFP code did not work anymore. That is consistent with my earlier findings (IE8,IE9,IE10) and the results of Mike(IE8) and Olaf(IE11). So something has changed in IE9 and up regarding to VFP-like code. But focus() and select() in VBS are still working in IE9, IE10, IE11.

Next I created a Test.vbs script

Code:
on error resume next

p1=wscript.arguments.item(0)
p2=wscript.arguments.item(1)
p3=wscript.arguments.item(2)

Set IE = CreateObject("InternetExplorer.Application")
IE.navigate p1
IE.Visible = True

Set objShell = CreateObject("WScript.Shell")
objShell.AppActivate IE

do while IE.readystate<>4
loop

IE.document.getElementbyId(p2).focus()
IE.document.getElementbyId(p2).value=p3

' to select the field, put this after the value setting
' ie.document.getElementbyId(p2).select()

And this is an Ebay example of the VFP Code: (Remember this topic is not about Ebay. This is merely an example of A website)

Code:
lcfile='test.vbs'

DECLARE INTEGER ShellExecute IN SHELL32.dll ; 
INTEGER nWinHandle, ; 
STRING cOperation, ; 
STRING cFileName, ; 
STRING cParameters, ; 
STRING cDirectory, ; 
INTEGER nShowWindow

par='[URL unfurl="true"]https://signin.ebay.com/ws/eBayISAPI.dll[/URL] pass testpass'

ShellExecute(0,"Open",lcfile, par, '', 0)

And Eureka, the code works on IE9 and up from within VFP via a VBS script. But I still don't know why there is a difference between the two CreateObjects (VFP versus VBS) ....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top