By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,652 Members | 1,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,652 IT Pros & Developers. It's quick & easy.

Generating random string

P: n/a
Hi

I need to generate a string of six random characters to act as the first
password. Is there an example of how to do this somewhere?

Thanks

Regards
Apr 16 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
answered in post with same subject line, in microsoft.public.access
newsgroup.
"John" <Jo**@nospam.infovis.co.uk> wrote in message
news:BM********************@pipex.net...
Hi

I need to generate a string of six random characters to act as the first
password. Is there an example of how to do this somewhere?

Thanks

Regards

Apr 16 '06 #2

P: n/a
This will do it:

Public Function MakePass()
Dim Lets(6) As String
Dim PW As String
Dim i, j, k As Integer
j = 1
Do While j < 6
k = Int((122 * Rnd) + 65)
If (k >= 65 And k < 91) Or (k > 96 And k < 123) Then
Lets(j) = Chr(k)
j = j + 1
End If
Loop
PW = Lets(1) & Lets(2) & Lets(3) & Lets(4) & Lets(5) & Lets(6)
MakePass = UCase(PW)
End Function

This generates the password in upper case. You can remove UCase to
get upper and lower. This will repeat letters sometimes. So you
might get : ABCDEB or CDXXSZ.

If dups are a problm let me know and I can add the code to avoid them.

Good luck
Ira Solomon

On Sun, 16 Apr 2006 04:09:00 +0100, "John" <Jo**@nospam.infovis.co.uk>
wrote:
Hi

I need to generate a string of six random characters to act as the first
password. Is there an example of how to do this somewhere?

Thanks

Regards

Apr 16 '06 #3

P: n/a
Thanks Ira. Works great.

Regards

"Ira Solomon" <is******@solomonltd.com> wrote in message
news:gi********************************@4ax.com...
This will do it:

Public Function MakePass()
Dim Lets(6) As String
Dim PW As String
Dim i, j, k As Integer
j = 1
Do While j < 6
k = Int((122 * Rnd) + 65)
If (k >= 65 And k < 91) Or (k > 96 And k < 123) Then
Lets(j) = Chr(k)
j = j + 1
End If
Loop
PW = Lets(1) & Lets(2) & Lets(3) & Lets(4) & Lets(5) & Lets(6)
MakePass = UCase(PW)
End Function

This generates the password in upper case. You can remove UCase to
get upper and lower. This will repeat letters sometimes. So you
might get : ABCDEB or CDXXSZ.

If dups are a problm let me know and I can add the code to avoid them.

Good luck
Ira Solomon

On Sun, 16 Apr 2006 04:09:00 +0100, "John" <Jo**@nospam.infovis.co.uk>
wrote:
Hi

I need to generate a string of six random characters to act as the first
password. Is there an example of how to do this somewhere?

Thanks

Regards

Apr 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.