|
FUNCTION anciennete(datedeb,cejour)
LOCAL nbjour as Integer ,nbmois as Integer
m.nbjour= m.cejour - m.datedeb
m.nban=INT(m.nbjour/365)
m.nbmois =(YEAR(m.cejour)-YEAR(m.datedeb))*12+MONTH(m.cejour)-MONTH(m.datedeb) - (m.nban*12)
m.retour=el_callet(m.nban," an")+" "+ IIF(m.nbmois>0," et " +el_callet(m.nbmois,IIF(nbmois>1," moi"," Mois")),"")
RETURN retour
Function el_callet(chiffre,monai)
Local i as Integer ,T as Integer
Local cChif as string
Local tChif as string
Local aniveau,texte,arangs,amil,aexcep,avcex
If Vartype(monai)="L"
monai="€uros"
Endif
chiffre=Iif(Vartype(chiffre)=="C",Val(chiffre),chiffre)
chiffre=Iif(Vartype(chiffre)=="N".And.chiffre<0,chiffre*-1,chiffre)
cChif=Ltrim(Transform(Round(Iif(Vartype(chiffre)=="C",Val(chiffre),chiffre),2),"999999999999999.99"))
tChif=Left(cChif,Len(cChif)-3)
Dimension aniveau[1,2],amil[5]
Dimension arangs[9,3],aexcep[12,2],avcex[2,2]
texte=""
arangs[1,1]="cent "
arangs[1,2]="dix "
arangs[1,3]="un "
arangs[2,1]="deux cents "
arangs[2,2]="vingt "
arangs[2,3]="deux "
arangs[3,1]="trois cents "
arangs[3,2]="trente "
arangs[3,3]="trois "
arangs[4,1]="quatre cents "
arangs[4,2]="quarante "
arangs[4,3]="quatre "
arangs[5,1]="cinq cents "
arangs[5,2]="cinquante "
arangs[5,3]="cinq "
arangs[6,1]="six cents "
arangs[6,2]="soixante "
arangs[6,3]="six "
arangs[7,1]="sept cents "
arangs[7,2]="soixante dix "
arangs[7,3]="sept "
arangs[8,1]="huit cents "
arangs[8,2]="quatre vingts "
arangs[8,3]="huit "
arangs[9,1]="neuf cents "
arangs[9,2]="quatre vingt dix "
arangs[9,3]="neuf "
amil[1]=monai
amil[2]="mille"
amil[3]="million"
amil[4]="milliard"
amil[5]="billion"
aexcep[1,1]="dix un"
aexcep[1,2]="onze"
aexcep[2,1]="dix deux"
aexcep[2,2]="douze"
aexcep[3,1]="dix trois"
aexcep[3,2]="treize"
aexcep[4,1]="dix quatre"
aexcep[4,2]="quatorze"
aexcep[5,1]="dix cinq"
aexcep[5,2]="quinze"
aexcep[6,1]="dix six"
aexcep[6,2]="seize"
aexcep[7,1]="vingt un"
aexcep[7,2]="vingt et un"
aexcep[8,1]="trente un"
aexcep[8,2]="trente et un"
aexcep[9,1]="quarante un"
aexcep[9,2]="quarante et un"
aexcep[10,1]="cinquante un"
aexcep[10,2]="cinquante et un"
aexcep[11,1]="soixante un"
aexcep[11,2]="soixante et un"
aexcep[12,1]="soixante onze"
aexcep[12,2]="soixante et onze"
avcex[1,1]="vingts"
avcex[1,2]="vingt"
avcex[2,1]="cents"
avcex[2,2]="cent"
i=1
Do .T.
If i=1
aniveau[1,1]=Right(tChif,Iif(Len(tChif)>2,3,Len(tChif)))
aniveau[1,2]=""
Else
Dimension aniveau[i,2]
aniveau[i,1]=Right(tChif,Iif(Len(tChif)>2,3,Len(tChif)))
aniveau[i,2]=""
Endif
i=i+1
tChif=Left(tChif,Len(tChif)-3)
If Len(tChif)==0
Exit
Endif
Enddo
For i=1 To Alen(aniveau,1)
aniveau[i,1]=Iif(Len(aniveau[i,1])<3,Padl(aniveau[i,1],3,"0"),aniveau[i,1])
For T=1 To Len(aniveau[i,1])
If Substr(aniveau[i,1],T,1)<>"0"
aniveau[i,2]=aniveau[i,2]+arangs[val(substr(aniveau[i,1],T,1)),T]
Endif
Next
If i>1
aniveau[i,2]=aniveau[i,2]+amil[i]+Iif(Val(aniveau[i,1])>1.And.i>2,"s "," ")
Endif
Next
For i=Alen(aniveau,1) To 1 Step -1
texte=texte+aniveau[i,2]
Next
For i=1 To 12
texte=Strtran(texte,aexcep[i,1],aexcep[i,2])
Next i
texte=Iif(Left(texte,8)="un mille",Right(texte,Len(texte)-3),texte)
For i=1 To 2
texte=Strtran(Left(texte,Len(texte)-4),avcex[i,1],avcex[i,2])+Right(texte,4)
Next
texte=texte+Iif(Len(Alltrim(texte))>2,;
amil[1]+"s ",;
iif(!Empty(texte),;
amil[1]+" ","zéro "+amil[1]+" "))
texte=texte+Iif(Val(Right(cChif,2))>0,Iif(Val(Right(cChif,2))>1,Right(cChif,2)+" centimes",Right(cChif,2)+" centime"),"")
Return texte
|
Bonjour Jean
Je ne sais pas si une classe dans le cas présent est rentable.
la fonction s'execute très vite, même dans un scan. Mais pour une vision scolaire des classes pourquoi pas !
Bonne journée