#include "FiveWin.ch"
Function Main()
Local aLet, cNum := Space( 20 )
While .T.
If MsgGet( "Números a Letras", "Número:", @cNum )
aLet := aNumLet( Val( cNum ), 100 )
MsgInfo( aLet[ 1 ] + CRLF + aLet[ 2 ], "En Letras" )
cNum := Space( 20 )
Else
Exit
EndIf
EndDo
Return Nil
//--------------------------------------------------------------//
Function aNumLet( nVar, nLong )
Local aCent := { "CIENTO", "DOSCIENTOS", "TRESCIENTOS", "CUATROCIENTOS", "QUINIENTOS", "SEISCIENTOS", ;
"SETECIENTOS", "OCHOCIENTOS", "NOVECIENTOS" }, ;
aUnid := { "UN", "DOS", "TRES", "CUATRO", "CINCO", "SEIS", "SIETE", "OCHO", "NUEVE" }, ;
aDece := { "DIEZ", "ONCE", "DOCE", "TRECE", "CATORCE", "QUINCE", "DIECISEIS", "DIECISIETE", "DIECIOCHO", ;
"DIECINUEVE", "VEINTE", "VEINTIUN", "VEINTIDOS", "VEINTITRES", "VEINTICUATRO", "VEINTICINCO", ;
"VEINTISEIS", "VEINTISIETE", "VEINTIOCHO", "VEINTINUEVE" }, ;
aDece1 := { "", "", "TREINTA", "CUARENTA", "CINCUENTA", "SESENTA", "SETENTA", "OCHENTA", "NOVENTA" }, ;
cNumalf := Transform( nVar, "############.##" )
Local aN2 := { Val( SubStr( cNumalf, 1, 3 ) ), Val( SubStr( cNumalf, 4, 3 ) ), Val( SubStr( cNumalf, 7, 3 ) ), ;
Val( SubStr( cNumalf, 10, 3 ) ), Val( SubStr( cNumalf, 14, 2 ) ) }, ;
aN1 := {}, ;
aRet := {}, ;
nV1 := 0, ;
cLetra := "( " + If( Int( nVar ) == 0, "CERO ", "" )
nLong := If( ValType( nLong ) = "N" .and. nLong > 0, nLong, 75 )
For nV1 := 1 To 4
aN1 := { Val( SubStr( Str( aN2[ nV1 ], 3 ), 1, 1 ) ), Val( SubStr( Str( aN2[ nV1 ], 3 ), 2, 1 ) ), ;
Val( SubStr( Str( aN2[ nV1 ], 3 ), 3, 1 ) ), Val( SubStr( Str( aN2[ nV1 ], 3 ), 2, 2 ) ) }
cLetra += If( aN1[ 1 ] > 0, If( aN1[ 1 ] == 1 .and. aN1[ 4 ] == 0, ;
"CIEN ", Trim( aCent[ aN1[ 1 ] ] ) + Space( 1 ) ), "" )
cLetra += If( aN1[ 4 ] > 9 .and. aN1[ 4 ] < 30, Trim( aDece[ aN1[ 4 ] - 9 ] ) + Space( 1 ), "" )
cLetra += If( aN1[ 4 ] > 29, aDece1[ aN1[ 2 ] ] + Space( 1 ) + If( aN1[ 3 ] > 0, "Y ", "" ), "" )
cLetra += If( aN1[ 4 ] > 29 .or. aN1[ 4 ] < 10, If( aN1[ 3 ] > 0, ;
aUnid[ aN1[ 3 ] ] + Space( 1 ), "" ), "" )
cLetra += If( nV1 = 2 .and. nVar > 999999.99, If( aN2[ nV1 ] != 1, "MILLONES", "MILLON" ) + ;
If( aN2[ 3 ] == 0 .and. aN2[ 4 ] = 0, " DE ", ", " ), "" )
cLetra += If( ( nV1 = 1 .and. aN2[ nV1 ] > 0 ) .or. ( nV1 == 3 .and. aN2[ nV1 ] > 0 ), "MIL ", "" )
Next
cLetra += If( nVar > 1.99 .or. nVar < 1.00, "PESOS ", "PESO " ) + StrZero( aN2[ 5 ], 2 ) + "/100 M.N. )"
cLetra := PadR( cLetra, nLong * 2 )
aRet := { MemoLine( cLetra, nLong, 1 ), Memoline( cLetra, nLong, 2 ) }
Return aRet /* regresa un arreglo con 2 elementos de longitud = nLong */