A simple permission system based on logic operation (principle, design, implementation) VBS version _vbs

Source: Internet
Author: User
Tags logical operators
Author: slightboy, Time: 2006-10-14
Starting in: http://cs.alienwave.cn/Topic/329.aspx

See a lot of students permission to judge is to use string and then or split or intercept
In fact, to allow/disallow (True/false) This kind of permission, the logical operation is more appropriate
Statement: This article is aimed at getting started and for the mastery of the students, if they already understand that can be ignored
Perhaps the meaning of the expression is not very clear, please forgive me.

Introduction to Logical operators:
And: Logic and
0 and 0 = 0
0 and 1 = 0
1 and 0 = 0
1 and 1 = 1
Or: Logical OR
0 Or 0 = 0
0 Or 1 = 1
1 Or 0 = 1
1 Or 1 = 1
XOR: Exclusive OR
0 Xor 0 = 1
0 Xor 1 = 1
1 Xor 0 = 1
1 Xor 1 = 1
Not: Logical non-
Not 1 = 0
Not 0 = 1

How to express:
1 means ture, 0 is False
Take two digits for example
The first digit represents the permission of Read, and the second represents the permission to Write, which can represent four permissions
Read (False) Write (false)
Read (True) Write (false)
Read (False) Write (true)
One Read (True) Write (True)

Operation Method Introduction:
Or continue with the above example
Read = (1), Write = 10 (2)
(0) and Read = 0
(1) and read = Read
Ten (2) and Read = 0
One (3) and read = Read
(0) and Write = 0
(1) and Write = 0
Ten (2) and write = Write
One (3) and write = Write

Here's how to show the sample code:
Permission definition class (to have an enumeration type) how nice ...)
Class permissiontypepublic readpublic writepublic deleteprivate Sub class_initializeread = 1Write = 2Delete = 4End SubEnd Class
Permission class
Class permissionsetcomponentprivate intvaluepublic property get read () Read =  getvalue (Permission.read) end propertypublic property let read (ARG) Call SetValue (Permission.read, arg) End propertypublic property get write () Write = getvalue (Permission.Write) End  propertypublic property let write (ARG) call setvalue (permission.write, arg) End  propertypublic property get delete () Delete = getvalue (Permission.Delete) End  propertypublic property let delete (ARG) call setvalue (permission.delete, arg) End  propertypublic property get value () value = intvalueend propertypublic  property let value (ARG) intvalue = argend propertypublic function  GetValue (inttype) getvalue =  (value and inttype)  = inttypeend functionpublic  Sub setvalue (Inttype, boolvalue) if  (boolvalue)  ThenValue = Value Or  inttypeelsevalue =  value and  (Not inttype) End ifend subend class
Use sample code:
Dim Permission:set Permission = new Permissiontypedim permissionset:set PermissionSet = new Permissionsetcomponentperm Issionset.value = 0w ("Read:") Permissionset.read = Falsew (Permissionset.value & "" & Permissionset.read) Permissionset.read = Truew (Permissionset.value & "" & Permissionset.read) W ("Write:") Permissionset.write = Falsew (Permissionset.value & "" & permissionset.write) Permissionset.write = Truew (Permissionset.value & "" & Permissionset.write) W ("Delete:") Permissionset.delete = Falsew (Permissionset.value & "" & Permissionset.delete) Permissionset.delete = Truew (Permissionset.value & "" & Permissionset.delete) Function W ( O) Response.Write ("<br/>" & O) End Function

Today's lesson is here, we can extrapolate, class ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.