Home > Archive > FoxPro database connector > October 2005 > Using variables in replace command









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Using variables in replace command
Rotsj

2005-10-27, 8:34 am

Hi,
i'm writing procedure to process a txt file. This is a txt file with
variable length like this:

#00013#0120VST#0121S
torkstraat#012222#01
243833 LB#0125LEUSDEN#0127N
L
i've put the codes (#0001, #0120, etc.) in a table with corresponding
recordnames for the table so i can look it up.
So i put the recordname in the variable mRecordName like this:
mRecordName = ALLTRIM(imp_cb.recordname)

I put the value (in a loop) in the variable mValue like this:
mValue = SUBSTR(dummy.line, (mbegin + 5), (mEnd - (mbegin + 5)))

and try to use an append blank and replace construction like this:
replace &mRecordName WITH &mValue

unfortunately i get an error:
Command contains unrecognised phrase/keyword.
The problem is the variable: mRecordName. If i read the value, it seems
correct.

Thanks!
Rotsj


Roger Ansell

2005-10-27, 8:34 am

Replace (mRecordName) With (mValue)

-Roger
--
Roger Ansell
Ansell Management Services
Adelaide, Australia

"Rotsj" <r.knipscheer@home.nl> wrote in message news:dhrakl$s3s$1@ne
ws1.zwoll1.ov.home.nl...
Hi,
i'm writing procedure to process a txt file. This is a txt file with
variable length like this:

#00013#0120VST#0121S
torkstraat#012222#01
243833 LB#0125LEUSDEN#0127N
L
i've put the codes (#0001, #0120, etc.) in a table with corresponding
recordnames for the table so i can look it up.
So i put the recordname in the variable mRecordName like this:
mRecordName = ALLTRIM(imp_cb.recordname)

I put the value (in a loop) in the variable mValue like this:
mValue = SUBSTR(dummy.line, (mbegin + 5), (mEnd - (mbegin + 5)))

and try to use an append blank and replace construction like this:
replace &mRecordName WITH &mValue

unfortunately i get an error:
Command contains unrecognised phrase/keyword.
The problem is the variable: mRecordName. If i read the value, it seems
correct.

Thanks!
Rotsj



Rotsj

2005-10-27, 8:34 am

What is the difference between & and ( )
"Roger Ansell" < notmyreal@emailaddre
ss.com> schreef in bericht
news:OQNvRCCyFHA.736@tk2msftngp13.phx.gbl...
> Replace (mRecordName) With (mValue)
>
> -Roger
> --
> Roger Ansell
> Ansell Management Services
> Adelaide, Australia
>
> "Rotsj" <r.knipscheer@home.nl> wrote in message

news:dhrakl$s3s$1@ne
ws1.zwoll1.ov.home.nl...
> Hi,
> i'm writing procedure to process a txt file. This is a txt file with
> variable length like this:
>
> #00013#0120VST#0121S
torkstraat#012222#01
243833 LB#0125LEUSDEN#0127N
L
> i've put the codes (#0001, #0120, etc.) in a table with corresponding
> recordnames for the table so i can look it up.
> So i put the recordname in the variable mRecordName like this:
> mRecordName = ALLTRIM(imp_cb.recordname)
>
> I put the value (in a loop) in the variable mValue like this:
> mValue = SUBSTR(dummy.line, (mbegin + 5), (mEnd - (mbegin + 5)))
>
> and try to use an append blank and replace construction like this:
> replace &mRecordName WITH &mValue
>
> unfortunately i get an error:
> Command contains unrecognised phrase/keyword.
> The problem is the variable: mRecordName. If i read the value, it seems
> correct.
>
> Thanks!
> Rotsj
>
>
>



Fred Taylor

2005-10-27, 8:34 am

& is a macro and will be replace with exactly the same text string, which
depending on where it's used may cause a problem, especially with embedded
spaces and is slower than using (), name expressions. Macros are also
slower that use of (). Note that they are not 100% interchangeable.

In your example you could use:

REPLACE &mrecordname WITH mValue

as a macro in this instance wouldn't make a big difference, and the ()
around the value portion is really only parenthesis, not really name
expression here. The reason that the & didn't work for the value is it
probably was a string, so you were missing your quotation marks for the
value.

--
Fred
Microsoft Visual FoxPro MVP


"Rotsj" <r.knipscheer@home.nl> wrote in message
news:dhrg9v$5l3$1@ne
ws2.zwoll1.ov.home.nl...
> What is the difference between & and ( )
> "Roger Ansell" < notmyreal@emailaddre
ss.com> schreef in bericht
> news:OQNvRCCyFHA.736@tk2msftngp13.phx.gbl...
> news:dhrakl$s3s$1@ne
ws1.zwoll1.ov.home.nl...
>
>



Jack Jackson

2005-10-27, 8:34 am

& is macro expansion, the contents of the variable are placed on the
line and the line is re-parsed. () tells VFP that the contents of the
variable inside the parens should be used for the next parse item.

For example:

cStr = "fld"
cVal = "abc"

REPLACE &cStr. WITH &cVal.

is equivalent to:

REPLACE fld WITH abc

REPLACE (cStr) WITH (cVal)

is equivalent to:

REPLACE fld WITH "abc"


On Mon, 3 Oct 2005 16:46:02 +0200, "Rotsj" <r.knipscheer@home.nl>
wrote:

>What is the difference between & and ( )
>"Roger Ansell" < notmyreal@emailaddre
ss.com> schreef in bericht
>news:OQNvRCCyFHA.736@tk2msftngp13.phx.gbl...
> news:dhrakl$s3s$1@ne
ws1.zwoll1.ov.home.nl...
>

Lee Mitchell

2005-10-27, 8:34 am

Hi Rotsj:

To add a little to Fred's response, you might want to look at this article:

http://support.microsoft.com/defaul...KB;EN-US;125046

I hope this helps.

This posting is provided "AS IS" with no warranties, and confers no rights.

Sincerely,
Microsoft FoxPro Technical Support
Lee Mitchell

*-- VFP9 HAS ARRIVED!! --*
Read about all the new features of VFP9 here:
http://msdn.microsoft.com/vfoxpro/

*--Purchase VFP 9.0 here:
http://www.microsoft.com/PRODUCTS/i...cid=54787e64-52
69-4500-8bf2-3f06689f4ab3&type=ovr

Keep an eye on the product lifecycle for Visual FoxPro here:
http://support.microsoft.com/gp/lifeselectindex
- VFP5 Mainstream Support retired June 30th, 2003
- VFP6 Mainstream Support retired Sept. 30th, 2003

>& is a macro and will be replace with exactly the same text string, which
>depending on where it's used may cause a problem, especially with embedded
>spaces and is slower than using (), name expressions. Macros are also
>slower that use of (). Note that they are not 100% interchangeable.


>In your example you could use:


>REPLACE &mrecordname WITH mValue


>as a macro in this instance wouldn't make a big difference, and the ()
>around the value portion is really only parenthesis, not really name
>expression here. The reason that the & didn't work for the value is it
>probably was a string, so you were missing your quotation marks for the
>value.


--
>Fred
>Microsoft Visual FoxPro MVP



>"Rotsj" <r.knipscheer@home.nl> wrote in message
> news:dhrg9v$5l3$1@ne
ws2.zwoll1.ov.home.nl...
> What is the difference between & and ( )
> "Roger Ansell" < notmyreal@emailaddre
ss.com> schreef in bericht
> news:OQNvRCCyFHA.736@tk2msftngp13.phx.gbl...
> news:dhrakl$s3s$1@ne
ws1.zwoll1.ov.home.nl...
>
>


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com