>I'm trying to provide an option for users to selectively track changes to important files. This is what we've got...
>
>IF AUDITING && user option to track changes to selected files
> COPY TO ARRAY TEMVAR RECORD(RECNO()) && the unchanged record
> && (Note 'Scatter to Temvar' doesn't seem to work any differently in this context)
>ENDIF
>GATHER MEMVAR MEMO && store the changes in the table being tracked
>IF AUDITING
> IF TYPE('AUDFILE')='L' && the file recording changes hasn't been defined yet
> AUDFILE=TRIM(AUDITPATH+ALIAS())+'.DBF' && auditpath is the directory we store the audit files in
> ENDIF
> IF FILE(AUDFILE)
> INSERT INTO &AUDFILE FROM ARRAY TEMVAR && the original version
> INSERT INTO &AUDFILE FROM MEMVAR && the changed version
> ENDIF
>ENDIF
>
>
>I find that the array version is consistently screwed up! The data seems to be shunted along a couple of fields making the record useless.
>
>I find also that I get exactly the same results if I switch from 'insert into' to the slower and more long winded 'append blank/gather' alternative.
>
>Is this just me?
>
>If not, is it documented anywhere and is there a fix?
>
>The one pattern I have noticed is that the copy/scatter to array version can't seem to handle memo fields and that some of its shunting is caused by its skipping such fields. But even if I reorder the fields and place memos at the end of the table, although this improves things slightly, the shunting still happens.
>
>Incidentally, if I run a test manually from the command window, it works perfectly! So the problem must be caused by something in my application environment. Even a suggestion on how to debug it would be extremely welcome!
>
>I have watched the values of 'temvar' in the debugger prior to and after the insertion and compared them field by field with the original record and they match exactly. Its only in the 'audit' table itself that the values are screwed up...
>
>(the audit table starts off as a blank copy of the table being audited so its structure is identical)
>
>Finally, although I would welcome advice along the lines of 'there is a much better way to do this in vfp' I would still like some insight into why those few simple lines don't do the job as anticipated.
>
>Harry
Harry,
"Copy to array" doesn't handle memo and general. But initializes them to .f.
"Scatter to (arrayname) memo" would handle memo fields but not general (that's if you fcount() is 10 and have 2 general, array would have 8 elements).
If leaving general out is not a problem, scatter - gather is a safer way :
scatter to memvar memo && prevents shifting of fields as in array
gather memvar
But you cannot be sure of field types used for a generic routine beforehand. So I suggest you also support general and use SQL for such things.
select ... into cursor myTemp nofilter
...
append from myTemp
Cetin