Discussion Locked

How to generate random letters in vb6.0

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi

Just wondering how I would generate random letters in VB 6.0?

Cheers
Mark

3 replies

by john.a.wills

Use Rnd to get a number from 0 to 1. Multiply by 25, add 1, round to nearest integer. Convert 1 to A, 2 to B, etc.

by tom

Mark, try this out.....

Private Sub MakeRandom()
Dim theNum As Double
Dim theUpper As String
Dim theLower As String

' Upper Case
theUpper = Chr(64 + Rnd() * 10000000 Mod 26)
' Lower Case
theLower = Chr(96 + Rnd() * 10000000 Mod 26)

End Sub

by dvroman

Visually / Functionally The Function Would Be:
Chr$(Int(Rnd() * (Asc("Z") - Asc("A"))) + Asc("A"))
Cryptically It Would Be:
Chr$(Int(Rnd() * 25) + 65)

This discussion is closed to new replies.