The HotDocs Computation Archive  

SET TextVar TO "«TextVar:LIKE THIS»" SET Tempn TO LENGTH( TextVar ) SET LoopLimitn[ Tempn ] TO 1 0 REPEAT Loop // Look at the next two characters SET Chart TO MID( TextVar, COUNTER, 1 ) IF COUNTER < Tempn SET Nextt TO MID( TextVar, COUNTER + 1, 1) ELSE SET Nextt TO "" END IF // 1s IF Chart = "I" IF Nextt = "V" OR Nextt = "X" OR Nextt = "L" OR Nextt = "C" OR Nextt = "D" OR Nextt = "M" RESULT  1 ELSE RESULT + 1 END IF // 5s ELSE IF Chart = "V" IF Nextt = "X" OR Nextt = "L" OR Nextt = "C" OR Nextt = "D" OR Nextt = "M" RESULT  5 ELSE RESULT + 5 END IF // 10s ELSE IF Chart = "X" IF Nextt = "L" OR Nextt = "C" OR Nextt = "D" OR Nextt = "M" RESULT  10 ELSE RESULT + 10 END IF // 50s ELSE IF Chart = "L" IF Nextt = "C" OR Nextt = "D" OR Nextt = "M" RESULT  50 ELSE RESULT + 50 END IF // 100s ELSE IF Chart = "C" IF Nextt = "D" OR Nextt = "M" RESULT  100 ELSE RESULT + 100 END IF // 500s ELSE IF Chart = "D" IF Nextt = "M" RESULT  500 ELSE RESULT + 500 END IF // 1000s ELSE IF Chart = "M" RESULT + 1000 END IF SET LoopLimitn TO UNANSWERED END REPEAT SET Tempn TO UNANSWERED SET Chart TO UNANSWERED SET Nextt TO UNANSWERED
This computation is for the rare occasion when you need to convert a Roman numeral back into a standard numeral (e.g. "MCMXCIX" > 1999). The result is a HotDocs number value.
NOTE: To format a standard numeral as a Roman numeral, just use the "IX" format for the number.
This computation uses a simple loop in the form of a repeated dialog called Loop. A detailed explanation of how the loop works is available in Computation #0015: Loops Via REPEAT. The dialog has a single number variable in it called LoopLimitn. Set this variable's Advanced options to "Ask only in dialog," "Don't warn if unanswered," and "Don't save in answer file." The computation also uses two other temporary text variables, Chart and Nextt. Set their Advanced options just like you did for LoopLimitn. These variables store the current characters being analyzed.
The computation uses the Loop to examine each character of the Roman numeral, one at a time. On any given pass, the computation will store the current character in Chart and the character following it (if any) in Nextt. We do this because we must see two Roman numerals at a time, as you'll see.
The computation then examines the character in Chart to determine what it is. It must then look at the following character to see if it is higher in order. If so, the current character is reducing the overall value. Otherwise it is increasing it. For example, the character "I" normally increases the overall value by 1 (e.g. VI = 5 + 1, or 6; VIII = 5 + 1 + 1 + 1, or 8). But if a higherorder character follows it, it reduces the overall value by 1 (e.g. IV = 1 + 5, or 4; IX = 1 + 10, or 9).
The computation returns the numeric equivalent of the Roman numeral
This template has everything you need set up and configured for you. It will work asis, or can be adapted to your variable and dialog names. It contains: 1) sample Word and WordPerfect templates (or an Automator form) to demonstrate an implementation of the computation, 2) a component file containing the computation and all supporting dialogs and variables, and 3) instructions for adapting the computation for your use.