
Code:
Code : Tout sélectionner
; *********************************************************************************************************
; PureBasic Visual Designer v3.95 build 1485 (PB4Code)
;
; et <<<< GeBonet >>>> présentent...
;
; Un code toujours utile :
;
; Une conversion de chiffre en lettre en respectant des règles de français !
;
; L'intérêt de ce "code", c'est qu'il est une intégration simplifié d'un "code récupéré" de QB...
;
; ----------< et ADAPTE avec un MINIMUM de changement par rapport à l'original... >-------------------------
;
; Il ne s'agit donc pas d'une optimisation PB, mais de vérifier la facilité d'utiliser
; de "l'ancien code" et aussi d'apprendre rapidement les différences essentielles
; pour être plus vite opérationnel en PB..
; 09-05-2008
; Conseil aux nouveaux en PB comme moi !!!
;
; C'est de bien respecter les définitions de variable et donc de passer par des déclaration
; pour que LES choses soient claires... PB aime le clair ! (stricte) et pas comme ici !
;
; Attention : Au moment de créer l'EXE... ou de tester avec des versions successives...
; ********** Il m'est alors arrivé de travailler sur une version et de compiller
; la précédente...
;
; Et je m'étonnais que ce que je changeais n'avais aucun effet !!! Vous imaginez, c'est bête, hein :)
;
; Donc bien verifier que dans "Option compilateur" vous ayez bien comme fichier principal
; la bonne Version.... :-) ------------------
;**************************************************************************************************************
;
IncludeFile "Common.pb" ; Ici fenêtre de base crée avec Visual Designer...
;
Dim U$(16)
Dim D$(9)
;
U$(1) = "un": U$(2) = "deux": U$(3) = "trois": U$(4) = "quatre"
U$(5) = "cinq": U$(6) = "six": U$(7) = "sept": U$(8) = "huit"
U$(9) = "neuf": U$(10) = "dix ": U$(11) = "onze ": U$(12) = "douze"
U$(13) = "treize": U$(14) = "quatorze": U$(15) = "quinze" : U$(16) = "seize"
D$(1) = "dix": D$(2) = "vingt": D$(3) = "trente": D$(4) = "quanrante" : D$(5) = "cinquante"
D$(6) = "soixante": D$(7) = "septante" : D$(8) = "quatre-vingt": D$(9) = "nonante"
MILLE$ = "mille":MILLION$ = "million":MILLIARD$ = "milliard": CENT$ = "cent"
;***********************************************************************************************************
Open_Window_0()
Sortie$="N"
Repeat
Event = WaitWindowEvent()
WindowID = EventWindow()
GadgetID = EventGadget()
EventType = EventType()
; *******************************************************************************************************************
If Event = #PB_Event_Gadget
If GadgetID = #Valeur ; Une Valeur à convertir est-elle là ?...
Valeur.d=ValD(GetGadgetText(#Valeur)); OUI alors c'est placé dans la Variale chaine Premier$
EndIf
;
If GadgetID = #Button_1 ; Demande t-on le calcul ???
If Valeur.d=0 ; OUI mais de valeur Nulle on efface
StringGadget(#Valeur, 155, 65, 300, 25, "", #PB_Sort_Double)
Else ; sinon on Continue, ça vaut p'être la peine !
NBR.d=Valeur.d ; C'est combien au fait ?
Comp.d=1000*1000*1000 ; Pour pas devoir compter les zéro :-)
If NBR.d < Comp.d ; Puis-je le converir ?
;==============================================================================
Gosub RoutineCodageChiffreLettre ; On traduit NBR.d en lettres et en français ?
;===============================;==============================================
Resultat$="= "+P1$ ; Affiche le résultat dans la zone
TextGadget(#Text_3, 80, 105, 400, 50, Resultat$) ; Ajoute une case pour montrer
SetGadgetFont(#Text_3, FontID6) ; Même police
SetGadgetColor(#Text_3, #PB_Gadget_FrontColor, $0000FA) ; Mais en rouge pour être certain d'être lu
Else ; NON ON PEUX PAS -------
Resultat$="Opps... Déjà que je fait une effort jusque :" ;
Resultat$=Resultat$+" Un Milliard moins 1"
TextGadget(#Text_3, 80, 105, 400, 50, Resultat$) ; Ajoute une case pour montrer
SetGadgetFont(#Text_3, FontID6) ; Même police
SetGadgetColor(#Text_3, #PB_Gadget_FrontColor, $0000FA) ; Mais en rouge pour être certain d'être lu
EndIf
EndIf
EtatBouton0=GetGadgetState(#Button_1) ; on le mémorise AU cas ou
Sortie$="N" ; Non j'veux pas sortir !!
ElseIf GadgetID = #Button_2 ; On recommence... Bon, on y va !
EtatBouton0=GetGadgetState(#Button_1) ; Oui on recommence....
Sortie$="N" : Deja=0
StringGadget(#Valeur, 155, 65, 300, 25, "", #PB_Sort_Double) ; Efface les zones Valeur et Résulat
TextGadget(#Text_3, 80, 105, 400, 50, Space(Len(Resultat$)))
SetGadgetFont(#Text_3, FontID6)
ElseIf GadgetID = #Button_3
Sortie$="O" ; On en à marre on sort, alors Sortie OK
EndIf
EndIf
Until Sortie$="O" ;Event = #PB_Event_CloseWindow ; Fin de la boucle d'attente
End
;*******************************************************************************************
; CONVERSION DE CHIFFRES EN LETTRES ANCIEN CODE ADAPTE !!!
;
; Corps du programme ===> Transformer "NBR.d" en sa forme exprimé en "lettres"
;********************************************************************************************
; Ancien nom... de la SUB
RoutineCodageChiffreLettre:
; (CHIF.LETR (NBR.d, ER.d, P1$, U$(), D$()) Static OU Ancienne forme d'appel de la SUB...
ET = 0: J.d = L.d: CAS = 1:P1$ = "0"
If NBR.d <>0
; Vrai début....
Decim = Val(Str((NBR.d-Int(NBR.d))*100))
If Decim>49
NBO$ = Str(NBR.d-1)
Else
NBO$ = Str(NBR.d)
EndIf
L.d = Len(NBO$): P1$ = ""
; Ici un Case serait bienvenus.... ET !
If L.d < 3
NBR$ = NBO$: Gosub Unit:: Goto Arret:: ; DIZAINES Goto à prohiber... Mais des fois ... :-)
EndIf
If L.d < 4
NBC$ = NBO$: Gosub Cent:: Goto Arret : ; CENTAINES
EndIf
If L.d < 7
NBM$ = NBO$: Gosub Millier:: Goto Arret ; MILLIERS
EndIf
If L.d < 13
NBT$ = NBO$: Gosub Million: Goto Arret ; c'est dans MILLIONS, Milliards puis termine
EndIf
EndIf
Return
; *******************************************************************************************
Arret: If Decim<>0
Gosub Decima:: P1$ = P1$ + " "
Else
Gosub CentS
EndIf
Return ; Sortie de retour
; ********************************************************************************************
;
Million: ;' -- MILLIONS -- ENTREE = NBM$ (0 -> 999999999)
;
NBM$ = Right(NBT$, 6): K.w = Len(NBT$): CAS=8
If Val(NBM$) <> 0
Gosub Millier
P3$ = P1$
EndIf
NBC$ = Left(NBT$, K.w - 6): P1$ = ""
If Val(NBC$) = 0
P1$ = P3$: Return
EndIf
L.d = Len(NBC$)
If Val(NBC$) = 1 :
P1$ = "Un " + MILLION$ + " " + P3$: Return
Else
MILLION$ = MILLION$ + "s"
EndIf
If L.d < 3
NBR$ = NBC$: Gosub Unit
Else
Gosub Cent
EndIf
If Right(P1$, 1) <> " " : P1$ = P1$ + " ":EndIf
P1$ = P1$ + MILLION$ + " " + P3$: P3$ = "": Return
;-------------------------------------------------------------------------
Millier: ; -- MILLIERS -- ENTREE = NBM$ (0 -> 999999)
;
NBC$ = Right(NBM$, 3): J.d = Len(NBM$)
If Val(NBC$) <> 0 : Gosub Cent:: P3$ = P1$ : EndIf
NBC$ = Left(NBM$, J.d - 3): P1$ = ""
If Val(NBC$) = 0 : P1$ = P3$: Return : Else : EndIf
L.d = Len(NBC$)
If Val(NBC$) = 1
P1$ = "" : Goto FMillier
EndIf
If L.d < 3
NBR$ = NBC$: Gosub Unit
Else
Gosub Cent
EndIf
If Right(P1$, 1) <> " " : P1$ = P1$ + " " :EndIf
FMillier: P1$ = P1$ + MILLE$ + " " + P3$: P3$ = "": Return
; ----------------------------------------------------------------------
Cent: ; -- CENTAINES -- ENTREE = NBC$ (0 -> 999)
;
UC$ = Left(NBC$, 1): NBR$ = Right(NBC$, 2): u = Val(UC$): P2$ = ""
If u = 1
P2$ = CENT$
ElseIf u <> 0
P2$ = U$(u) + " " + CENT$
EndIf
If Val(NBR$) <> 0
Gosub Unit
EndIf
P1$ = P2$ + " " + P1$
Return
; -------------------------------------------------------------------------
Unit: ; -- UNITES ET DIZAINES -- ENTREE = NBR$ (0 -> 99)
;
ET = 1: M.d = Len(NBR$): If M.d < 2 : P1$ = U$(Val(NBR$)): Return : Else : EndIf
DZ$ = Right(NBR$, 2): If Val(DZ$) < 17 : P1$ = U$(Val(DZ$)): Return : Else : EndIf
U$ = Right(NBR$, 1): D$ = Mid(NBR$, M.d - 1, 1)
If U$ = "1"
T$ = " et "
Else ; Les IF Else imbriqué : On peut les écrires comme ceci ou comme ci dessous...
T$ = "-"
EndIf
If D$ = "8" And U$ = "1" : P1$ = D$(8) + "-" + U$(Val(U$)): Return : Else : EndIf
If D$ = "8" And U$ = "0" : P1$ = D$(8) + "s": Return : Else : EndIf
If Val(U$) = 0 : P1$ = D$(Val(D$)): Return : Else : EndIf
P1$ = D$(Val(D$)) + T$ + U$(Val(U$)): Return
; ------------------------------------------------------------------------------
CentS: GL.w = Len(P1$)
If GL.w < 4
Return
EndIf
If Right(P1$, 1) = " " ; Les THEN disparaissent...
P1$ = Left(P1$, GL.w - 1): GL.w = GL.w - 1
EndIf
KL = FindString(P1$, "cent", GL.w - 5) ; Et oui "Instr" devient "FindString"
If KL <> 0
P1$ = P1$ + "s" ; et les "End If" ==> "EndIf"
EndIf
Return
; ---------------------------------------------------------------------------
Decima:
NBR$=Str(Decim):M.d = Len(NBR$):PN$=P1$
ET = 1: Gosub Unit
P1$=PN$+" et "+P1$+" cents"
Return
;******************************************************************************************
; IDE Options = PureBasic 4.20 (Windows - x86)
; CursorPosition = 109
; Folding = -
; EnableAsm
; EnableXP
; UseMainFile = ProgChifLetr5.pb
; Executable = ProgChiLetr5.exe
; CurrentDirectory = C:\0 01 Pure Basic\PureBasic\
; CompileSourceDirectory
; Debugger = IDE
; EnableCompileCount = 19
; EnableBuildCount = 0
; EnableExeConstant
Code : Tout sélectionner
;---------------------------------------------------------------------------
; PureBasic Visual Designer v3.95 build 1485 (PB4Code)
;-----------------------------------------------------------------------------
;- Window Constants
;
Enumeration
#Window_0
EndEnumeration
;- Gadget Constants
;
Enumeration
#Text_0
#Valeur
#Text_1
#Text_2
#Text_3
#Resultat
#Button_1
#Button_2
#Button_3
EndEnumeration
;- Fonts
Global FontID1
FontID1 = LoadFont(1, "@Arial Unicode MS", 12)
Global FontID2
FontID2 = LoadFont(2, "Times New Roman", 20, #PB_Font_Bold)
Global FontID3
FontID3 = LoadFont(3, "Arial", 12)
Global FontID4
FontID4 = LoadFont(4, "Times New Roman", 22)
Global FontID5
FontID5 = LoadFont(5, "Times New Roman", 20)
Global FontID6
FontID6 = LoadFont(6, "Times New Roman", 12)
Global FontID7
FontID7 = LoadFont(7, "Times New Roman", 12)
Global FontID8
FontID8 = LoadFont(8, "Arial", 11)
Procedure Open_Window_0()
If OpenWindow(#Window_0, 251, 165, 510, 236, "Convertion de chiffre en lettre ", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
If CreateGadgetList(WindowID(#Window_0))
TextGadget(#Text_0, 10, 65, 140, 30, "Valeur à convertir :")
SetGadgetFont(#Text_0, FontID6)
StringGadget(#Valeur, 155, 65, 300, 25, "", #PB_Sort_Double)
SetGadgetFont(#Valeur, FontID8)
TextGadget(#Text_1, 40, 15, 450, 25, "Transformation de chiffres en lettres", #PB_Text_Center)
SetGadgetFont(#Text_1, FontID2)
;
TextGadget(#Text_2, 15, 105, 85, 25, "Résultat : ")
SetGadgetFont(#Text_2, FontID6)
ButtonGadget(#Button_1, 230, 190, 80, 25, "Résultat")
ButtonGadget(#Button_2, 130, 190, 80, 25, "Autre Essai")
ButtonGadget(#Button_3, 330, 190, 80, 25, "Quitter")
EndIf
EndIf
EndProcedure
; IDE Options = PureBasic 4.20 (Windows - x86)
; CursorPosition = 1
; Folding = -
; EnableAsm
; EnableXP
; CurrentDirectory = C:\0 01 Pure Basic\PureBasic\
; CompileSourceDirectory
; EnableCompileCount = 2
; EnableBuildCount = 0
; EnableExeConstant


