home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / clarion / chkstr.zip / CHKSTR.CLA next >
Text File  |  1989-09-14  |  9KB  |  280 lines

  1.          TITLE('Demo Program for Check_String FUNCTION.')
  2.  
  3. !Program   : Chkstr
  4. !Module       : Chkstr.CLA
  5. !Function  : Test Check_String Function
  6. !Version   : 1.0
  7. !Author       : David Drake
  8. !       : Double-D Software
  9. !       : 4924 Chantilly
  10. !       : Las Vegas, Nv 89110
  11. !       : (702) 438-2173
  12. !Date       : September 14, 1989
  13. !Notice       : Copyright (c) 1989 David Drake.  All Rights Reserved.
  14. !
  15. !INSTRUCTIONS:
  16. !This test program demonstrates the Check_String Function.
  17. !Input the number to string (assumes 2 decimal places)
  18. !    (ie. 12345 assumes 123.45)
  19. !Input the maximum allowable return string length
  20. !The function will return the amount spelled out.
  21. !If the spelled out amount will not fit within the specified
  22. !maximum length, the function will attempt to compact the string
  23. !by not expanding some of the digits into words.
  24. !First it will compact the hundreds, then the thousands and finally
  25. !the millions as necessary.  Within each group (hundred,thousand,
  26. !million), the fucntion will first compact the amount less than
  27. !one hundred then the hundreds amount.
  28. !To see this compaction work, input a large number (12312312)
  29. !and a max length of 80, then decrease the maximum length.
  30. !
  31. !This function was converted from a basic routine that was part
  32. !of the check printing program for Accounts Payable.  It has NOT
  33. !been exhaustively tested after the conversion to Clarion, but I
  34. !believe it is relatively bug-free.  I would appreciate hearing
  35. !of any bugs found.
  36. !
  37.  
  38. CHKSTR    PROGRAM
  39.  
  40.          MAP
  41.         PROC(MAIN)
  42.         FUNC(Check_String),STRING
  43.         END
  44.  
  45. Amount         LONG
  46. Outstr         STRING(132)
  47. Length         BYTE
  48.          CODE
  49.   SETHUE(3,0)
  50.   BLANK()
  51.   MAIN
  52.  
  53. MAIN         PROCEDURE
  54.          CODE
  55.   LOOP
  56.    SHOW(1,20,'Amount:')
  57.    SHOW(2,20,'Maxlen:')
  58.    ASK(1,28,Amount,@n_12)
  59.    ASK(2,28,Length,@n_3)
  60.    IF AMOUNT = 0 THEN BREAK.
  61.    Outstr=Check_String(Amount,Length)
  62.    SHOW(4,1,Outstr)
  63.  .
  64.  
  65. !*************************************************
  66. !         Function CheckString
  67. !**************************************************
  68. Check_String FUNCTION(ChkAmt,MaxLen)
  69.  
  70. ChkAmt         EXTERNAL                 !Amount to Convert
  71. MaxLen         EXTERNAL                 !Max Length of return String
  72. String         STRING(132)
  73. RetStr         STRING(132)             !Return String
  74. WrkAmt         LONG                 !Temp Amt for Processing
  75.  
  76. Compact         BYTE
  77. Level_1         SHORT                 !First Level Compaction
  78. Level_2         SHORT                 !Second Level Compaction
  79.  
  80. Dollars         BYTE                 !Flag to output 'DOLLARS'
  81. Yes         BYTE(1)                 !logical YES
  82. No         BYTE(0)                 !Logical NO
  83. TmpStr         STRING(10)                 !Used by ones/tens routines
  84. TmpAmt         SHORT                 !Used to Hold 3-digit group
  85. Work         LONG                 !Used in Group Processing
  86. Temp         LONG                 !Used in Group Processing
  87. Word         STRING(10)
  88.  
  89.          CODE
  90. ! Start with Compacting Levels At Minimum
  91.    Level_1 = 0
  92.    Level_2 = 0
  93. !
  94. !Main Processing Loop
  95. !
  96. ! Generates full string and checks length
  97. !   If too long, Increments Compacting Level and tries again
  98. !      If still too long after max compaction, returns 'ERROR'
  99. !
  100.   LOOP
  101.     WrkAmt=ChkAmt                 !Set to Passed Amount
  102.     DO String_it                 !Convert to String
  103.     IF LEN(CLIP(String)) > MaxLen         !Too Long, Start Compaction
  104.        IF Level_1 = 0 THEN Level_1 = 1.         ! Turn Compaction Lvl1 on
  105.        Level_2 += 1                 !  Bump Level2 Setting
  106.        IF Level_2 > 2                 !  Hit Max Leel 2?
  107.       Level_1 += 1                 !    Yes, Bump Level 1
  108.       Level_2 = 1                 !       Reset Level 2
  109.       IF Level_1 > 3             !  Hit Max Compaction?
  110.          String='ERROR'             !   Yes, error
  111.          BREAK                 !
  112.       END
  113.        END
  114.     ELSE
  115.        BREAK                     !All ok, done
  116.     END
  117.   .
  118.     RETURN(LEFT(CLIP(string) & ALL('*',132),MaxLen))
  119.  
  120. !
  121. !Do Actual conversion of amount to String
  122. !   Will Respond to compaction levels as Follows
  123. !   Level_1 controls Which Groups of 3 digits will be compacted
  124. !   Level_2 Controls which Digits in a group will be compacted
  125. !
  126. !   Level_1 = 0 - No Compaction
  127. !          1 - Compact 100's
  128. !          2 - Compact 1000's and 100's
  129. !          3 - Compact 1000000's, 1000's and 100'
  130. !
  131. !   Level_2 = 0 - No Compaction
  132. !          1 - Compact 1-99 of group
  133. !          2 - Compact 100's of group
  134. !
  135. String_it    ROUTINE
  136.  
  137.      String=''                     !Start with Null string
  138.      Dollars=No                     ! no Dollars
  139.      Compact=No                     ! Compaction off
  140. !
  141. ! Process Millions, if any
  142. !
  143.      IF WrkAmt > 99999999             !millions
  144.     TmpAmt=INT(WrkAmt/100000000)         !Get Millions
  145.     Word = 'MILLION'             !set temp string
  146.     If Level_1 = 3 THEN Compact=Yes.     !level3 = compact millions
  147.     DO String_Group                 !String a 3 digit Group
  148.     Compact = No                 !Turn off Compacting
  149.     String = CLIP(String) & ' ' & CLIP(Word) !Build String
  150.     WrkAmt = WrkAmt - (TmpAmt*100000000)     !Reduce by Millions
  151.     Dollars = YES                 ! Yes, we have some dollars
  152.      END
  153. !
  154. ! Process Thousands, if any
  155. !
  156.      IF WrkAmt > 99999                 !thousands
  157.     TmpAmt=INT(WrkAmt/100000)         !Get Thousands
  158.     Word='THOUSAND'                 !set temp string
  159.     If Level_1 = 3 THEN Compact=Yes.     !level3 = compact millions
  160.     DO String_Group                 !String a 3 digit Group
  161.     Compact = No                 !Turn off Compacting
  162.     String = CLIP(String) & ' ' & CLIP(Word) !Build String
  163.     WrkAmt = WrkAmt - (TmpAmt*100000)     !Reduce by thousands
  164.     Dollars = Yes                 ! Ye, we have some dollars
  165.      END
  166. !
  167. ! Process Hundreds, if any
  168. !
  169.      IF WrkAmt > 99                 !dollars
  170.     TmpAmt=INT(WrkAmt/100)             !Get Thousands
  171.     If Level_1 = 3 THEN Compact=Yes.     !level3 = compact millions
  172.     DO String_Group                 !String a 3 digit Group
  173.     Compact = No                 !Turn off Compacting
  174.     WrkAmt = WrkAmt - (TmpAmt*100)         !Reduce by dollars
  175.     Dollars = Yes                 !Yes, Dollars
  176.      END
  177. !
  178. ! If there were no dollars, output 'ZERO'
  179. !
  180.      IF Dollars = No
  181.     String = 'ZERO'
  182.      END
  183. !
  184. ! Do cents processing
  185. !
  186.      String = CLIP(String) & ' AND '         ! xxxxx DOLLARS AND
  187.      IF WrkAmt = 0 THEN                 ! How many Cents?
  188.     String = CLIP(String) & ' ' & 'ZERO'     !   None!
  189.      ELSIF WrkAmt < 10                 !
  190.     String = CLIP(String) & ' ' & FORMAT(WrkAmt,@n_1)
  191.      ELSE
  192.     String = CLIP(String) & ' ' & FORMAT(WrkAmt,@n_2)
  193.      END
  194.      String = CLIP(String) & '/100 DOLLARS'     !Finish it
  195.      EXIT
  196. !
  197. ! Routine to run a 3-digit group (nnn) into a string
  198. !
  199. String_Group ROUTINE
  200.  
  201.       Work = TmpAmt                 !temp
  202.       IF Work > 99                 ! hundreds?
  203.      IF Compact = YES and Level_2 > 1     !yes, but compact?
  204.         String = CLIP(String) & ' ' & CLIP(FORMAT(Work,@s3))& ' ' !Compact
  205.         EXIT
  206.      ELSE
  207.         Temp = INT(Work/100)         !get Hundreds
  208.         DO Ones                 !string it
  209.         String = CLIP(String) & ' HUNDRED '     !HUNDREDS
  210.         Work = Work - (Temp*100)         !Reduce Work
  211.      END
  212.       END
  213. !
  214. !now only 1 - 99 possible
  215. !
  216.       IF Compact = YES and Level_2 > 0
  217.      String = CLIP(String) & ' ' & CLIP(FORMAT(Work,@s3))
  218.      EXIT
  219.       END
  220. !do teens
  221.       IF Work > 9 and Work < 20
  222.      Temp = Work
  223.      DO Tens
  224.      Temp = 0
  225.       ELSE
  226. !tens if any
  227.      Temp = INT(Work/10)
  228.      IF Temp ~= 0
  229.         DO Tens
  230.         Work = Work - (Temp*10)
  231.      END
  232. !ones if any
  233.      IF Work ~= 0
  234.         Temp = Work
  235.         DO Ones
  236.      END
  237.       END
  238.       EXIT
  239. !
  240. ! routine to do a single digit
  241. !
  242. Ones         ROUTINE
  243.          IF Temp = 1 THEN TmpStr = 'ONE'.
  244.          IF Temp = 2 THEN TmpStr = 'TWO'.
  245.          IF Temp = 3 THEN TmpStr = 'THREE'.
  246.          IF Temp = 4 THEN TmpStr = 'FOUR'.
  247.          IF Temp = 5 THEN TmpStr = 'FIVE'.
  248.          IF Temp = 6 THEN TmpStr = 'SIX'.
  249.          IF Temp = 7 THEN TmpStr = 'SEVEN'.
  250.          IF Temp = 8 THEN TmpStr = 'EIGHT'.
  251.          IF Temp = 9 THEN TmpStr = 'NINE'.
  252.          String = CLIP(String) & ' ' & CLIP(TmpStr)
  253.          EXIT
  254.  
  255. !
  256. ! Routine to do from 10 to 19
  257. !
  258. Tens         ROUTINE
  259.          IF Temp = 10 THEN TmpStr = 'TEN'.
  260.          IF Temp = 11 THEN TmpStr = 'ELEVEN'.
  261.          IF Temp = 12 THEN TmpStr = 'TWELVE'.
  262.          IF Temp = 13 THEN TmpStr = 'THIRTEEN'.
  263.          IF Temp = 14 THEN TmpStr = 'FOURTEEN'.
  264.          IF Temp = 15 THEN TmpStr = 'FIFTEEN'.
  265.          IF Temp = 16 THEN TmpStr = 'SIXTEEN'.
  266.          IF Temp = 17 THEN TmpStr = 'SEENTEEN'.
  267.          IF Temp = 18 THEN TmpStr = 'EIGHTEEN'.
  268.          IF Temp = 19 THEN TmpStr = 'NINETEEN'.
  269.          IF Temp = 2 THEN TmpStr = 'TWENTY'.
  270.          IF Temp = 3 THEN TmpStr = 'THIRTY'.
  271.          IF Temp = 4 THEN TmpStr = 'FOURTY '.
  272.          IF Temp = 5 THEN TmpStr = 'FIFTY'.
  273.          IF Temp = 6 THEN TmpStr = 'SIXTY'.
  274.          IF Temp = 7 THEN TmpStr = 'SEVENTY'.
  275.          IF Temp = 8 THEN TmpStr = 'EIGHTY'.
  276.          IF Temp = 9 THEN TmpStr = 'NINETY'.
  277.          String = CLIP(String) & ' ' & CLIP(TmpStr)
  278.          EXIT
  279.  
  280.