Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2003
    Location
    London, England
    Posts
    52

    Unanswered: VBA to decode digits into letters

    Given that A = 1, B = 2, , Z = 26 how would you write a VBA function that decodes a string of digits into all the possible letter strings it could represent?

    Thus
    f(182491) = AHBDIA, AHXIA, RBDIA, RXIA

    The above example gives the letter strings corresponding to (1 8 2 4 9 1), (1 8 24 9 1), (18 2 4 9 1), (18 24 9 1) respectively.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Use the chr function or is it the asc funcion to get the ascii value of the character
    Use the mid function to extract a single character firm a variable.
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Sep 2003
    Location
    London, England
    Posts
    52
    My first problem is how to automatically split up the string of digits.

    Thus

    182491 may be split in 4 ways: (1 8 2 4 9 1), (1 8 24 9 1), (18 2 4 9 1), (18 24 9 1)

    18415188 may be split in 8 ways: (1 8 4 1 5 1 8 8), (1 8 4 1 5 18 8), (1 8 4 15 1 8 8), (1 8 4 15 18 8), (18 4 1 5 1 8 8), (18 4 1 5 18 8), (18 4 15 1 8 8), (18 4 15 18 8)
    Last edited by JLR; 07-13-13 at 15:58. Reason: emoticon removal

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    So encode using two digits per character
    01 02...09 10.....
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Sep 2003
    Location
    London, England
    Posts
    52
    Thanks for your answer but I'm still puzzled.
    How does encoding using 2 digits per character lead to, for example, 4 possibilities for 182491?
    Does 182491 become 01 08 02 04 09 01 and then how is it split into the four cases 1 8 2 4 9 1, 1 8 24 9 1, 18 2 4 9 1 and 18 24 9 1?

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    sorry I assumed your previous query was how to make certain you could decode. I don't understand what you are trying to do. doing what you are proposing is a naive one way translation. perhaps it would be better if you could give a brief description of what you want to achieve
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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