# Thread: VBA to decode digits into letters

1. Registered User
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.

Join Date
Nov 2004
Location
out on a limb
Posts
13,692
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.

3. Registered User
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

Join Date
Nov 2004
Location
out on a limb
Posts
13,692
So encode using two digits per character
01 02...09 10.....

5. Registered User
Join Date
Sep 2003
Location
London, England
Posts
52
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?

Join Date
Nov 2004
Location
out on a limb
Posts
13,692