#213934 - 2020-10-31 09:00 PM
Re: If ingroup bug
[Re: Robdutoit]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4546
Loc: USA
|
I would suggest trying to keep all your evaluations as True which is what your first IF is doing.
If Ingroup ("groupA") = 1 or Ingroup ("GroupB") = 1 So the statement above says, If someone is one or both groups, do something.
Ingroup returns 1 if someone is in a group, and 0 if not.
So basically your IF looks like this if someone is in one group and not the other
If (1=1) or (0=1)
; True or False
? "True"
Endif
I'm struggling to explain why your second IF isn't working but I'm pretty sure it's syntax and not a bug. There's some rules regarding AND and OR, and I can't seem to find what I'm looking for.
|
Top
|
|
|
|
#213936 - 2020-11-02 05:21 PM
Re: If ingroup bug
[Re: Robdutoit]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
I have always had better luck treating them as logic statements, rather than comparison statements. Probably just because it's easier for me to read and understand. Just some elementary examples...
If Ingroup("groupA") And Ingroup("GroupB")
; in both groups
EndIf
If Ingroup("groupA") Or Ingroup("GroupB")
; in at least one of the groups, maybe both
EndIf
If Not Ingroup("groupA") And Not Ingroup("GroupB")
; not in either group
EndIf
If Not Ingroup("groupA") Or Not Ingroup("GroupB")
; not in one of the two groups, maybe not in either
EndIf
You can always nest them too, if it makes more sense to do so...
If Ingroup("groupA")
If Ingroup("GroupB")
; in both groups
Else
; in groupA, but not groupB
EndIf
EndIf
|
Top
|
|
|
|
#213940 - 2020-11-05 03:47 PM
Re: If ingroup bug
[Re: ShaneEP]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Also, I'll add that the "Expressions" page in the CHM html help file might help. It outlines a lot of the logical comparators, and lists many various examples. This section may be in the original help doc as well, but I don't have it handy to check.
Newest CHM files can be found at link below...
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=202858
|
Top
|
|
|
|
#213942 - 2020-11-12 01:42 PM
Re: If ingroup bug
[Re: Mart]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
So - late to the party, but from the original question Why doesn't "If Ingroup ("groupA") = 0 or Ingroup ("GroupB") = 0" work when a user is in one group? The answer is simple - the logic test is "TRUE" when a user is NOT in a group. With OR, if a user is not in either group, the action will be taken.
Using "If Ingroup()", as others have pointed out, tests the Boolean value rather than an explicit comparison. A statement such as "If X = 0" is counter-intuitive because the test is TRUE when the value being compared is FALSE. It's your brain, not the code, because you SEE zero and have been taught that Zero=False, you're not recognizing that the result of the comparison and not the compare value is what's being evaluated.
Follow the guidance above and ditch the specific return code comparisons.. use "If TEST" for any true and "If Not TEST" for any false triggered action, and leave the "=" for specific value tests.
Lastly, the examples in the KiXtart guide are at a primer level - they indicate what's explicitly returned. It's about interpreting the results.. if it returns just 1 or 0, treat it like a Boolean and you will generally be fine. Note that many of the earliest Kix functions and even many UDFs return 0 on SUCCESS and an error value on FAIL. That's counter to most app-dev processes that return a value of 1 on success, 0 on failure (if not returning specific data) so you can use the form If func()
do stuff...
Else ; oops - failed!
Error recovery based on @ERROR value
EndIf With some 400+ functions now in our library, every one of them that doesn't return specific data is written to return a Bool True and Exit with 0 on success. Even functions that return strings can be tested this way by returning an empty string on function failure. Use unique Exit codes to represent specific failures rather than returning error messages from the function with generic Exit 1. It's much harder to process things that way.
Glenn
Edited by Glenn Barnas (2020-11-12 01:43 PM)
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 396 anonymous users online.
|
|
|