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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare Memvar's against Table Values...

Status
Not open for further replies.

ArevProgrammer

Programmer
Apr 7, 2001
38
0
0
US
Hi,

What is the best way to compare memvars against table
values so if the ESC key is pressed in a data entry window,
you can ask to save changes. Or not ask if nothing has changed.


Thanks,

Scott Rome was not built in a day. Be patient!
 
Scott,
If the memvars are all named the same as the fields (e.g. due to a Scatter MEMVAR), then just do an AFIELDS() to get the names, and then loop through the array and make the comparison.
Code:
llNoChanges = .T.
SELECT myAlias
lnFields = AFIELDS(laFields)
FOR lnii = 1 to lnFields
   lcField = alltrim(laFields[1]) && name of the field
   IF m.&lcField <> myAlias.&lcField
      wait window &quot;Field: '&quot;+lcField+&quot;' changed&quot;
      llNoChanges = .F.
   ENDIF
ENDFOR
IF NOT llNoChanges
   wait window &quot;You've got one or more changes!&quot;
ENDIF
You might need to do some extra checking if you've got memo fields and be careful about the current EXACT setting for string comparisons.

Rick
 
Rick,
Just a thought.... What if I use the UPDATED() function in tandem with a READ statement issued to capture the SCATTER MEMVAR fields?
Best Regards,
Yours sincerely,
Udai.
 
Rick,
to vary lcField, I think...
FOR lnii = 1 to lnFields
lcField = alltrim(laFields[lnii,1]) ...
(please, apologize my triviality)
Tesar
 
Also, take a look at the READKEY() function. From the help:

If READKEY( ) is issued without the optional numeric expression <expN>, the value returned represents the key pressed to exit from these
editing commands: APPEND, BROWSE, CHANGE, CREATE, EDIT, INSERT, MODIFY and READ.
An integer between 0 and 36, or between 256 and 292 is returned. The value returned is between 0 and 36 if the data was not modified. The
value returned is between 256 and 292 if the data is modified.
Dave S.
 
Tesar,
No need to appologize, we all make that the kind of mistake when we write code on-the-fly, good catch. While I usually try to test most of the code I post, I was in a hurry this time and didn't.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top