This will generate Random numbers and letters at will, i know theres another kind, i just like making my own stuff![]()
VB Code:
Private Sub Command1_Click() Call RndLetter(True) End Sub Private Function RndLetter(Numbers As Boolean) Dim AscChr As String, ChrAsc As String, rnduplow As Integer Randomize rnduplow = Int((3 * rnd) + 1) AscChr = Abs(Int(97 - 122) * rnd - 97) ChrAsc = Chr(AscChr) If rnduplow = 1 Then MsgBox ChrAsc ElseIf rnduplow = 2 Then MsgBox UCase(ChrAsc) ElseIf rnduplow = 3 Then MsgBox Int((9 * rnd) + 1) End If End Function
And heres the way everyone else does it:
VB Code:
Public Function CreateRandomLetter(ByVal pblnUpperCase As Boolean) As String Dim lngAsc As Long Dim strChar As String Randomize lngAsc = vbKeyA + CLng(Rnd * (vbKeyZ - vbKeyA)) If pblnUpperCase Then strChar = LCase$(Chr$(lngAsc)) Else strChar = LCase$(Chr$(lngAsc)) End If CreateRandomLetter = strChar End Function
enjoy guys
edit**
and heres a way to generate random anything
VB Code:
Option Explicit Private Sub Command1_Click() Call RndAny End Sub Private Sub RndAny() Dim AscChr As String, ChrAsc As String Randomize AscChr = Abs(Int(0 - 255) * Rnd) ChrAsc = Chr(AscChr) MsgBox ChrAsc End Sub






Reply With Quote