2025-06-27 14:40:52
我白忙了,就是
不过已经忙了就附上吧:
'主函数
Function GetRndString() As String
Randomize
Dim item As String
item = GetRndLetters(Int(Rnd * 10 + 1)) '获取长度1 到10随机确定的随机字母串
item = item & GetRndDigits(Int(Rnd * 10 + 1)) '获取长度1到10随机确定的随机数字串
GetRndString = item
End Function
'产生给定数量的随机数字字符串,由GetRndString调用
Function GetRndDigits(nlen As Integer) As String
Dim item As String
Dim i As Integer
Randomize
For i = 1 To nlen
item = item & Int(Rnd * 10)
Next
GetRndDigits = item
End Function
'产生给定数量的随机字母字符串,由GetRndString调用
Function GetRndLetters(nlen As Integer) As String
Const CTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZzbcdefghijklmnopqrstuvwxyz" '如果只想产生大写字母的话,那就把小写字母删除掉
Dim item As String
Dim i As Integer
Dim loc As Integer
Randomize
For i = 1 To nlen
loc = Int(Rnd * Len(CTable) + 1)
item = item & Mid(CTable, loc, 1)
Next
GetRndLetters = item
End Function
2025-06-27 02:00:01
参考一下这个:
Private Sub Command1_Click()
Dim strText$, i&, v&
strText = vbNullString
Randomize
For i = 1 To 8 ' 1 to 8 就是生成长度为8字符
v = Rnd() * 35
If (v > 9) Then
strText = strText & Chr$(55 + v)
Else
strText = strText & Chr$(48 + v)
End If
Next
MsgBox strText, vbInformation
End Sub
2025-06-27 14:38:52
2025-06-27 07:20:03