> On Jul 16, 2017, at 9:18 PM, David Adams via 4D_Tech <[email protected]>
> wrote:
>
> So, I'd be grateful if anyone that is Really Into Sets (we all know you're
> out there!) gave it some thought. If it's reliable, great! If not, I'll
> kill it rather than rely on it.
I really should shut up since I have already penned an inaccurate post on this
subject.
But in the interest of keeping the conversation going, how about using ADD TO
SET as the command to test whether a set exists?
You can first check to see whether the proposed set has more than zero records.
If it does, then the set exists.
If Records in set returns zero records then it might be because the set does
not exist and it might be because the set is valid but has zero records. Now
apply the ADD TO SET command and see if it throws an error.
ADD TO SET is documented to throw an error if the set does not exist.
If it does exist, then adding zero records to some set should not cause any
harm.
WARNING: I would not actually rely on the code below without, as David has
said, having people who are "Really Into Sets" make a contribution. It has been
previously demonstrated that I am not "Really Into Sets" :)
* * * * * * * * * * * * * * * *
* * * * * *
// PROJECT METHOD: rfSetExist PATH: rfSetExist
// PARAMETERS
// $1 = Set name being tested
// ----------------------------------------------------
// RETURNED VALUE(s)
// $0 Type: Boolean
// ----------------------------------------------------
// DESCRIPTION: Tells you whether a set exists. If True then the set exists
C_BOOLEAN($0;$setDoesExist)
C_TEXT($1;$setName)
C_BOOLEAN($testInSet)
C_LONGINT($numInSet)
$setName:=$1
$numInSet:=Records in set($setName) // Documentation: Records in set returns
the number of records in set. If set does not exist, or if there are no records
in set, the command returns 0.
If ($numInSet>0)
$setDoesExist:=True
Else
// two possibilities
// 1. set does not exist
// 2. set exists but has no records
// logic: The documentation says: // ADD TO SET ( {aTable ;} set ) …
ADD TO SET adds the current record of aTable to set. The set must already
exist; if it does not, an error occurs.
// if the set does not exist, I will get an error.
// if it does exist then I will NOT get an error but it is safe
because I will not have changed the state of anything since adding zero records
to an existing set does nothing.
fErrorHappened:=False // this is a process variable that is created at
startup
ON ERR CALL("ErrorIgnore") // ErrorIgnore is a method that sets
fErrorHappened to true
$testInSet:=ADD TO SET($setName) // if the set does not exist, this
will throw an error. This particular "Set" command is sensitive as to whether
the set exists
ON ERR CALL("")
If (fErrorHappened)
$setDoesExist:=False
Else
$setDoesExist:=True
End if
$0:=$setDoesExist
End if
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ: http://lists.4d.com/faqnug.html
Archive: http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************