|
|
|
| 12 February 2002 | Flip_Currency() |
| Author | W.M. Hinsch (New Mexico Mark) |
| Action | Add or remove the currency symbol (as defined in your system setup) in a number. |
| Syntax | Flip_Currency (String) |
| Parameters | |
| Remarks | This works fine as a stand-alone function, but it may be called from Fmt(), Flip_Numsep(), or Flip_Dec(). |
| Returns | A string. |
| Dependencies | None. |
| Examples |
"Flip_Currency($123.00) = " + Flip_Currency("$123.00") ?
"Flip_Currency(123.00) = " + Flip_Currency("123.00") ?
; Console Output (Example)
; Flip_Currency($123.00) = 123.00
; Flip_Currency(123.00) = $123.00
|
| Source |
FUNCTION Flip_Currency ($svar)
; This function takes an expression that evaluates to a string or that
; can be directly converted to a string. It adds (or removes if present)
; the system currency symbol in the place specified by the system and
; returns the modified string.
;
IF VarType($svar) < 2 OR VarType($svar) > 8
EXIT -1
ENDIF
DIM $ccur, $iloc, $ilen, $sreg
$svar = "" + $svar
$sreg = 'HKCU\Control Panel\International'
$ccur = ReadValue($sreg,'sCurrency')
$iloc = Val(ReadValue($sreg,'iCurrency'))
$ilen = Len($svar)
SELECT
CASE $iloc = 0 ; "$2"
IF Substr($svar,1,1) = $ccur
$flip_currency = Substr($svar,2)
ELSE
$flip_currency = $ccur + $svar
ENDIF
CASE $iloc = 1 ; "2$"
IF $ilen > 1
IF Substr($svar,$ilen - 1,1) = $ccur
$flip_currency = Substr($svar,1,$ilen - 1)
ELSE
$flip_currency = $svar + $ccur
ENDIF
ENDIF
CASE $iloc = 2 ; "$ 2"
IF Substr($svar,1,2) = $ccur + " "
$flip_currency = Substr($svar,3)
ELSE
$flip_currency = $ccur + " " + $svar
ENDIF
CASE $iloc = 3 ; "2 $"
IF $ilen > 2
IF Substr($svar,$ilen - 2,2) = " " + $ccur
$flip_currency = Substr($svar,1,$ilen - 2)
ELSE
$flip_currency = $svar + " " + $ccur
ENDIF
ELSE
$flip_currency = $svar + " " + $ccur
ENDIF
ENDSELECT
ENDFUNCTION ; - Flip_Currency -
|
|
|
|