random letter generator

qwkslvr1999

Registered User.
Local time
Today, 00:39
Joined
Jan 21, 2002
Messages
42
I would like to create a function that will take numbers as inputs and generate a certain combination of 5 letters.

Let's use A,B,C,D,E for example. a user inputs how many A's or B's and so on, he wants to have in the output. It is not necessary that there is an input for every letter. So, a user can input 15 for A, 8 for D and 17 for E. The output should always be a 40-character combination. The specified letters should be arranged in a random order.

I tried the suggestion in another post titled "random 6 digit letter field" but I do not know how I can modify it to be able to specify the number of letters I want to appear in the result.

Hope someone will be able to help me this. Thanks!
 
Last edited:
Public Function GetRndString(Optional intA As Integer = 0, Optional intB As Integer = 0, _
Optional intC As Integer = 0, Optional intD As Integer = 0, _
Optional intE As Integer = 0, Optional intF As Integer = 0, _
Optional intG As Integer = 0, Optional intH As Integer = 0, _
Optional intI As Integer = 0, Optional intJ As Integer = 0, _
Optional intK As Integer = 0, Optional intL As Integer = 0, _
Optional intM As Integer = 0, Optional intN As Integer = 0, _
Optional intO As Integer = 0, Optional intP As Integer = 0, _
Optional intQ As Integer = 0, Optional intR As Integer = 0, _
Optional intS As Integer = 0, Optional intT As Integer = 0, _
Optional intU As Integer = 0, Optional intV As Integer = 0, _
Optional intW As Integer = 0, Optional intX As Integer = 0, _
Optional intY As Integer = 0, Optional intZ As Integer = 0)

Dim stTemp As String
Dim stNewString As String
Dim intRnd As Integer
Dim iLoop As Integer

For iLoop = 1 To 26
stTemp = stTemp & Space$(Choose(iLoop, intA, intB, intC, intD, intE, intF, intG, intH, intI, intJ, intK, intL, intM, intN, intO, intP, intQ, intR, intS, intT, intU, intV, intW, intX, intY, intZ))
stTemp = Replace(stTemp, " ", Choose(iLoop, "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"))
Next iLoop

Do While Len(stTemp) > 0
Randomize (0)
intRnd = (Rnd * Len(stTemp) + 1)
stNewString = stNewString & Mid(stTemp, intRnd, 1)
stTemp = Left(stTemp, intRnd - 1) & Mid(stTemp, intRnd + 1)
Loop
GetRndString = stNewString
End Function
 
Travis,

I was so excited to try your code but then when I tried to run it, it was looking for a function named replace!

Thanks!
 
See Knowledgebase article:

ACC: How to Replace a String with Another String
ID: Q109330


This will show you how to have a rreplace function in versions earlier then A2K.
 
Password Generator

How could this be modified to automatically produce a random password?
 
Here something to cut your teeth on:

Code:
Public Function RandomPassword(Optional iMaxLength As Integer = 10, Optional iMinLength As Integer = 5) As String
    Dim iLength As Integer
    Dim iCharacter As Integer
    Dim iLoop As Integer
    Dim strPassword As String
    
        Randomize (0)
        iLength = (Rnd * (iMaxLength - iMinLength) + iMinLength)
        
        For iLoop = 1 To iLength
            iCharacter = (Rnd * (93) + 33)
            strPassword = strPassword & Chr(iCharacter)
        Next iLoop
        
        RandomPassword = strPassword
        
End Function
 
Password generator

Hi

I am trying to put together a password generator database and I am having trouble with the basic design. Does anyone know what is needed to put a successful database together. The previous threads look great, but as I am a complete novice on this it would be helpful to get the whole package?? Please HELP!!!!
 

Users who are viewing this thread

Back
Top Bottom