OT macro operator

Post Reply
User avatar
Detlef Hoefner
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany
Contact:

OT macro operator

Post by Detlef Hoefner »

Hi All,

a very stupid question but it's driving me nuts.
I want to update a field in a dbf.
The field name is defined in an array.

Code: Select all

#define DB_DBF 1
#define DB_FLD 2

LOCAL aDbf := {;
            { "dbf_1", "fiel_name_1" },;
            { "dbf_2", "fiel_name_2" },;
             ...
            { "dbf_n", "fiel_name_n" },;
    }
I can do

Code: Select all

use ( aDbf[n][DB_DBF] ) shared alias wrk new
But i can not

Code: Select all

wrk->&aDbf[n][DB_FLD] := uVal
I tried several variations. Either i get "invalid lvalue" at compile time or "&syntax error" at runtime.

So many years clippering but stumbling over such stupidity.
Sorry for bothering you. :oops:

Regards,
Detlef
User avatar
Richard Chidiak
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France
Contact:

Re: OT macro operator

Post by Richard Chidiak »

Detlef,

I remember some time ago having a similar problem

This is how i got it working

DT := "CLIENT" + ALLTRIM(SUBS(TABVAR[15][J],63,6))
REPLACE (MYFILE)->&DT WITH .....

HTH

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Detlef Hoefner
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany
Contact:

Post by Detlef Hoefner »

Richard,

thanks a lot for your answer.
I just found an other workaround which i will also show, allthough it is dangerous code if the field doesn' t exist.

Code: Select all

wrk->( fieldput( fieldpos( aDbf[ n ][ DB_FLD ] ), uVal ) ) 
But thanks again, Richard.
Regards,
Detlef
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

This works:

Code: Select all

wrk->&( aDbf[n][DB_FLD] ) := uVal
Anyway my personal preference in such cases is fieldput and fieldpos. I try to avoid macros. Again its a matter of choice.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Detlef Hoefner
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany
Contact:

Post by Detlef Hoefner »

NageswaraRao,

many thanks for your answer.
As you i always avoided the use of the macro operator.
But therefor i have a poor knowledge about it.

Thanks again for your hint.

Regards,
Detlef
Barry O'Brien
Posts: 9
Joined: Tue Aug 28, 2007 9:09 am
Location: Oxford, England

Post by Barry O'Brien »

Hi Detlef,

I had a similar problem just yesterday trying to do:

Code: Select all

cDBField := "ACNT_NBR"
REPLACE PAYMENT->&cDBField WITH cValue
This was causing the "&syntax error" you mentioned.

I fixed it by doing the following:

Code: Select all

cDBField := "PAYMENT->ACNT_NBR"
REPLACE &cDBField WITH cValue
Not sure if this will help in your circumstances but it worked for me.

Kind regards,

Barry
User avatar
Detlef Hoefner
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany
Contact:

Post by Detlef Hoefner »

Thanks, Barry

the response in this forum is unbelievable.

Regards,
Detlef
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Detlef,

Aren't you using TData? Did you know that the data is already buffered?

In TData the fieldnames are stored in aFldnames.

Perhaps if you explain what you are trying to do, I can help with a TData solution.

James
User avatar
Detlef Hoefner
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany
Contact:

Post by Detlef Hoefner »

James,

thanks for your kind offer.
But my problem concerned a mere MS DOS program where i had dbf and field names in an array and had to update those fields in a loop from each dbf.

Thanks and regards,
Detlef
FiveWiDi
Posts: 910
Joined: Mon Oct 10, 2005 2:38 pm

Post by FiveWiDi »

James Bott wrote:Detlef,

Aren't you using TData? Did you know that the data is already buffered?

In TData the fieldnames are stored in aFldnames.

Perhaps if you explain what you are trying to do, I can help with a TData solution.

James
Where is Tdata class?

Thanks,
Carlos G.
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

>Where is Tdata class?

TData is a commercial product I developed. You can read more about it and download a demo on my website.

http://ourworld.compuserve.com/homepage ... rogram.htm

James
Post Reply