englandr@phoenix.Princeton.EDU (Scott Englander) (07/18/89)
I've written a simple function that i'd like to reference in a REPLACE statement. I'd like to pass it a field like dTdt(tr2) where tr2 is the field name Here's the function: ************** *dTdt.prg Q compute time derivative using central difference *value returned is in units/s parameter T && field to operate on missing = -99.0 twomin = 1.3889e-3 && 2 minutes in days n = recno() if n > 1 go n-1 t1 = lintime Tlast = T go n+1 t2 = lintime Tnext = T if t2-t1 <twomin && make sure data are continuous return (Tnext - Tlast)/120 && return time derivative over 2 min else return missing end if else return missing endif ***************** but as is, the function interprets the parameter to be the current value of the parameter, and skipping to a new record within the function does not change that value. Also, if there is a way to do this, do i have to be careful about setting the record pointer back to where it was upon entry of the function in order for a REPLACE ALL to work properly? -- - Scott
englandr@phoenix.Princeton.EDU (Scott Englander) (07/19/89)
OK. Here's how you do it. Just pass the field name in quotes. Then, each time you reference the field in your function, use a macro substitution, like deltaT = &T - Tlast where T was declared in a parameter statement. I still don't know the answer to the question regarding moving the record pointer within a function called by replace -- do you need to reset it to where it was upon entry of the function? Two other related points: 1. FoxBASE+/Mac 2.0 would not let me refer to a UDF in the with... dialog box used in building a replace statement. It worked fine on the command line. It seemed to think it was an array, giving me an error message about subscripts. 2. I neglected to check within my function for eof(), and tried to goto a non-existent record. An error alert came up, and i pressed the cancel button, at which point the "do cancelled" flag appeared, and stayed there for 15 minutes (it had taken that long to run the program). The machine seemed to be semi-hung, so i pressed the interrupt button and typed a G, which gave brought the machine back to life, with a message that Fox had quit unexpectedly. Is this a bug? Should i have pressed "suspend" and done a flush? -- - Scott