Search code examples
stringrandomvb6lettersalphabet

How to get a random letter in VB6?


I cannot convert those I see in VB.Net I wanted to create something like a "Word Factory" So I need to produce a random letter. I managed to get a random number using this

Dim x, first, last
first = 65
last = 90
x = Int((last - Min + 1) * Rnd + Min)

How about random letters from the alphabet? in VB6. Thanks.


Solution

  • You can turn an integer code point into a character with the Chr() function, and go back the other way with Asc().

    That means you can get a random letter with code such as:

    Dim mych As String
    mych = Chr(Asc("A") + 26 * Rnd)