Results 1 to 8 of 8

Thread: Random letters/numbers...

Threaded View

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Random letters/numbers...

    This will generate Random numbers and letters at will, i know theres another kind, i just like making my own stuff
    VB Code:
    1. Private Sub Command1_Click()
    2. Call RndLetter(True)
    3. End Sub
    4.  
    5. Private Function RndLetter(Numbers As Boolean)
    6. Dim AscChr As String, ChrAsc As String, rnduplow As Integer
    7. Randomize
    8.       rnduplow = Int((3 * rnd) + 1)
    9.        AscChr = Abs(Int(97 - 122) * rnd - 97)
    10.         ChrAsc = Chr(AscChr)
    11.             If rnduplow = 1 Then
    12.                  MsgBox ChrAsc
    13.             ElseIf rnduplow = 2 Then
    14.                  MsgBox UCase(ChrAsc)
    15.             ElseIf rnduplow = 3 Then
    16.                 MsgBox Int((9 * rnd) + 1)
    17.             End If
    18. End Function

    And heres the way everyone else does it:
    VB Code:
    1. Public Function CreateRandomLetter(ByVal pblnUpperCase As Boolean) As String
    2. Dim lngAsc  As Long
    3. Dim strChar As String
    4.     Randomize
    5.     lngAsc = vbKeyA + CLng(Rnd * (vbKeyZ - vbKeyA))
    6.     If pblnUpperCase Then
    7.         strChar = LCase$(Chr$(lngAsc))
    8.     Else
    9.         strChar = LCase$(Chr$(lngAsc))
    10.     End If
    11.     CreateRandomLetter = strChar
    12. End Function

    enjoy guys

    edit**
    and heres a way to generate random anything

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4. Call RndAny
    5. End Sub
    6.  
    7. Private Sub RndAny()
    8. Dim AscChr As String, ChrAsc As String
    9. Randomize
    10.        AscChr = Abs(Int(0 - 255) * Rnd)
    11.         ChrAsc = Chr(AscChr)
    12.                  MsgBox ChrAsc
    13. End Sub
    Last edited by |2eM!x; Jun 4th, 2005 at 11:42 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width