Page 1 of 1

OT macro operator

Posted: Wed Oct 24, 2007 10:35 am
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

Re: OT macro operator

Posted: Wed Oct 24, 2007 11:32 am
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

Posted: Wed Oct 24, 2007 11:44 am
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

Posted: Wed Oct 24, 2007 12:00 pm
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.

Posted: Wed Oct 24, 2007 12:14 pm
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

Posted: Wed Oct 24, 2007 1:49 pm
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

Posted: Wed Oct 24, 2007 2:12 pm
by Detlef Hoefner
Thanks, Barry

the response in this forum is unbelievable.

Regards,
Detlef

Posted: Thu Oct 25, 2007 1:28 am
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

Posted: Thu Oct 25, 2007 8:06 am
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

Posted: Thu Oct 25, 2007 10:59 am
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.

Posted: Thu Oct 25, 2007 9:05 pm
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