|
|
|||||||
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 |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
Everything has always worked for me without using =1 or =0. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
Originally Posted By: ShaneEP Everything has always worked for me without using =1 or =0. Just to add some more preference from experience..... 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. |
||||||||
|
|
|||||||
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? 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 Glenn |
||||||||
|
|
|||||||
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. |