home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource1
/
chint
/
useful30.hnt
< prev
next >
Wrap
Text File
|
1993-10-29
|
2KB
|
46 lines
This useful hint has a simple function that can be used in the field
validation box of a field that allows "Duplicates" to eliminate
duplicate entries unless the key field has been left blank.
bool onlyEmptyDups(int fno, int kno, strptr keyfield)
{
bool fval, savok;
keystr ks;
long rno;
fval = empty(keyfield); /* No problem if it's empty */
if (!fval) {
savok = ok; /* Save the global variable "OK" */
strcpy(ks,keyfield); /* tk is the key we need to check */
findkey(idxkey[fno][kno],&rno,ks); /* Try to locate "tk" */
fval = !ok; /* if OK == True, it's already used */
ok = savok; /* restore original value of "OK" */
}
return(fval); /* return our findings to the function */
}
You would use this function in the "Validation Expression" of the
field definition of the field that is the key, combined with an "Error
Message" like :-- "This File Number is already in use, try another."
This function is for "C"haracter fields that are keys. If the key has
a key expression then you would need to use that when calling the
function, EG:--
File Number : 1
Field Name : ACCT_CODE
Key Number : 1
Allow Duplicates: Yes
Key Expression : upper(_tts,{})
Validation Exp. : onlyEmptyDups(1,1,upper(_tts,{}))
If the field is a "N"umeric field then you would need to use a
slightly different function. It could also be in the same function
file, and would look exactly the same as "onlyEmptyDups" except that
:--
1. You would replace occurances of onlyEmptyDups with onlyZeroDups
2. The line after the beginning "{" becomes :-
fval = (valu(keyfield) == 0);