求高手帮助:如何用VB生成这样一组特殊的随机字符串

来源:百度知道 编辑:UC知道 时间:2024/06/18 22:47:17
恳请高手帮助:我想用vb的随机函数编程给出一组随机字符串,满足如下要求:
1、可以包含大小写字母、特殊符号如标点符号、阿拉伯数字等
2、字符串中的字符不能重复
3、在每次给出的随机字符串中,都要包含有10个阿拉伯数字,顺序可以随意
4、字符串长度控制在30——50之间
恳求高手帮忙,最好能给出源代码,万分感谢!
我的邮箱是anti555@sohu.com

'加一个按钮控件
Option Explicit

Private Sub Command1_Click()
Dim a As Integer, b As Integer
Dim myPassWord As String
Randomize (Timer)
Cls
For a = 33 To 127
myPassWord = myPassWord & Chr(a)
Next
a = Val(InputBox("请输入你需要的密码长度:30-50之间", "密码长度", 30))
myPassWord = Replace(myPassWord, "0123456789", "")
myPassWord = zhzsucyg(a - 10, myPassWord)
myPassWord = "0123456789" & myPassWord
myPassWord = zhzsucyg(a, myPassWord)
Print myPassWord
End Sub

Private Function zhzsucyg(a As Integer, b As String) As String
Dim i As Integer, j As Integer
Dim myInput As String, myOutput As String
myInput = b
For i = 1 To a
j = Int((Len(myInput)) * Rnd) + 1
myOutput = myOutput & Mid(myInput, j, 1)
myInput = Replace(myInput, Mid(myInput, j, 1), "")
Next
zhzsucyg = myOutput
End Functi