FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Concatenate a varible into a method call
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Concatenate a varible into a method call
Posted: Tue May 17, 2011 07: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

Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: Concatenate a varible into a method call
Posted: Tue May 17, 2011 08: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 )

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Concatenate a varible into a method call
Posted: Wed May 18, 2011 12:56 PM
Gale

Thank you for your suggestions .. both options failed with

Variable does not exist: IE



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



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
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: Concatenate a varible into a method call
Posted: Wed May 18, 2011 01: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 )

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Concatenate a varible into a method call
Posted: Wed May 18, 2011 02: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 :



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



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 ..



I think we are close ..

Rick Lipkin
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: Concatenate a varible into a method call
Posted: Wed May 18, 2011 07: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+[" } ] )

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Concatenate a varible into a method call
Posted: 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

Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: Concatenate a varible into a method call
Posted: 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.

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Concatenate a varible into a method call
Posted: 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 (fw): Select all Collapse
// 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: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: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
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Concatenate a varible into a method call
Posted: Thu May 19, 2011 12:32 AM
Rick

your code working fine... only 1 tiny mistake

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


is inline assignment, you should use :=
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Concatenate a varible into a method call
Posted: 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

Continue the discussion