Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Not a charcter exp" error - macro subst

Status
Not open for further replies.

MrFancyteeth

Programmer
Mar 18, 2003
90
GB
morning

I'm trying to resize grid columns based on data that the cursor contains

step 1 is an Afields()

AFIELDS(arrfld,"curgrid")

FOR x=1 TO ALEN(arrfld,1)
cFld=arrfld(x,1)
IF arrfld(x,2)="C" && only for char fields
thisform.sizemycolumns(cfld,x)
endif
endfor

step 2 is the "sizemycolumns" form method which i pass the fieldname & an integer(x) which should be the column name

**** SIZEMYCOLUMNS Form Method
LPARAMETERS cFld,x

cexp="thisform.grid1.column" + ALLTRIM(STR(x))+".width"

cfld=ALLTRIM(cfld)

SELECT &cfld as fname,999999.999 as tlen FROM curgrid INTO cursor curlen GROUP BY &cfld readwrite

SELECT curlen
REPLACE curlen.tlen WITH thisform.TextWidth(ALLTRIM(curlen.fname))ALL

SELECT MAX(tlen) FROM curlen INTO ARRAY arrLen
&cexp=thisform.TextWidth(arrlen(1,1))

SELECT curlen
use

**** end of method

the error occurs in -
&cexp=thisform.TextWidth(arrlen(1,1))

I guess the macro substition of &cexp isn't liking having a numeric assigned to it.

anybody know a fix for this or another way of making the grid columns resize automatically?

mrF

 

If I follow the logic of your code your final expression is missing an "=" sign at the end of it?

cexp="thisform.grid1.column" + ALLTRIM(STR(x))+".width"



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
thanks
but adding "="
to the cexp didn't work

cexp="thisform.grid1.column" + ALLTRIM(STR(x))+".width="

then

&cexp thisform.TextWidth(arrlen(1,1))

still causes the "not a character expression error"

bTW - my logic goes something like

get all fieldnames,types from a cursor which is a grid source (using afields)

loop thru array - if it is character type then work out max length

Find the longest (using textwidth) - a regular len() produced shortened column width

make the respective column that width

mrf


 
FIXED!!

it wasn't a macro substition error - i'd already calced the max length of the field.

The error was because i was trying to textwidth() a numeric value (the result of the previously created textwidth)!

amazing what a beer At lunchtime & getting away from work for a bit can do. -

if ur interested here's the sizemycolumns method (that works)

LPARAMETERS cFld,x

cfld=ALLTRIM(cfld)

SELECT ALLTRIM(&cfld) as fname,999999.999 as tlen FROM curgrid INTO cursor curlen GROUP BY &cfld readwrite

SELECT curlen
REPLACE curlen.tlen WITH thisform.TextWidth(ALLTRIM(curlen.fname))ALL

SELECT MAX(tlen) FROM curlen INTO ARRAY arrLen


cexp="thisform.grid1.column"+ALLTRIM(STR(x))+".width=arrlen(1,1)"
&cexp

SELECT curlen
use

mrF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top