home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / os2 / etelr212 / sformat.vrm < prev    next >
Text File  |  1994-09-01  |  4KB  |  127 lines

  1. /* Custom mainline for macro */
  2.  
  3.     signal on SYNTAX name _VRESyntax
  4.     signal _VREMain
  5.  
  6. _VRESyntax:
  7.     parse source . . _VRESourceSpec
  8.     call VRMessage "", "Syntax error in" _VRESourceSpec "line" SIGL":" ErrorText(rc), "Error!"
  9.     exit 32000
  10.  
  11. _VREMain:
  12. /*:VRX         Main
  13. */
  14. Main:
  15. /***********************************************/
  16. /* VX-Rexx Macro to strip char. strings from   */
  17. /* amounts & put them back again.              */
  18. /* Please do not modify                        */
  19. /***********************************************/
  20. signalled = 1
  21. parse upper arg value action .
  22. call VRMethod 'Application', 'GetVar', 'currency.'
  23. sDecimal = currency.5
  24. iDigits = currency.2
  25. sThousand = currency.4
  26. if action = 'STRIP' then
  27.     signal iStrip
  28. minus = 0
  29. if value = '' | DataType( value ) <> 'NUM' then 
  30.     value = 0
  31. if value = 0 then do
  32.     value = 0
  33.     signalled = 0
  34.     call iStrip
  35. end
  36. valLen = Length( value )
  37. if valLen = 1 then do
  38.     value = '0'||value
  39.     valLen = 2
  40. end
  41. pos = valLen - iDigits
  42. if( POS( '.', sDecimal ) <> 0 )then 
  43.     value = Insert( '.', value, pos )
  44. if( POS( ',', sDecimal ) <> 0 )then 
  45.     value = Insert( ',', value, pos )
  46. if( Left( value, 1 ) = '-' )then do
  47.     minus = 1
  48.     value = Strip( value, 'L', '-' )
  49. end
  50. if POS( '.', sDecimal ) <> 0 then 
  51.     parse var value dollar '.' cent
  52. if POS( ',', sDecimal ) <> 0 then 
  53.     parse var value dollar ',' cent
  54. if Length( dollar ) >= 4 then do
  55.     NewDollar = ''
  56.     Remainder = Right( dollar, 3 )
  57.     do until Remainder = ''
  58.         NewDollar = Remainder||NewDollar
  59.         if( Length( dollar ) <= 2 )then
  60.             leave
  61.         dollar = DelStr( dollar, Length( dollar) - 2 )
  62.         remainder = Right( dollar, 3 )
  63.         if remainder = '' then
  64.             leave
  65.         if POS( ',', sThousand ) <> 0 then 
  66.             NewDollar = ','||NewDollar
  67.         if POS( '.', sThousand ) <> 0 then 
  68.             NewDollar = '.'||NewDollar
  69.         if POS( "'", sThousand ) <> 0 then 
  70.             NewDollar = "'"||NewDollar
  71.         if POS( ';', sThousand ) <> 0 then 
  72.             NewDollar = ';'||NewDollar
  73.         if POS( ' ', sThousand ) <> 0 then 
  74.             NewDollar = ' '||NewDollar
  75.     end
  76.     dollar = NewDollar
  77. end
  78. if( POS( '.', sDecimal ) <> 0 )then 
  79.     value = dollar||'.'||cent
  80. if( POS( ',', sDecimal ) <> 0 )then 
  81.     value = dollar||','||cent
  82. if dollar = 0 & POS( '0', iLzero ) <> 0 then 
  83.     value = DelStr( value, 1, 1 )
  84. value = Strip( value, 'L' )
  85. if minus = 1 then value = '-'||value
  86. drop dollar cent pos newdollar remainder centlen valLen minus
  87. rc = value
  88. call VRMethod 'Application', 'PutVar', 'rc'
  89. exit
  90.  
  91. iStrip:
  92. minus = 0
  93. if( Left( value, 1 ) = '-' )then
  94.     minus = 1
  95. if POS( '.', sDecimal ) <> 0 then
  96.     parse var value dollars '.' cents
  97. if POS( ',', sDecimal ) <> 0 then
  98.     parse var value dollars ',' cents
  99. CentLen = Length( cents )
  100. if CentLen <> 0 then do
  101.     if CentLen < iDigits then
  102.         do iDigits - Centlen
  103.             cents = cents||'0'
  104.         end
  105.     if CentLen > iDigits then
  106.         cents = DelStr( cents, ( Length( value ) - ( CentLen - iDigits ) + 1 ) )
  107. end
  108. if CentLen = 0 then
  109.     do iDigits
  110.         cents = cents||'0'
  111.     end
  112. value = dollars||cents
  113. valLen = Length( value )
  114. do i = 1 to valLen
  115.     if Datatype( SubStr( value, i, 1 ) ) = 'CHAR' then
  116.         value = DelStr( value, i, 1 )
  117. end
  118. drop dollars cents CentLen i
  119. if minus = 1 then
  120.     value = '-'||value
  121. if signalled = 0 then
  122.     return
  123. rc = value
  124. call VRMethod 'Application', 'PutVar', 'rc'
  125. exit
  126.  
  127.