求vb穷举代码
来源:百度知道 编辑:UC知道 时间:2024/05/16 06:27:02
我要的是代码!你这是随机生成的字符串,我是穷举啊!如果是不要非字母数字字符(符号)呢?怎样改?
请首先引用 Microsoft VBScript Regular Expressions 5.5 对象,用于正则表达式判断
Option Explicit
Sub Main()
Dim bytLen As Byte
Dim strPwd As String
Dim i As Byte
Randomize
Do '开始穷举
bytLen = Int(Rnd * 11) + 6 '生成6-16位的随机长度
strPwd = "" '清空密码
For i = 1 To bytLen '生成字符
strPwd = strPwd & Chr(Int(Rnd * 95) + 32) '随机生成32-126的所有可见字符
Next
If TestRegExp(strPwd) Then Debug.Print strPwd '用正则表达式判断密码是否符合要求,怎么处理这些密码没作处理,仅演示用
DoEvents '防止程序停止响应
Loop
End Sub
Function TestRegExp(strString As String) As Boolean
Dim objRegExp As RegExp
Set objRegExp = New RegExp
With objRegExp
.IgnoreCase = True
.Global = True
.Pattern = "\d{0,8}" '9位以下纯数字
End With