Results 1 to 10 of 10

Thread: Number Generator XXX999

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    South Africa
    Posts
    113

    Number Generator XXX999

    Hi all,
    Silly easy question here.

    How can I go about generating a number in the format
    'AAA000"
    AAA001"
    ...
    AAA999
    AAB001
    ...
    AAZ999
    ABA000vance
    ...

    I need to be able to do this in Access (yuk) and so I cant use any fancy VB functions.

    Thanks in Advance
    You are living a pacifist dream, and if you dreaming it means you sleeping and you should damn well wake up!

  2. #2
    Hyperactive Member The Dutch Dude's Avatar
    Join Date
    Nov 2001
    Location
    Holland. Land of the Dutch. Home for me.
    Posts
    261
    You need to program this in VBA, then?
    Obey the dragon thing. Or not. Or possibly just a bit.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    South Africa
    Posts
    113
    Yep...but I dont mind a solution in VB since im sure the logic would help.
    You are living a pacifist dream, and if you dreaming it means you sleeping and you should damn well wake up!

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    Might not be elegant - but here's a solution:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. Dim lngChr1 As Long
    4. Dim lngChr2 As Long
    5. Dim lngChr3 As Long
    6. Dim lngNumber As Long
    7.  
    8. Dim strText As String
    9.  
    10. lngChr1 = 1
    11. lngChr2 = 1
    12. lngChr3 = 1
    13.  
    14. lngNumber = -1
    15.  
    16. Do
    17.     lngNumber = lngNumber + 1
    18.     If lngNumber > 999 Then
    19.         lngNumber = 0
    20.         lngChr3 = lngChr3 + 1
    21.         If lngChr3 > 26 Then
    22.             lngChr3 = 1
    23.             lngChr2 = lngChr2 + 1
    24.         End If
    25.         If lngChr2 > 26 Then
    26.             lngChr2 = 1
    27.             lngChr1 = lngChr1 + 1
    28.         End If
    29.         If lngChr1 > 26 Then Exit Do
    30.     End If
    31.     strText = Chr$(lngChr1 + 64) & Chr$(lngChr2 + 64) & Chr$(lngChr3 + 64) + Format$(lngNumber, "00#")
    32.     Debug.Print strText
    33. Loop
    34.  
    35. End Sub

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    South Africa
    Posts
    113
    Thanks alot.

    I havent been coding for over 3 years now and realise just how lazy and rubbish I have become
    You are living a pacifist dream, and if you dreaming it means you sleeping and you should damn well wake up!

  6. #6
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    VB Code:
    1. Dim n As Integer
    2. Dim x As Integer
    3. Dim y As Integer
    4. Dim z As Integer
    5.  
    6.  
    7. For x = 65 To 90
    8.     For y = 65 To 90
    9.         For z = 65 To 90
    10.             For n = 0 To 999
    11.                 Debug.Print Chr$(x) & Chr$(y) & Chr$(z) & Format$(n, "00#")
    12.             Next
    13.         Next
    14.     Next
    15. Next

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    dis1411 - that is much more elegant than mine

  8. #8
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048

  9. #9
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    Originally posted by dis1411
    Did looping come to mind immediately, or did you at least use my code as a jumping point?

  10. #10
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    when i saw number / letter generation like that, nested for..nexts came to mind

    i did copy and paste your debug.print line, although i changed it

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