It's no bother at all - just ask away anytime - glad to help.
If you increase the number of digits in your codes then you need to make a small adjustment to both the encoding and decoding routines to take into account the number of digits in your coded version of the letters.
The same program but with 9 digits per code would be :
Dim Codes$(26,2)
Codes$(1,1) = "a" : Codes$(1,2) = "000000010"
Codes$(2,1) = "b" : Codes$(2,2) = "000000011"
Codes$(3,1) = "c" : Codes$(3,2) = "000000012"
Codes$(4,1) = "d" : Codes$(4,2) = "000000013"
Codes$(5,1) = "e" : Codes$(5,2) = "000000014"
Codes$(6,1) = "f" : Codes$(6,2) = "000000015"
Codes$(7,1) = "g" : Codes$(7,2) = "000000016"
Codes$(8,1) = "h" : Codes$(8,2) = "000000017"
Codes$(9,1) = "i" : Codes$(9,2) = "000000018"
Codes$(10,1) = "j" : Codes$(10,2) = "000000019"
Codes$(11,1) = "k" : Codes$(11,2) = "000000020"
Codes$(12,1) = "l" : Codes$(12,2) = "000000021"
Codes$(13,1) = "m" : Codes$(13,2) = "000000022"
Codes$(14,1) = "n" : Codes$(14,2) = "000000023"
Codes$(15,1) = "o" : Codes$(15,2) = "000000024"
Codes$(16,1) = "p" : Codes$(16,2) = "000000025"
Codes$(17,1) = "q" : Codes$(17,2) = "000000026"
Codes$(18,1) = "r" : Codes$(18,2) = "000000027"
Codes$(19,1) = "s" : Codes$(19,2) = "000000028"
Codes$(20,1) = "t" : Codes$(20,2) = "000000029"
Codes$(21,1) = "u" : Codes$(21,2) = "000000030"
Codes$(22,1) = "v" : Codes$(22,2) = "000000031"
Codes$(23,1) = "w" : Codes$(23,2) = "000000032"
Codes$(24,1) = "x" : Codes$(24,2) = "000000033"
Codes$(25,1) = "y" : Codes$(25,2) = "000000034"
Codes$(26,1) = "z" : Codes$(26,2) = "000000035"
Print "Encoding this is a test coded string"
Encoded$ = _Encode("this is a test coded string")
Print "Writing encoded version to file"
Delete File "encodedfile.txt"
Open To Write 1,"encodedfile.txt"
Write String 1, Encoded$
Close File 1
Print "Reading encoded version back from file"
Open To Read 1,"encodedfile.txt"
Read String 1,Line$
Close File 1
Print "Encoded version is :"
Print Line$
Print "Decoding"
Decoded$ = _Decode(Line$)
Print "Decoded version is :"
Print Decoded$
Wait Key
Function _Encode(String$)
ReturnString$ = ""
For Letter = 1 To Len(String$)
If Mid$(String$,Letter) <> " "
For Element = 1 To 26
If Codes$(Element,1) = Mid$(String$,Letter)
ReturnString$ = ReturnString$ + Codes$(Element,2)
Endif
Next Element
Else
ReturnString$ = ReturnString$ + " "
Endif
Next Letter
EndFunction ReturnString$
Function _Decode(String$)
ReturnString$ = ""
For Letter = 1 To Len(String$) Step 9
Coded$ = ""
For Parse = Letter To Letter + 8
Coded$ = Coded$ + Mid$(String$,Parse)
Next Parse
If Coded$ = " "
ReturnString$ = ReturnString$ + " "
Else
For Element = 1 To 26
If Codes$(Element,2) = Coded$
ReturnString$ = ReturnString$ + Codes$(Element,1)
Endif
Next Element
Endif
Next Letter
EndFunction ReturnString$
Four changes were made :
1) The coded versions of the letters as declared in the array were changed to nine digits ("10" became "000000010" for example)
2) The coded version of the " " was changed from "__" to "_________" because to keep the coded string uniform for later decoding, a space needs to be written out the same length as the coded version of the letter so "_________" = nine spaces.
(Note : I have used "_" do denote spaces to preserve the format)
3) The For..Next loop in the decoder code was changed from Step 2 to Step 9 to reflect the new number of digits in the code (9).
4) The part that decoded each letter was changed from Mid$(String$, Letter) + Mid$(Strings$, Letter + 1) to a quick For..Next loop to concatenate all 9 digits of the code - it could have been written as :
Coded$ = Mid$(String$, Letter) + Mid$(String$,Letter + 1) + Mid$(String$, Letter + 2) + Mid$(String$, Letter + 3) + Mid$(String$, Letter + 4) + Mid$(String$, Letter + 5) + Mid$(String$, Letter + 6) + Mid$(String$, Letter + 7) + Mid$(String$, Letter + 8)
It would have achieved the same thing only with more typing (I'm lazy so I prefer to type as little as I can get away with!)