• Welcome to Valhalla Legends Archive.
 

generate random letters - vb

Started by haZe, March 03, 2003, 05:50 AM

Previous topic - Next topic

haZe

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

iago

#1
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
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Mesiah / haiseM

#2
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.
]HighBrow Innovations
Coming soon...

AIM Online Status: 

Noodlez

#3
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)

haZe

#4
thx that helped a lot