VBA 生成带时间戳的随机数字

栏目: 时间戳 · 发布时间: 2021-01-23

来源:cnblogs.com

简介  这篇文章主要介绍了VBA 生成带时间戳的随机数字以及相关的经验技巧,文章约1991字,浏览量262,点赞数8,值得参考!

Function GenPasswd(length, level)
Dim allstr, substr, passwd As String

allstr = "[email protected]#$%^&*()"
Select Case level
Case 1
strlen = 10
Case 2
strlen = 36
Case 3
strlen = 62
Case Else
strlen = 72
End Select
substr = Left(allstr, strlen)
‘Debug.Print substr
passwd = ""
For i = 1 To length
passwd = passwd & Mid(substr, Int(Rnd * strlen + 1), 1)
Next
GenPasswd = passwd
End Function
Function GetUnixTime()
GetUnixTime = DateDiff("s", "01/01/1970 00:00:00", Now())
End Function
Function GeneratePassData(strlen As Integer)

Dim str As String

str = Convert10To62(GetUnixTime())
If strlen <= Len(str) Then
GeneratePassData = str
Exit Function
End If
GeneratePassData = GenPasswd(strlen - Len(str), 3) + str

End Function

Function Convert10To62(str As Long)

Dim i, j As Integer
Dim rest As Long
Dim arr()
Dim str1 As String
Dim retStr As String

retStr = ""
rest = str
str1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
ReDim Preserve arr(Len(str1))
For i = 1 To Len(str1)
arr(i) = Mid(str1, i, 1)
Next

While rest <> 0
j = rest - (rest 62) * 62 + 1 ‘vba 角标是从1开始,不是从0开始
retStr = retStr + arr(j)
rest = rest 62
Wend
Convert10To62 = StrReverse(retStr)
End Function

 


















































以上就是本文的全部内容,希望对大家的学习有所帮助,版权归原作者或者来源机构所有,感谢作者,如果未能解决你的问题,请参考以下文章。

SQL时间戳的使用

Servlet仿CSDN动态验证码的生成-带数字和字母

随机生成指定长度的密码之---Random

C# 时间戳的生成

php生成毫秒时间戳的例子