KNOWLEDGE BASE
Tech Tip: Methods for Alphabet Number Conversions for alphabetic numbering in documents
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: December 13, 2018

In creating documents, a very common order scheme for creating lists, outlines, table of contents as well as identifying a page is to use numbers. The following below can also be used which is the use of alphabet numbering:

Alphbetic numbering can also be useful for things like extending content of an item that contains multiple sub items in lists and table of contents such as the following:

Below are two methods that can convert a Alphabet number to a number and vice versa:

 //--------------------------------------------------------------------------------- // Name: NUM_TO_ALPHABET_NUM // Description: Method will generate a alphabet number with a given number. // EX: 22 -> v, 45 -> ss, 68 -> ppp // // Parameters: // \$1 (LONGINT) - Number to conver to an alphabet number // Output: // \$0 (TEXT) - Alphabet number in text // --------------------------------------------------------------------------------C_LONGINT(\$1;\$num;\$i;\$numMinusOne;\$remainder;\$quotient)C_TEXT(\$0;\$alphaNum;\$letter)ARRAY TEXT(\$alphaLetter;0)\$num:=\$1 // Loading the Letters (a-z) to an ArrayFor (\$i;97;122)  APPEND TO ARRAY(\$alphaLetter;Char(\$i))End for \$alphaNum:=""\$remainder:=Mod(\$num;26)\$quotient:=int(\$num/26)Case of   : (\$quotient=0)   \$alphaNum:=\$alphaLetter{\$remainder}     : (\$quotient=1)   If (\$remainder=0)    \$alphaNum:=\$alphaLetter{26}   else    \$alphaNum:=\$alphaLetter{\$remainder}*2   End if      Else    If (\$remainder=0)    For (\$i;0;\$quotient-1)     \$alphaNum:=\$alphaNum+\$alphaLetter{26}    End for    Else     For (\$i;0;\$quotient)     \$alphaNum:=\$alphaNum+\$alphaLetter{\$remainder}    End for   End if End case\$0:=\$alphaNum

Here are some examples of using the command:

 C_TEXT(\$alphaNum1;\$alphaNum2;\$alphaNum3)\$alphaNum1:=NUM_TO_ALPHABET_NUM(22) // v\$alphaNum2:=NUM_TO_ALPHABET_NUM(45) // ss\$alphaNum3:=NUM_TO_ALPHABET_NUM(68) // ppp

ALPHABET_NUM_TO_NUM takes a Alphabet number in text and converts to a number:

 //--------------------------------------------------------------------------------- // Name: ALPHABET_NUM_TO_NUM // Description: Method will covert a given number to an alphabet number. // EX: v -> 22, ss -> 45, ppp -> 68 // // Parameters: // \$1 (LONGINT) - Number to conver to an alphabet number // Output: // \$0 (TEXT) - Alphabet number in text // --------------------------------------------------------------------------------C_TEXT(\$1;\$alphaText)C_LONGINT(\$0;\$num;\$i;\$pos)ARRAY TEXT(\$alphaLetter;0) // Loading the Letters (a-z) to an ArrayFor (\$i;97;122)   APPEND TO ARRAY(\$alphaLetter;Char(\$i))End for \$alphaText:=lowercase(\$1)\$num:=0For (\$i;1;Length(\$alphaText))  \$pos:=Find in array(\$alphaLetter;\$alphaText[[\$i]])  If (\$i=1)   \$num:=\$num+\$pos  Else    \$num:=\$num+26  End if End for \$0:=\$num

Here are some examples of using the command:

 C_LONGINT(\$num1;\$num2;\$num3)\$num1:=ALPHABET_NUM_TO_NUM("v") // 22\$num2:=ALPHABET_NUM_TO_NUM("ss") // 45\$num3:=ALPHABET_NUM_TO_NUM("ppp") // 68