Discussion:
Using variables in replace command
(too old to reply)
Rotsj
2005-10-03 13:09:19 UTC
Permalink
Hi,
i'm writing procedure to process a txt file. This is a txt file with
variable length like this:

#00013#0120VST#0121Storkstraat#012222#01243833 LB#0125LEUSDEN#0127NL
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-02 17:38:02 UTC
Permalink
Replace (mRecordName) With (mValue)

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

"Rotsj" <***@home.nl> wrote in message news:dhrakl$s3s$***@news1.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#0121Storkstraat#012222#01243833 LB#0125LEUSDEN#0127NL
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-03 14:46:02 UTC
Permalink
What is the difference between & and ( )
Post by Roger Ansell
Replace (mRecordName) With (mValue)
-Roger
--
Roger Ansell
Ansell Management Services
Adelaide, Australia
Hi,
i'm writing procedure to process a txt file. This is a txt file with
#00013#0120VST#0121Storkstraat#012222#01243833 LB#0125LEUSDEN#0127NL
i've put the codes (#0001, #0120, etc.) in a table with corresponding
recordnames for the table so i can look it up.
mRecordName = ALLTRIM(imp_cb.recordname)
mValue = SUBSTR(dummy.line, (mbegin + 5), (mEnd - (mbegin + 5)))
replace &mRecordName WITH &mValue
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-03 15:24:17 UTC
Permalink
& 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
Post by Rotsj
What is the difference between & and ( )
Post by Roger Ansell
Replace (mRecordName) With (mValue)
-Roger
--
Roger Ansell
Ansell Management Services
Adelaide, Australia
Hi,
i'm writing procedure to process a txt file. This is a txt file with
#00013#0120VST#0121Storkstraat#012222#01243833 LB#0125LEUSDEN#0127NL
i've put the codes (#0001, #0120, etc.) in a table with corresponding
recordnames for the table so i can look it up.
mRecordName = ALLTRIM(imp_cb.recordname)
mValue = SUBSTR(dummy.line, (mbegin + 5), (mEnd - (mbegin + 5)))
replace &mRecordName WITH &mValue
Command contains unrecognised phrase/keyword.
The problem is the variable: mRecordName. If i read the value, it seems
correct.
Thanks!
Rotsj
Lee Mitchell
2005-10-03 19:50:34 UTC
Permalink
Hi Rotsj:

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

http://support.microsoft.com/default.aspx?scid=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/info/product.aspx?view=22&pcid=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
Post by Fred Taylor
& 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.
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.
--
Post by Fred Taylor
Fred
Microsoft Visual FoxPro MVP
What is the difference between & and ( )
Post by Roger Ansell
Replace (mRecordName) With (mValue)
-Roger
--
Roger Ansell
Ansell Management Services
Adelaide, Australia
Hi,
i'm writing procedure to process a txt file. This is a txt file with
#00013#0120VST#0121Storkstraat#012222#01243833 LB#0125LEUSDEN#0127NL
i've put the codes (#0001, #0120, etc.) in a table with corresponding
recordnames for the table so i can look it up.
mRecordName = ALLTRIM(imp_cb.recordname)
mValue = SUBSTR(dummy.line, (mbegin + 5), (mEnd - (mbegin + 5)))
replace &mRecordName WITH &mValue
Command contains unrecognised phrase/keyword.
The problem is the variable: mRecordName. If i read the value, it seems
correct.
Thanks!
Rotsj
Jack Jackson
2005-10-03 15:42:44 UTC
Permalink
& 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"
Post by Rotsj
What is the difference between & and ( )
Post by Roger Ansell
Replace (mRecordName) With (mValue)
-Roger
--
Roger Ansell
Ansell Management Services
Adelaide, Australia
Hi,
i'm writing procedure to process a txt file. This is a txt file with
#00013#0120VST#0121Storkstraat#012222#01243833 LB#0125LEUSDEN#0127NL
i've put the codes (#0001, #0120, etc.) in a table with corresponding
recordnames for the table so i can look it up.
mRecordName = ALLTRIM(imp_cb.recordname)
mValue = SUBSTR(dummy.line, (mbegin + 5), (mEnd - (mbegin + 5)))
replace &mRecordName WITH &mValue
Command contains unrecognised phrase/keyword.
The problem is the variable: mRecordName. If i read the value, it seems
correct.
Thanks!
Rotsj
Loading...