Results 1 to 5 of 5

Thread: I asked this question before but,....

  1. #1

    Thread Starter
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Ok. i want to be able to have the somputer choose like 7 digits and letters only. like
    abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_

    and it chooses Ac34B2z
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  2. #2
    Addicted Member
    Join Date
    May 2000
    Posts
    240

    Question How do you mean?

    What is the question??


    Do you want it to choose them in a random way or what..???




  3. #3

    Thread Starter
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    yah. randomly choose 7 digits from the all the letters and numbers
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  4. #4
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    ok, here
    Code:
    Function GetRandom(length As Integer) As String
    
    Dim keystring As String 'to hold return
    Randomize 'randomize RND generator
    Dim b As Integer 'loop var
    For b = 1 To length 'loop
        Select Case Int((3 - 1 + 1) * Rnd + 1) 'pick Caps, Lower, or Nums
            Case 1
                keystring = keystring & Chr(Int((57 - 48 + 1) * Rnd + 48)) 'get random number
            Case 2
                keystring = keystring & Chr(Int((90 - 65 + 1) * Rnd + 65)) 'get random capital
            Case 3
                keystring = keystring & Chr(Int((122 - 97 + 1) * Rnd + 97)) 'get radnom lowercase
        End Select
    Next b
    GetRandom = keystring
    [Edited by gwdash on 10-07-2000 at 04:27 PM]
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  5. #5
    Guest
    Try this code:

    Code:
    Public Function GetRandomString(ByRef CharsToChooseFrom As String, ByVal NumberOfCharsToReturn) As String
        Dim T As Integer
        Dim TmpStr As String
        
        Randomize Timer
        For T = 1 To NumberOfCharsToReturn
            TmpStr = TmpStr + Mid(CharsToChooseFrom, CInt(Rnd * (Len(CharsToChooseFrom) - 1)) + 1, 1)
        Next T
        GetRandomString = TmpStr
    End Function
    Usage:

    TheString=GetRandomString("abcABC123",5)

    This wil return 5 chars, each of them will be a,b,c,A,B,C,1,2 or 3.

    To test with your given info:

    Code:
    Debug.Print GetRandomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_", 7)

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