Subject |
Re: Http: Response into my local software |
From |
Mervyn Bick <invalid@invalid.invalid> |
Date |
Mon, 18 Sep 2017 10:57:11 +0200 |
Newsgroups |
dbase.getting-started |
On 2017-09-18 5:17 AM, Michael wrote:
> Thanks Mervyn.
>
> I am using Dbase 11.3.0 and I am still finding a few funny things going on. I will give it another shot and lets see if i can get it working smoothly. One question, i see what your've entered for the connection string and driver but if I want to talk to the server on the web, what would I need to use as a connection string? Ip address? can you give me an example.
>
If you don't want to access the server directly you can use the
Microsoft ActiveX webbrowser control in a dBASE form as an interface.
The ActiveX control should be on your computer. To make it available to
dBASE open a form in the designer and from the File menu select Set up
ActiveX. Once you've moved the control to the righthand list it will be
available in the ActiveX tab of the Component Palette.
Once you've placed the ActiveX control on the form you can use its
nativeobject's navigate() method to to fetch the webpage.
function PUSHBUTTON1_onClick()
form.MICROSOFTWEBBROWSER1.nativeobject.navigate("http://www.whatever")
return
If you submit data (the data can be inserted and returned automatically
by your program) the server should return an answer page.
The HTML code of the displayed answer page is available
function PB_GETHTML_onClick
// Get page html to look at
// This works, but can be too much text for a msgbox !!
oDoc = form.microsoftwebbrowser1.nativeObject.document()
s = oDoc.body.innerHTML
// ?s
msgbox(s)
return
The following snippet was used to build an array which fetched the data
from a webpage. The fourth column of the array was populated with data
to return. The form I was working on returned some data but required
other fields to be completed. If you only want to retrieve data this
should do for you.
This code was used on a webpage using CSS so there was only one forms
object in the document object. If you are using frames there are
multiple forms and it gets more complicated as you have to deal with
each of them in turn.
function PB_CREATEINPUTDATA_onClick()
// build dataArray
oDoc = form.microsoftwebbrowser1.nativeObject.document()
oForms = oDoc.forms
oElements = oforms.item(0).elements
form.oElements = oElements
nCount = 0
for n = 0 to oElements.length -1
try
if trim(oElements.item(n).type ) <> 'hidden'
nCount ++
endif
catch(exception e)
endtry
next
form.nCount = nCount
form.dataArray = new array(nCount,4)
nCount = 1
for n = 0 to oElements.length - 1
try
if trim(oElements.item(n).type ) <> 'hidden'
form.dataArray[nCount,1] = trim(oElements.item(n).name)
form.dataArray[nCount,2] = trim(oElements.item(n).type)
form.dataArray[nCount,3] = trim(oElements.item(n).value)
nCount ++
endif
catch(exception e)
endtry
next
\\ class::getData()
\\ form.PB_INSERTDATA.enabled = true
\\ form.PB_DISPLAYARRAY.enabled = true
return
To insert data into the form first place the relevant data in the fourth
column of the dataArray.
function PB_INSERTDATA_onClick()
// insert data in form
oDoc = form.microsoftwebbrowser1.nativeObject.document()
oForms = oDoc.forms
oElements = oforms.item(0).elements
for n = 0 to oElements.length - 1
cName = oElements.item(n).getattribute('name')
cVal = oElements.item(n).getattribute('value')
for x = 1 to form.dataArray.size/4
if trim(cName) = form.dataArray[x,1] and trim(cVal) =
form.dataArray[x,3]
if oElements.item(n).getattribute('type') = 'radio' or
oElements.item(n).getattribute('type') = 'checkbox'
if not empty(form.dataArray[x,4])
oElements.item(n).setattribute('checked','true')
endif
else
if not empty(form.dataArray[x,4]) and
(empty(form.dataArray[x,3]) or form.dataArray[x,1] = 'AmountClaimed')
oElements.item(n).setattribute('value',
trim(form.dataArray[x,4]))
endif
endif
x = form.dataArray.size/4
endif
next
next
return
Mervyn.
|
|