2011年3月3日 星期四

隨機取得6-8碼數字+英文字

'此功能需要一個CommandButton 跟一個TextBox

Private Sub Command1_Click()
Dim intLoop As Integer
Dim intLoop2 As Integer
Dim strValue As String
Dim strTmpValue As String
Dim intType As Integer
Dim intRValue As Integer
Dim intCount As Integer
Randomize Timer '隨機取得6,7或8碼
intCount = Int(Rnd * 3) + 6

For intLoop = 1 To intCount
Randomize Timer '隨機取得數字,小寫或大寫英文字
intLoop2 = Int(Rnd * 3)
Randomize Timer
If intLoop2 = 0 Then
intRValue = Int(Rnd * 10) '取0-9
strTmpValue = Chr(intRValue + 48)
Else
intRValue = Int(Rnd * 26)
If intLoop2 = 1 Then
strTmpValue = Chr(intRValue + 97) '取a~z
Else
strTmpValue = Chr(intRValue + 65) '取A~Z
End If
End If

strValue = strValue & strTmpValue
Next
Text1.Text = strValue

End Sub

沒有留言:

張貼留言