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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

_web object interaction

Status
Not open for further replies.

cmbazan

IS-IT--Management
Jul 12, 2010
4
MX
Hi everybody,

I'm programming an app in which I launch web pages and browse them on a VFP 9.0 form usign a "_web" (VFP distribution) class object.

Now, due to my requirements, I need to COPY certain text (phone numbers) from the page I'm browsing and PASTE it in a DBF field (in the case you have not guessed, I need to associate each URL to a phone number).

In order to increase productivity (# of phone numbers captured) I'd like to automate copying & pasting this text through a shortcut by capturing an event (ON KEY LABEL ALT+V...) for later COPYing and "pasting" the text that I need by means of _cliptext:

KEYBOARD '{CTRL+c}'
phoneNumber = _cliptext


My problem is that apparently, KEYBOARD '{CTRL+c}' is not working properly programatically on the _web object on the page I'm browsing, although if I do it interactively it works fine.

Any sugestion?
 
My problem is that apparently, KEYBOARD '{CTRL+c}' is not working properly programatically on the _web object on the page I'm browsing

It's not the Ctrl+C that's not working. It's the KEYBOARD. The KEYBOARD command can only send keystrokes within VFP. It can't send them to an external object like a browser control.

Have you got some way of programmatically recognising these phone numbers? Perhaps they're all formatted in a certain way? Or they are the only text strings on the page that consist of exactly so-many digits?

If so, you might find it easier to parse the underlying HTML. You can access that from the control's cSourceHTML property. If you can identify the phone number within the HTML, just copy it out to a variable (using STREXTRACT() perhaps), and then insert that into the table (with REPLACE).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thank you for the idea Mike! I would give it a try, using regular expressions (oRE = CREATEOBJECT("VBScript.RegExp"))

I'll still need human interaction with web pages, in order to recognize if the page he/she's browsing may contain a phone number pattern (he/she may face a Flash only page in which there's no phone number pattern).

So, I'll add a button (or alike) to allow the operator to scan a phone number thru its regular expression on the explored page.

Meanwhile if someone else has another idea over my original programming draft, I'd like to hear it too.
 
If you are happy for the user to visually examine the page to identify a phone number, you could always go back to your original plan, but instead of using KEYBOARD, do something like this.

1. In the Init of the form:

Code:
THIS.oWSH = CREATEOBJECT("wscript.shell")

2. Place a button on the form. In its Click:

Code:
thisform.WebBrowser.SetFocus 
  && WebBrowser is the name of your browser control
thisform.oWSH.SendKeys("^c")
  && Sends Ctrl+C to the web browser

3. At run time, navigate to the page; highlight the phone number; click the button

I think this is similar to your original approach, except it uses the Windows Scripting Host's SendKeys as an alternative to VFP's KEYBOARD.

I haven't tested this, but it should give the general idea.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Cmbazan,

I don't if you've had time to try my SendKeys suggestion. I'd be interested to know if it works.

In the meantime, I just came across this script that might solve your problem:


It's essentially a bit of Javascript that you add to your web page. It would only be useful if you have control over the pages that contain the telephone numbers (which I guess you haven't, otherwise you wouldn't need to copy and paste). Also, it only seems to work in IE.

But it might give you some other ideas for solving the problem.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thank you for your interest Mike,

I tried out your suggestion on Windows WSH's Sendkeys as alternative but it didn't work out: it behaves the same way VFP's Keyboard command. :(.

I'm still working on the regular expression idea, but finding an "universal" pattern has been dificult.

Let me check the link your suggesting me.

Once again, thanks.
 
Cmbazan,

I'm surprised Sendkeys didn't work. I just tried it myself, and it worked fine.

But if you can parse the HTML with a regular expression, that would be a better solution. You can make the whole thing automatic.

Let us know how you get on.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
You're right Mike,

I was also surprised it didn't work. I tried it on a Win XP Pro + SP3 PC with VFP 9.0 installed (w/o service pack). Would be the execution environment a cause?
 
No, I doubt that the environment would make a difference. If you don't get an error when instantiating "wscript.shell", the rest of it should work fine.

Are you sure the browser control had focus at that point? If, for any reason, there's a delay in giving it focus, it might be necessary to pause for a few hundred milliseconds just before you send the keys. But that's a bit of a long shot.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top