Concatenate a varible into a method call

Concatenate a varible into a method call

Postby Rick Lipkin » Tue May 17, 2011 7:09 pm

To All

I am trying to insert the literal value of a character string into a method call ..

Example: this is the line I am trying to create
IE:document:forms:item(0):search:Value = cPARTS

cSFD := "document:forms:item(0):search"
IE:&cSFD:Value = cPARTS

The above fails and I can not use a plus (+) or macro (&) to concatenate or insert the variable into the method command ..

Any suggestions ?

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Concatenate a varible into a method call

Postby Gale FORd » Tue May 17, 2011 8:54 pm

Maybe you can create a block using macro compiler.
cSFD := "document:forms:item(0):search"
bSFD := &( "{ | cValue | IE:"+cSFD+":Value = cValue }" )
eval( bSFD, cPARTS )

Or maybe
cSFD := "document:forms:item(0):search"
bSFD := &( "{ || IE:"+cSFD+":Value = cPARTS }" )
eval( bSFD )
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Concatenate a varible into a method call

Postby Rick Lipkin » Wed May 18, 2011 12:56 pm

Gale

Thank you for your suggestions .. both options failed with

Variable does not exist: IE

Image

Application
===========
Path and name: C:\Fox\WebCrawl\WebCrawl.Exe (32 bits)
Size: 2,043,904 bytes
Time from start: 0 hours 0 mins 17 secs
Error occurred at: 05/18/2011, 08:30:51
Error description: Error BASE/1003 Variable does not exist: IE
Args:

Stack Calls
===========
Called from: Vendor1.prg => (b)_VENDOR1(85)
Called from: Vendor1.prg => _VENDOR1(86)
Called from: main.prg => SEARCH(390)
Called from: main.prg => (b)_SEARCH(347)
Called from: .\source\classes\BUTTON.PRG => TBUTTON:CLICK(176)
Called from: .\source\classes\CONTROL.PRG => TBUTTON:HANDLEEVENT(1427)
Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
Called from: => SENDMESSAGE(0)
Called from: .\source\classes\DIALOG.PRG => TDIALOG:COMMAND(407)
Called from: => TWINDOW:HANDLEEVENT(0)
Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT(928)
Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
Called from: => WINRUN(0)
Called from: .\source\classes\WINDOW.PRG => TWINDOW:ACTIVATE(966)
Called from: main.prg => MAIN(260)

and again in basically the same block

Image

Application
===========
Path and name: C:\Fox\WebCrawl\WebCrawl.Exe (32 bits)
Size: 2,043,904 bytes
Time from start: 0 hours 0 mins 14 secs
Error occurred at: 05/18/2011, 08:46:17
Error description: Error BASE/1003 Variable does not exist: IE
Args:

Stack Calls
===========
Called from: Vendor1.prg => (b)_VENDOR1(91)
Called from: Vendor1.prg => _VENDOR1(92)
Called from: main.prg => SEARCH(390)
Called from: main.prg => (b)_SEARCH(347)
Called from: .\source\classes\BUTTON.PRG => TBUTTON:CLICK(176)
Called from: .\source\classes\CONTROL.PRG => TBUTTON:HANDLEEVENT(1427)
Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
Called from: => SENDMESSAGE(0)
Called from: .\source\classes\DIALOG.PRG => TDIALOG:COMMAND(407)
Called from: => TWINDOW:HANDLEEVENT(0)
Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT(928)
Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
Called from: => WINRUN(0)
Called from: .\source\classes\WINDOW.PRG => TWINDOW:ACTIVATE(966)
Called from: main.prg => MAIN(260)

I agree there must be some 'fire' mechanism to EVAL a character string to launch the method .. it appears that the IE: sender must be outside the block ?

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Concatenate a varible into a method call

Postby Gale FORd » Wed May 18, 2011 1:25 pm

Just wondering, does the variable IE exist?

If this is an existing Internet Explorer object, then try this.

cSFD := "document:forms:item(0):search"
bSFD := &( "{ | oMyIE | oMyIE:"+cSFD+":Value = cPARTS }" )
eval( bSFD, IE )
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Concatenate a varible into a method call

Postby Rick Lipkin » Wed May 18, 2011 2:38 pm

Gale

Interesting result .. the error log reveals the values of two results 'Enter Keyword' and the search string '130794'

Application
===========
Path and name: C:\Fox\WebCrawl\WebCrawl.Exe (32 bits)
Size: 2,043,904 bytes
Time from start: 0 hours 0 mins 14 secs
Error occurred at: 05/18/2011, 10:21:36
Error description: Error BASE/1071 Argument error: =
Args:
[ 1] = C Enter Keyword
[ 2] = N 130794

Stack Calls
===========
Called from: Vendor1.prg => (b)_VENDOR1(85)
Called from: Vendor1.prg => _VENDOR1(86)

The first variable seems to be the eval of the DOM element I wish to stuff :

Image

Here is the code .. modified slightly because cPARTS was included in the string and errored ..

Image

the IE: send variable was defined earlier
IE := CreateObject("InternetExplorer.Application")

Curious why you chose oMyIE as your eval variable ?
bSFD := &( "{ | oMyIE | oMyIE:"+cSFD+":Value = "+cPARTS+" }" )

Just curious .. I did a msginfo( bSFD ) and it returned this interesting value ..

Image

I think we are close ..

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Concatenate a varible into a method call

Postby Gale FORd » Wed May 18, 2011 7:03 pm

I chose a different name for IE variable so it clearer which variable name has the focus.
If there is already a variable IE I did not want another local/block variable with the same name.

If cParts needs to be a string passed to :value then you need to add another set of quotes.
It might be more clear if you try it this way.

bSFD := &( [ { | IE | IE:]+cSFD+[:Value = "]+cPARTS+[" } ] )
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Concatenate a varible into a method call

Postby Rick Lipkin » Wed May 18, 2011 10:11 pm

Gale

Your examples do run and compile .. but the code does not execute and plug in the value into the web form :( .. Eval() does not seem to fire :(

*IE:document:forms:item(0):search:Value = cPARTS // this runs

bSFD := &( [ { | IE | IE:]+cSFD+[:Value = "]+cPARTS+[" } ] )
eval( bSFD, IE )

I really appreciate your insite !

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Concatenate a varible into a method call

Postby Gale FORd » Wed May 18, 2011 10:22 pm

The scope on the variable IE might be wrong. Why don't you change the variable name IE to something else inside the block.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Concatenate a varible into a method call

Postby Rick Lipkin » Wed May 18, 2011 10:57 pm

Gale

Here is a self contained example that is working .. The code opens IE and navigates to a web site .. inserts the part number 130794 into the search field then clickd the 'go' submit button .. notice the IE methods that do all the work.

Thanks
Rick Lipkin

Code: Select all  Expand view

// Rick.prg
//

//-------------------------------
Func Main()

LOCAL cURL, cLB, cLD, cPD, cSBLD
LOCAL cSFD, cSSBD
LOCAL cPARTS, IE

PRIVATE cSUB1,cSUB2,cSUB3,cSUB4,cSUB5

//-- from table

cURL   := "http://tewarehouse.com"
cSFD   := "document:forms:item(0):search"
cSSBD  := "document:all:go"
cPARTS := "130794"

IE:= CreateObject("InternetExplorer.Application")

*IE:Visible := .F.
IE:Visible := .t.
IE:Navigate( cURL )

Do While IE:Readystate <> 4
   SysWait(1)
   SysRefresh()
   Loop
Enddo

//  "Inserting part number "+cPARTS

IE:document:forms:item(0):search:Value = cPARTS

/*  THIS WORKS
cSub1 := "document"
cSub2 := "forms"
cSub3 := "item[0]"
cSub4 := "search"
cSub5 := "Value"

IE:&cSub1:&cSub2:item(0):&cSub4:&cSub5 = cPARTS

*/


/*
bSFD := &( [ { | IE | IE:]+cSFD+[:Value = "]+cPARTS+[" } ] )
eval( bSFD, IE )
*/

/*
cSFD := "document:forms:item(0):search"
bSFD := &( "{ || IE:"+cSFD+":Value = cPARTS }" )
eval( bSFD )
*/


SysWait(4)

//  "Clicking Search button"

IE:document:all:go:Click()

SysWait(4)

RETURN(NIL)
// end

 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Concatenate a varible into a method call

Postby Daniel Garcia-Gil » Thu May 19, 2011 12:32 am

Rick

your code working fine... only 1 tiny mistake

Code: Select all  Expand view
bSFD := &( [ { | IE | IE:]+cSFD+[:Value := "]+cPARTS+[" } ] )


is inline assignment, you should use :=
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Concatenate a varible into a method call

Postby Rick Lipkin » Thu May 19, 2011 12:28 pm

Gale, Daniel

Thank you VERY much for your timely and resourceful answers !! Indeed the final piece of the puzzle was the inline assignment :

bSFD := &( [ { | IE | IE:]+cSFD+[:Value := "]+cPARTS+[" } ] )
eval( bSFD, IE )

Thank you both !!
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 104 guests