OT macro operator

OT macro operator

Postby Detlef Hoefner » Wed Oct 24, 2007 10:35 am

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  Expand view  RUN
#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  Expand view  RUN
use ( aDbf[n][DB_DBF] ) shared alias wrk new

But i can not
Code: Select all  Expand view  RUN
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
Detlef Hoefner
 
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany

Re: OT macro operator

Postby Richard Chidiak » Wed Oct 24, 2007 11:32 am

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
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Postby Detlef Hoefner » Wed Oct 24, 2007 11:44 am

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  Expand view  RUN
wrk->( fieldput( fieldpos( aDbf[ n ][ DB_FLD ] ), uVal ) )


But thanks again, Richard.
Regards,
Detlef
User avatar
Detlef Hoefner
 
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany

Postby nageswaragunupudi » Wed Oct 24, 2007 12:00 pm

This works:

Code: Select all  Expand view  RUN
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
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby Detlef Hoefner » Wed Oct 24, 2007 12:14 pm

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
User avatar
Detlef Hoefner
 
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany

Postby Barry O'Brien » Wed Oct 24, 2007 1:49 pm

Hi Detlef,

I had a similar problem just yesterday trying to do:

Code: Select all  Expand view  RUN
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  Expand view  RUN
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
Barry O'Brien
 
Posts: 9
Joined: Tue Aug 28, 2007 9:09 am
Location: Oxford, England

Postby Detlef Hoefner » Wed Oct 24, 2007 2:12 pm

Thanks, Barry

the response in this forum is unbelievable.

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

Postby James Bott » Thu Oct 25, 2007 1:28 am

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
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Detlef Hoefner » Thu Oct 25, 2007 8:06 am

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
User avatar
Detlef Hoefner
 
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany

Postby FiveWiDi » Thu Oct 25, 2007 10:59 am

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.
FiveWiDi
 
Posts: 1189
Joined: Mon Oct 10, 2005 2:38 pm

Postby James Bott » Thu Oct 25, 2007 9:05 pm

>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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 68 guests