Hola amigos del foro
La funcion adjunta la utilizo para convertir los numeros a letras y la he empleado con exito desde clipper 5x pasando por FW23 pero ahora que trato de utilizarla en FWH al parecer no funciona debido a que no se pueden utilizar variables privadas ni publicas. Esta funcion es de vital importancia para mi ya que el sistema que estoy desarrollando debe imprimir cheques... he buscado en el foro una funcion equivalente y me he encontrado con una bastante larga. Me gustaria la ayuda de alguno de ustedes que me pueda decir como reutilizar este codigo en FWH. Esta funcion trabaja perfectamente en mis programas de FW23 agradezco mucho la ayuda que me puedan brindar.
CODIGO DE LA FUNCION: (Fue tomada de un libro que se llama Clipper Sumer 87 de EIDOS...)
(para tratar de resolver el caso he definido todas las locales y publicas como STATIC pero no ha funcionado...)
*--------------------------------------------------------------------------------------------------------------------------*
FUNC NUMLETRAS(NUM)
PRIV GRUPOS[5],ENLETRA,GRUPO,NUMSTR,UNIDAD,DECENA,CENTENA,;
UNI0,UNI1,UNI2,UNI3,UNI4,UNI5,UNI6,UNI7,UNI8,UNI9,DEC0,;
DEC1,DEC2,DEC3,DEC4,DEC5,DEC6,DEC7,DEC8,DEC9,CEN0,CEN1,;
CEN2,CEN3,CEN4,CEN5,CEN6,CEN7,CEN8,CEN9,DEC11,DEC12,DEC13,;
DEC14,DEC15,DEC16,DEC17,DEC18,DEC19,CONECT1,CONECT2,CONECT3,;
CONECT4,CONECT5,UNILET,DECLET,CENLET,CONECTOR,GRUPOST,GRUPOSTR
PUBLIC NUMERO:=NUM
UNI0="IIF(NUMERO=0 .AND. GRUPO=1,'cero','')"
UNI1="IIF(DECENA='1',DEC1&UNIDAD,IIF(GRUPOS[GRUPO]='001'.AND. (GRUPO=2 .OR. GRUPO=4),'',IIF(GRUPO>2,'un','una')))"
UNI2="IIF(DECENA='1',DEC1&UNIDAD,'dos')"
UNI3="IIF(DECENA='1',DEC1&UNIDAD,'tres')"
UNI4="IIF(DECENA='1',DEC1&UNIDAD,'cuatro')"
UNI5="IIF(DECENA='1',DEC1&UNIDAD,'cinco')"
UNI6="IIF(DECENA='1',DEC1&UNIDAD,'seis')"
UNI7="IIF(DECENA='1',DEC1&UNIDAD,'siete')"
UNI8="IIF(DECENA='1',DEC1&UNIDAD,'ocho')"
UNI9="IIF(DECENA='1',DEC1&UNIDAD,'nueve')"
DEC0="''"
DEC1="IIF(UNIDAD='0','diez','')"
DEC11="once"
DEC12="doce"
DEC13="trece"
DEC14="catorce"
DEC15="quince"
DEC16="dieciseis"
DEC17="diecisiete"
DEC18="dieciocho"
DEC19="diecinueve"
DEC2="IIF(UNIDAD='0','veinte','veinti')"
DEC3="'treinta'+IIF(UNIDAD<>'O',' y ','')"
DEC4="'cuarenta'+IIF(UNIDAD<>'O',' y ','')"
DEC5="'cincuenta'+IIF(UNIDAD<>'O',' y ','')"
DEC6="'sesenta'+IIF(UNIDAD<>'O',' y ','')"
DEC7="'setenta'+IIF(UNIDAD<>'O',' y ','')"
DEC8="'ochenta'+IIF(UNIDAD<>'O',' y ','')"
DEC9="'noventa'+IIF(UNIDAD<>'O',' y ','')"
CEN0="''"
CEN1="IIF(DECENA+UNIDAD='00','cien','ciento')"
CEN2="'doscient'+IIF(GRUPO<3,'os','os')"
CEN3="'trescient'+IIF(GRUPO<3,'os','os')"
CEN4="'cuatrocient'+IIF(GRUPO<3,'os','os')"
CEN5="'quinient'+IIF(GRUPO<3,'os','os')"
CEN6="'seiscient'+IIF(GRUPO<3,'os','os')"
CEN7="'setecient'+IIF(GRUPO<3,'os','os')"
CEN8="'ochocient'+IIF(GRUPO<3,'os','os')"
CEN9="'novecient'+IIF(GRUPO<3,'os','os')"
CONECT1="''"
CONECT2="IIF(GRUPOS[2]>'000',' mil','')"
CONECT3="IIF(GRUPOS[3]>'000' .OR. GRUPOS[4]>'000',IIF(GRUPOS[3]='001','mill¢n','millones'),'')"
CONECT4="IIF(GRUPOS[4]>'000',' mil','')"
CONECT5="IIF(GRUPOS[5]>'000',IIF(GRUPOS[5]='001','bill¢n','billones'),'')"
ENLETRA=''
NUMSTR=ALLTRIM(STR(NUMERO))
NUMSTR=REPLICATE('0',15-LEN(NUMSTR))+NUMSTR
FOR GRUPO=1 TO 5
GRUPOS[5-GRUPO+1]=SUBSTR(NUMSTR,(GRUPO-1)*3+1,3)
NEXT
FOR GRUPO=5 TO 1 STEP -1
UNIDAD=RIGHT(GRUPOS[GRUPO],1)
DECENA=SUBSTR(GRUPOS[GRUPO],2,1)
CENTENA=LEFT(GRUPOS[GRUPO],1)
UNILET=UNI&UNIDAD
DECLET=DEC&DECENA
CENLET=CEN&CENTENA
GRUPOSTR=STR(GRUPO,1)
CONECTOR=CONECT&GRUPOSTR
ENLETRA=ENLETRA+" "+&CENLET+" "+&DECLET+&UNILET+&CONECTOR
NEXT
RETU ENLETRA
Ayuda con esta funcion...
- Patricio Avalos Aguirre
- Posts: 1060
- Joined: Fri Oct 07, 2005 1:56 pm
- Location: La Serena, Chile
- Contact:
Re: Ayuda con esta funcion...
Hola
he hecho un copy paste y funciona muy bien...
que error te da?

he hecho un copy paste y funciona muy bien...
que error te da?
Code: Select all | Expand
alert( NUMLETRAS(100) ) alert( NUMLETRAS(20000) ) alert( NUMLETRAS(999966) )

Saludos
Patricio
__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl
Patricio
__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl
- Hernan Diego Ceccarelli
- Posts: 84
- Joined: Fri Oct 07, 2005 4:51 pm
- Location: Rosario - Santa Fe - Argentina
- Contact:
Re: Ayuda con esta funcion...
Hola gente linda, como anda todo por aca !!!
Esta la hice yo, espero te satisfaga:

Esta la hice yo, espero te satisfaga:
Code: Select all | Expand
FUNCTION NumLetra( nImporte, nDec ) local cTexto:= '' /// Equivale a '999999999999.99' local cPicture:= Replicate('9',12) local lSonSoloCentavos:= .F., nCpn local cNumero,aU,aD,aV,aC,aE,aM local nImporteDec:= 0 DEFAULT nDec:= 2 if nImporte < 0 cTexto:= 'Menos' nImporte *=-1 /// Lo paso a positivo endif if nDec == 0 nImporte:= Int( nImporte ) endif if nDec > 0 cPicture+= '.' + Replicate('9', nDec) endif if nImporte < 1 .and. nImporte > 0 // Solo Decimales nImporteDec:= Val( SubStr( Transform( nImporte, "9.9999999999999999" ), 3, nDec ) ) nImporte := Val( AllTrim(Str(Int(nImporte))) + "." + AllTrim(Str(Int(nImporteDec))) ) endif //// Evaluo la cadena numerica ,dividiendola en cuadro partes: //// 999 - 999 - 999 - 999 y los decimales correspondientes. cNumero := Transform( nImporte , cPicture ) nImporte:= Val( cNumero ) do case case nImporte == 0 .and. nImporteDec == 0 cTexto := 'Cero' case nDec > 0 .and. nImporteDec > 0 nImporte:= nImporteDec cNumero := Transform( nImporte , cPicture ) lSonSoloCentavos:= .T. endcase aU:= {'Uno','Dos','Tres','Cuatro','Cinco','Seis','Siete','Ocho','Nueve'} aD:= {'Once','Doce','Trece','Catorce','Quince','Dieciseis','Diecisiete',; 'Dieciocho','Diecinueve'} aV:= {'Diez','Veinte','Treinta','Cuarenta','Cincuenta','Sesenta','Setenta',; 'Ochenta','Noventa'} aC:= {'Ciento','Doscientos','Trescientos','Cuatrocientos','Quinientos',; 'Seiscientos','Setecientos','Ochocientos','Novecientos'} aE:= {'Veintiuno','Veintidos','Veintitres','Veinticuatro','Veinticinco',; 'Veintiseis','Veintisiete','Veintiocho','Veintinueve'} aM:= {'Billones','Millones','Mil','/100'} for nCpn = 1 to 4 /// Los 4 '999' //// Analizo 1er. 9 /// if Val(SubStr(cNumero,1,1)) <> 0 // Si existe Centena !!! do case case SubStr(cNumero,1,3) == '100' cTexto:= AllTrim(cTexto) + Space(1) + SubStr(aC[1],1,4) otherwise cTexto:= AllTrim(cTexto) + Space(1) + aC[Val(SubStr(cNumero,1,1))] endcase endif //// Analizo 2do. 9 /// if Val(SubStr(cNumero,2,1)) <> 0 // Si existe Decena !!! do case case SubStr(cNumero,2,1) == '1' .and. SubStr(cNumero,3,1) <> '0' cTexto:= AllTrim(cTexto) + Space(1) + aD[ Val(SubStr(cNumero,3,1)) ] case SubStr(cNumero,2,1) == '2' .and. SubStr(cNumero,3,1) <> '0' cTexto:= AllTrim(cTexto) + Space(1) + aE[ Val(SubStr(cNumero,3,1)) ] otherwise cTexto:= AllTrim(cTexto) + Space(1) + aV[ Val(SubStr(cNumero,2,1)) ] endcase endif //// Analizo 3er. 9 /// if Val(SubStr(cNumero,3,1)) <> 0 // Si existe la Unidad !!! do case case SubStr(cNumero,2,1) == '1' .or. SubStr(cNumero,2,1) == '2' // Del 1 al 29 ya se habrian definido antes.- otherwise if Val(SubStr(cNumero,1,2)) <> 0 .and. Val(SubStr(cNumero,2,1)) <> 0 cTexto:= AllTrim(cTexto)+' y' endif cTexto:= AllTrim(cTexto) + Space(1) + aU[ Val(SubStr(cNumero,3,1)) ] endcase if nCpn <> 4 .and. SubStr(cNumero,3,1) == '1' .and. ; SubStr(cNumero,2,1) <> '1' cTexto:= SubStr( AllTrim(cTexto), 1, Len(AllTrim(cTexto))-1 ) /// Sino quedaria Uno millon o Uno mil => Le saco el ultimo caracter. endif endif if nCpn < 4 if ! Val(SubStr(cNumero,1,3)) == 0 cTexto:= AllTrim(cTexto) + Space(1) + aM[nCpn] endif if (nCpn == 1 .or. nCpn == 2) .and. Val(SubStr(cNumero,1,3)) == 1 /// ' 1' cTexto:= SubStr( AllTrim(cTexto) , 1, Len(AllTrim(cTexto))-4) + 'ón' /// Le saco el 'ones' y le pongo 'ón' endif endif cNumero:= SubStr( cNumero , 4 ) next cNumero:= SubStr(cNumero,2,2) /// Decimales del Nro. if Val(cNumero) <> 0 // Si tiene decimales cTexto:= AllTrim(cTexto)+' Con '+ cNumero +"/1"+Replicate("0",nDec) endif if lSonSoloCentavos cTexto:= StrTran(cTexto,'Uno','Un ') cTexto:= AllTrim(cTexto) + ' Centavo' if nImporte > 1 cTexto+= 's' endif if nDec <> 2 // No le Cabe la palabra "centavo<s>" cuando nDec no es 2. cTexto:= "Cero Con " + AllTrim(Str(nImporteDec))+"/1"+Replicate("0",nDec) endif endifRETURN( AllTrim( cTexto ) )
Re: Ayuda con esta funcion...
Jose
Revisa este post quizas te sirva
http://forums.fivetechsupport.com/viewtopic.php?f=6&t=16955&p=87963&hilit=literal#p87963
Saludos
Adhemar
Revisa este post quizas te sirva
http://forums.fivetechsupport.com/viewtopic.php?f=6&t=16955&p=87963&hilit=literal#p87963
Saludos
Adhemar
Saludos,
Adhemar C.
Adhemar C.
Re: Ayuda con esta funcion...
Hola amigos
voy a probar las informaciones que me han suministrado... y les informo.
Otra pregunta
En FWH se pueden utilizar variables publicas y privadas ?. En mi caso no he podido... me envia un error
voy a probar las informaciones que me han suministrado... y les informo.
Otra pregunta
En FWH se pueden utilizar variables publicas y privadas ?. En mi caso no he podido... me envia un error
Re: Ayuda con esta funcion...
Jose, claro que se pueden definir
Function tufuncion()
Local var1,var2
Public var3,var4
Private var5,var6
...
Return
Tendrías que mostrar el error, quizas sea ambiguas de advertencia por el nivel de advertencia en tu enlazador, en UEstudio viene por defecto 1 hay que ponerle 0
Saludos
Adhemar
Function tufuncion()
Local var1,var2
Public var3,var4
Private var5,var6
...
Return
Tendrías que mostrar el error, quizas sea ambiguas de advertencia por el nivel de advertencia en tu enlazador, en UEstudio viene por defecto 1 hay que ponerle 0
Saludos
Adhemar
Saludos,
Adhemar C.
Adhemar C.
Re: Ayuda con esta funcion...
Hola a todos:
Gracias Hernan, utilice la funcion suministrada y esta perfecta !!!
Caso cerrado !
Gracias Hernan, utilice la funcion suministrada y esta perfecta !!!
Caso cerrado !
Re: Ayuda con esta funcion...
Se me olvidava: Gracias Cuellar, tambien me funciono lo de las variables.