ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

calcul d'ancienneté en lettres   



L'auteur

eric leissler
France France
Membre Simple
# 0000002784
enregistré le 06/03/2010
http://www.aumeric.fr
67 ans
LEISSLER Eric
85290 MORTAGNE SUR SEVRE
de la société AUMERIC LOGICIELS
Fiche personnelle


Note des membres
pas de note

Contributions > 01 - PRG : Programmation > Calculs de clefs et Checksums (rib, iban, ...)

calcul d'ancienneté en lettres
# 0000000736
ajouté le 20/01/2010 12:32:50 et modifié le 20/01/2010
consulté 8883 fois
Niveau débutant


Le téléchargement des pièces jointes est limité aux membres
Veuillez vous identifier ou vous inscrire si vous n'avez pas encore de compte ...
Description

bonjour à toutes et à tous

voici une petite fonction permettant de retourner le nombre d'années de de mois entre deux dates, et le tout en lettres

Bonne programmation à tous

= anciennete(ctod("01/01/2000") , ctod(18/02/2010)) renverra 10 ans et un mois

= anciennete(date_debut,date()) vous renverra l'ancienneté depuis à la date de début à ce jour

Aumeric

Code source :
FUNCTION anciennete(datedeb,cejour)
* auteur : Aumeric logiciels  18/01/2010
*= anciennete(ctod("01/01/2000") , ctod(18/02/2010))   renverra 10 ans  et un mois
*
*= anciennete(date_debut,date())   vous renverra l'ancienneté depuis à la date de début à ce jour




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
*mi_add2(@aniveau,"",2)
  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
* traite les exceptions
For i=1 To 12
  texte=Strtran(texte,aexcep[i,1],aexcep[i,2])
Next i


*   aeval(aexcep,{|a|texte:=strtran(texte,a[1],a[2])})
*// enlŠve un mille
texte=Iif(Left(texte,8)="un mille",Right(texte,Len(texte)-3),texte)
*// vingt et cent
For i=1 To 2
  texte=Strtran(Left(texte,Len(texte)-4),avcex[i,1],avcex[i,2])+Right(texte,4)
Next

*   aeval(avcex,{|a|texte:=strtran(left(texte,len(texte)-4),a[1],a[2])+right(texte,4)})
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

Commentaires
le 21/01/2010, eric leissler a écrit :
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

le 21/01/2010, eric leissler a écrit :
Dans une fonction également. Mais je trouve que dans ce ca la, c'est plus compliqué, mais une vision scolaire pour une classe, c'est un cas d'école non ?
Bonne soirée


Publicité

Les pubs en cours :


www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2024.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3