Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Number/Alphabet Generator

Status
Not open for further replies.

Ma3x323

Programmer
Jun 27, 2001
148
US
Hey Guys/Gals,
I have a field that I want to generate random variables in. It's basically an Order # in which I want a specific length of variables. I just want this field to produce a random Order #. ie: 6 long - UJ875J 8HGBKJ TFGSB7

Any ideas/opinions???

Thanks for the help in advance.

-Feryl
 
Hmmmmmmmmmmmmmm,

Sounds like a bad idea gone awry.

Using a random 'value' for an invoice id may produce duplicate values.

You can, of course, just restrict the output of the random generator to the range of ASCII charactrs of interest and use the random values as the Chr codes. Generatiing six codes, normalizing them to a range, and 'mapping the range to your sub-set of ASCII Characters would do the job, I'm just not at all sure this is a job which needs doing.

so, the following:

Code:
Public Function basRandInvoice() As String

    Dim tmpStr As String
    Dim ChrCode As Integer

    For Idx = 1 To 6
        ChrCode = (Rnd() * 36) + 1
        Select Case ChrCode
            Case 1 To 26        'Make this an UCase Alpha
                tmpStr = tmpStr & Chr(ChrCode + 64)
            Case 27 To 36       'Make this one a numeral
                tmpStr = tmpStr & Chr(ChrCode + 21)
        End Select
    Next Idx

    basRandInvoice = tmpStr

End Function

should produce the (rather ill advised for the announced purpose) results.



MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Hey Joe,
Do I need to use that Entisoft Tools? Or Do I have to declare those functions somewhere? Sorry, I am a C++ programmer and just starting VBA. I wrote down the function but it said it is not declared.

-Feryl
 
You need to purchase the program, it comes with a DLL that makes those functions work. Joe Miller
joe.miller@flotech.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top