CBool(IIf(BooleanFunction(), True, False))
-
We had a contract programmer do some work for us recently. Alas, he was hired by the Pointy Haired One, so this month I get to go over his work and correct errors. Among the steaming pile, I found this nugget:
RunTSMenuItem.Enabled = CBool(IIf(MyUser.HasPermission(Permission.Admin), True, False))
When a user logs into the application, an instance of
MyUser
is created with all of the user's permissions (among other data.)HasPermission(Permission.whatever)
will return true if the user has the requested permission and false otherwise. The above code activates a menu item on a form if the user is an administrator, otherwise the menu item is inactive. Unfortunately, this guy was overly fond ofIIf
and used it every opportunity he could, whether needed or not. -
We had a contract programmer do some work for us recently. Alas, he was hired by the Pointy Haired One, so this month I get to go over his work and correct errors. Among the steaming pile, I found this nugget:
RunTSMenuItem.Enabled = CBool(IIf(MyUser.HasPermission(Permission.Admin), True, False))
When a user logs into the application, an instance of
MyUser
is created with all of the user's permissions (among other data.)HasPermission(Permission.whatever)
will return true if the user has the requested permission and false otherwise. The above code activates a menu item on a form if the user is an administrator, otherwise the menu item is inactive. Unfortunately, this guy was overly fond ofIIf
and used it every opportunity he could, whether needed or not.