Page 1 of 1 1
Topic Options
#213933 - 2020-10-30 06:33 PM If ingroup bug
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
If the script reads

If Ingroup ("groupA") = 1 or Ingroup ("GroupB") = 1

and the user is actually in that either group, then it works

However if the script reads as

If Ingroup ("groupA") = 0 or Ingroup ("GroupB") = 0

For some reason the script applies the settings as if that person is not in those user groups, when they are actually in one of the groups!

Is this a bug or am I not understanding something? I have looked at the documentation and I think that I will rewrite my scripts so that the If ingroups work like below as much easier to read and code.

IF INGROUP("Developers", "Testers") = 1
? "Member of Developers OR Testers group"
ENDIF

I will test if putting in 0 has the same effect as my coding

Top
#213934 - 2020-10-31 09:00 PM Re: If ingroup bug [Re: Robdutoit]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
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
 Code:
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
#213935 - 2020-11-01 10:01 AM Re: If ingroup bug [Re: Allen]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
Yes I think that you have hit on the possible cause. I also had some problems with using "or" instead of "and" etc on my mail server when creating filtering rules. It would logically seem that you use "or", not "and", but the coding didn't work as desired. It is probably the same thing here.

I think the best solution would be for me to simplify the coding as my if ingroup = 1 or ingroup = 1 is a cumbersome way to do it especially if you have more then 2 groups to check. The kixtart example I think is far better.

I have it on my list of things to do to go through my scripts and optimise them as over the years, I have added more lines of codes and groups etc.

I also agree that I need to get into the habit of making my statements true. Thanks

Top
#213936 - 2020-11-02 05:21 PM Re: If ingroup bug [Re: Robdutoit]
ShaneEP Moderator Offline
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...

 Code:
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...

 Code:
If Ingroup("groupA")
   If Ingroup("GroupB")
      ; in both groups
   Else
      ; in groupA, but not groupB
   EndIf
EndIf

Top
#213937 - 2020-11-02 05:23 PM Re: If ingroup bug [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
 Quote:
If Ingroup ("groupA") = 0 or Ingroup ("GroupB") = 0

For some reason the script applies the settings as if that person is not in those user groups, when they are actually in one of the groups!


I would expect this IF statement to return false, if they are not in both of the groups. Since you are using OR, either one of the Ingroups returning a 0 would make the whole statement false.

Top
#213938 - 2020-11-03 05:17 PM Re: If ingroup bug [Re: ShaneEP]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
Do you not need to use = 1. Even the kixtart examples use if ingroup "ABC" = 1

I think that I see what you mean by my statement returning a false. I always understood the syntax to mean that it would apply if one of the ingroups statements were true.

However, then thinking about it, it doesn't make sense that it works when I use = 1 for both ingroups as naturally one of them will be false. But your examples do make sense as it explains why and works correctly when using not ingroups because I had the exact same problem with my mail server when I was trying to say if not in groups.

I will ask my brother in law to go over this with me as I will probably understand it better with someone showing me in person.

So yes - this is not a Kixtart bug, but simply me not understanding the concept of not if statements. Thanks

Top
#213939 - 2020-11-05 03:39 PM Re: If ingroup bug [Re: Robdutoit]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Everything has always worked for me without using =1 or =0.
Top
#213940 - 2020-11-05 03:47 PM Re: If ingroup bug [Re: ShaneEP]
ShaneEP Moderator Offline
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
#213941 - 2020-11-09 05:14 PM Re: If ingroup bug [Re: ShaneEP]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 Originally Posted By: ShaneEP
Everything has always worked for me without using =1 or =0.


Just to add some more preference from experience..... \:D In my opinion "If InGroup" or "If Not InGroup" is more clear than =1 or =0 at the end of the evaluation.

The only way I have ever used the InGroup function is like below. I have never used =0 or =1 to check the outcome.

 Code:
If InGroup("GroupName1")

or
 Code:
If Not InGroup("GroupName2")

If possible I also try to avoid situations where two or more groups are evaluated on one line and action needs to be taken based on the outcome. Maybe that is because I often have trouble getting all possible outcomes clear and make mistakes this way. I always try to nest the group checks like this:

 Code:
If InGroup("GroupName1")
	If Not InGroup("GroupName2")
		;Do something
	EndIf
Else
	;Do something else
EndIf


This has worked just fine for the past 18+ years that I'm using KiXtart.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#213942 - 2020-11-12 01:42 PM Re: If ingroup bug [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
So - late to the party, but from the original question
 Quote:
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
 Code:
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! \:D

Top
#213943 - 2020-11-12 03:58 PM Re: If ingroup bug [Re: Glenn Barnas]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
Thank you for the further information. I will definitely rewrite my code so it is clearer what the code is actually doing. You are quite right, for years, I have always assumed that the code was doing something completely different to what it actually was doing! Which is why it didn't work with the original = 0 options because it was still returning true! Now it makes sense!

Very interesting. I will book in some time to update the code to reflect this and to just tidy up the general coding as well as the scripts have evolved over the years and need a bit of trimming. Thank you.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.062 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org