Ok. i want to be able to have the somputer choose like 7 digits and letters only. like
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_
and it chooses Ac34B2z
Printable View
Ok. i want to be able to have the somputer choose like 7 digits and letters only. like
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_
and it chooses Ac34B2z
What is the question??
Do you want it to choose them in a random way or what..???
:confused: :confused: :confused: :eek:
yah. randomly choose 7 digits from the all the letters and numbers
ok, here
[Edited by gwdash on 10-07-2000 at 04:27 PM]Code:Function GetRandom(length As Integer) As String
Dim keystring As String 'to hold return
Randomize 'randomize RND generator
Dim b As Integer 'loop var
For b = 1 To length 'loop
Select Case Int((3 - 1 + 1) * Rnd + 1) 'pick Caps, Lower, or Nums
Case 1
keystring = keystring & Chr(Int((57 - 48 + 1) * Rnd + 48)) 'get random number
Case 2
keystring = keystring & Chr(Int((90 - 65 + 1) * Rnd + 65)) 'get random capital
Case 3
keystring = keystring & Chr(Int((122 - 97 + 1) * Rnd + 97)) 'get radnom lowercase
End Select
Next b
GetRandom = keystring
Try this code:
Usage:Code:Public Function GetRandomString(ByRef CharsToChooseFrom As String, ByVal NumberOfCharsToReturn) As String
Dim T As Integer
Dim TmpStr As String
Randomize Timer
For T = 1 To NumberOfCharsToReturn
TmpStr = TmpStr + Mid(CharsToChooseFrom, CInt(Rnd * (Len(CharsToChooseFrom) - 1)) + 1, 1)
Next T
GetRandomString = TmpStr
End Function
TheString=GetRandomString("abcABC123",5)
This wil return 5 chars, each of them will be a,b,c,A,B,C,1,2 or 3.
To test with your given info:
Code:Debug.Print GetRandomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_", 7)