Valhalla Legends Archive

Programming => General Programming => Topic started by: haZe on March 03, 2003, 05:50 AM

Title: generate random letters - vb
Post by: haZe on March 03, 2003, 05:50 AM
does anyone know how to make a textbox generate random letters as its text? code, please, and yes, its VB if u didnt read the subject :p
Title: Re: generate random letters - vb
Post by: iago on March 03, 2003, 06:01 AM
randomize timer
for iIndex = 0 to iAmount
    txtBlah = txtBlah + chr(int(rnd * 26) + asc("A"))
next

This is totally untested, but should fill txtBlah with iAmount random capital characters
Title: Re: generate random letters - vb
Post by: Mesiah / haiseM on March 04, 2003, 11:40 AM
i use this for random hex char's, it might be able to get you at least started:

Public Function RandomLetter(finished As Long) As String
    Randomize
    Dim anus As Long
    anus = Int((Val(finished) * Rnd) + 1)
    RandomLetter = Hex(anus)
End Function

just replace hex(anus) with chr(anus) and it should be fine.
Title: Re: generate random letters - vb
Post by: Noodlez on March 04, 2003, 08:10 PM
Public Function RandomString(Length As Long) As String
    Dim lLetters As String, uLetters As String
    lLetters = "1a2b3c4d5e6f7g8h9i0jklmnopqrstuv"
    uLetters = "ABCDEFGHIJKLM1N2O3P4Q5R6S7T8U9V0"

    For I = 1 To Length
        If Int(Rnd * 2) = 1 Then
            Randomize
            RandomString = RandomString & Mid$(lLetters, Int(Rnd * 32), 1)
        Else
            Randomize
            RandomString = RandomString & Mid$(uLetters, Int(Rnd * 22), 1)
        End If
    Next I

End Function
this'll generate a random string containing lowercase/uppercase and the numbers 1-9

usage:
Text1 = RandomString(10)
Title: Re: generate random letters - vb
Post by: haZe on March 05, 2003, 10:48 AM
thx that helped a lot