• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >vbs > 基于逻辑运算的简单权限系统(原理,设计,实现) VBS 版

基于逻辑运算的简单权限系统(原理,设计,实现) VBS 版

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了vbs中的四则运算,vbs运算符,vbs脚本权限,vbs脚本权限开启,win7 vbs脚本权限等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
作者:slightboy
看到好多同学权限判断都是用字符串 然后或分割或截取

其实对于 允许/不允许(true/false) 这种的权限, 用逻辑运算再恰当不过了

声明下: 本文针对入门和为掌握的同学, 如果已经懂了那可以无视了

 可能意思表达的不是很清楚, 敬请原谅. 

逻辑运算符介绍:
And: 逻辑与

0 And 0 = 0 
0 And 1 = 0 
1 And 0 = 0 
1 And 1 = 1 
Or: 逻辑或

0 Or 0 = 0 
0 Or 1 = 1 
1 Or 0 = 1 
1 Or 1 = 1 
Xor: 异或

0 Xor 0 = 0 
0 Xor 1 = 1 
1 Xor 0 = 1 
1 Xor 1 = 0 
Not: 逻辑非

Not 1 = 0 
Not 0 = 1 


表达方式介绍:

1 表示 ture, 0 表示 false

举二位为例

第一位 表示 Read 的权限, 第二位 表示 Write 的权限, 可以表示一下四种权限

00 Read(false) Write(false) 
01 Read(true) Write(false) 
10 Read(false) Write(true) 
11 Read(true) Write(true) 


运算方式介绍:

还是继续上面的例子

Read = 01(1), Write = 10(2)

00(0) And Read = 0 
01(1) And Read = Read 
10(2) And Read = 0 
11(3) And Read = Read 
00(0) And Write = 0 
01(1) And Write = 0 
10(2) And Write = Write 
11(3) And Write = Write 


下面给出示例代码:

权限定义类(要有枚举类型该多好啊...)

Class PermissionType

    Public Read
    Public Write
    Public Delete

  Private Sub Class_Initialize
    Read = 1
    Write = 2
    Delete = 4
  End Sub

End Class
权限类

Class PermissionSetComponent

    Private intValue

  Public Property Get Read()
    Read = GetValue(Permission.Read)
  End Property

  Public Property Let Read(arg)
    Call SetValue(Permission.Read, arg)
  End Property

  Public Property Get Write()
    Write = GetValue(Permission.Write)
  End Property

  Public Property Let Write(arg)
    Call SetValue(Permission.Write, arg)
  End Property

  Public Property Get Delete()
    Delete = GetValue(Permission.Delete)
  End Property

  Public Property Let Delete(arg)
    Call SetValue(Permission.Delete, arg)
  End Property

  Public Property Get Value()
    Value = intValue
  End Property


  Public Property Let Value(arg)
    intValue = arg
  End Property

  Public Function GetValue(intType)
    GetValue = (Value and intType) = intType

  End Function

  Public Sub SetValue(intType, boolValue)
    IF (boolValue) Then
        Value = Value Or intType
    Else
        Value =  Value And (Not intType)
    End IF
  End Sub

End Class
运用示例代码:

Dim Permission : Set Permission = new PermissionType

Dim PermissionSet : Set PermissionSet = new PermissionSetComponent
PermissionSet.Value = 0
w("Read:")
PermissionSet.Read = false
w(PermissionSet.Value &" "& PermissionSet.Read)

PermissionSet.Read = true
w(PermissionSet.Value &" "& PermissionSet.Read)

w("Write:")
PermissionSet.Write = false
w(PermissionSet.Value &" "& PermissionSet.Write)

PermissionSet.Write = true
w(PermissionSet.Value &" "& PermissionSet.Write)

w("Delete:")
PermissionSet.Delete = false
w(PermissionSet.Value &" "& PermissionSet.Delete)

PermissionSet.Delete = true
w(PermissionSet.Value &" "& PermissionSet.Delete)

Function w(o)
    Response.Write("<br />"& o)
End Function


今天的课程就到这里, 大家可以举一反三, 下课...

</div>

您可能想查找下面的文章:

  • 基于逻辑运算的简单权限系统(原理,设计,实现) VBS 版
  • 基于逻辑运算的简单权限系统(原理,设计,实现) VBS 版
  • VBS教程:运算符-运算符(+)
  • VBS教程:运算符-And 运算符
  • VBS教程:运算符-连接运算符 (&)
  • VBS教程:运算符-除运算符 (/)
  • VBS教程:运算符-幂运算符 (^)
  • VBS教程:运算符-Imp 运算符
  • VBS教程:运算符-Is 运算符
  • VBS教程:运算符-Mod 运算符

相关文章

  • Hardware_Info.vbs 获取硬件信息的VBS代码
  • VBS教程:函数-Mid 函数
  • vbs循环产生的参数的传递问题
  • vbs删除注册表项的代码
  • discuz 任意管理员密码漏洞利用工具 vbs代码
  • vbs Windows系统改变或修改网卡的MAC地址的脚本与软件第1/2页
  • vbs 中调用shell.application 简单函数
  • vbs实现的汉字转拼音的函数
  • 把vbscript发挥到它的极限应用之一(数组)!!!
  • 用VBS实现的发送带Cookie的HTTP请求的代码

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 如何通过计划任务调用QuickTest测试脚本
    • vbs实现的保存剪贴板中的文本并编辑或保存
    • VBScript Enun Remote CMD Shell代码
    • 用vbs 取得收藏夹里的所有链接名称和URL的脚本
    • 用vbs实现的强制杀进程的脚本
    • 批量替换快捷方式目的路径的VBS脚本
    • VBS教程:语句-While...Wend 语句
    • vbs实现无黑框无DOS窗口隐藏批处理运行窗口
    • Crack8 VBS整人脚本 你不说你爱我 就关机
    • vbs自动填表单分析附源码

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有