You are on page 1of 95

TRAVAUX PRATIQUES Sommaire Algorithmique et Visual C ++ : Calculs Simples 2 Algorithmique et Visual C ++ : Structures Conditionnelles 4 Algorithmique et Visual C ++ : Structures rptitives

8 Algorithmique : Divers Exercices 10 Visual Basic : Utilisation de l interface GUI et des structures de base 12 Visual Basic : Fonctions prdfinies 21 Visual Basic : Fonctions Prdfinies et utilisation des autres Contrles 29 Visual Basic : Gestion des fichiers sur disques, Listes et Grilles 38 Projets Informatiques : Niveau II 48 PAGE N : 1 / 53

TRAVAUX PRATIQUES ALGORITHMIQUE ET VISUAL C++ CURSUS T-TS NIVEAU I U.F. 4 SQUENCES 1 ET 2 T.P. N 1 OBJECTIF SE FAMILIARISER AVEC LA CRATION DES ALGORITHMES ET TRADUCTION DES ALGORITHMES SOUS VISUAL C++ CONTENU CALCULS SIMPLES A -CALCULER LA SOMME DE DEUX NOMBRES. ALGORITHME TRADUCTION VISUAL C 1. Dbut 2. Lire N1 3. Lire N2 4. S = N1 + N2 (ou S . N1 + N2) 5. Ecrire S 6. Fin // Programme de la somme de deux Nombres // int n1, n2, s; #include "stdio.h" void main() { printf("Premier Nombre : ");scanf("%d",&n1); printf("Deuxieme Nombre : ");scanf("%d",&n2); s = n1 + n2; printf("Somme des deux Nombres : %d ",s); } B -LA MOYENNE DE TROIS NOTES. ALGORITHME TRADUCTION VISUAL C 1. Dbut 2. Lire N1 3. Lire N2 4. Lire N3 5. M = (N1 + N2 + N3) / 3 (ou M . (N1 + N2 + N3) / 3) 6. Ecrire M 7. Fin // Programme de la moyenne de trois notes // float n1, n2, n3, m; #include "stdio.h" void main() { printf("Premiere Note : ");scanf("%f",&n1); printf("Deuxieme Note : ");scanf("%f",&n2); printf("Troisieme Note : ");scanf("%f",&n3); m = (n1 + n2 + n3) /3; printf("Moyenne des trois Notes : %6.2 ",m); }

PAGE N : 2 / 53

TRAVAUX PRATIQUES C -LE NET PAYER POUR UNE FACTURE UN SEUL PRODUIT. ALGORITHME TRADUCTION VISUAL C 1. Dbut 2. Lire PU (Prix Unitaire) 3. Lire Q (Quantit) 4. THT = PU * Q 5. TVA = THT * 0.2 6. TTC = THT + TVA 7. Ecrire THT 8. Ecrire TVA 9. Ecrire TTC 10. Fin // Programme de la Facture // float PU,Q, THT,TVA,TTC; #include "stdio.h" void main() { printf("Quantit : ");scanf("%f",&Q); printf("Prix Unitaire : ");scanf("%f",&PU); THT = Q * PU; TVA = THT * 0.2 ; TTC = THT + TVA ; printf("THT : %6.2 ",THT); printf("TVA : %6.2 ",TVA); printf("TTC : %6.2 ",TTC); } D -SURFACE D'UN CERCLE. ALGORITHME TRADUCTION VISUAL C 1. Dbut 2. Lire R (Rayon) 3. S = 3.14 * R * R 4. Ecrire S 5. Fin // Programme de la surface d'un cercle // float R, S; #include "stdio.h" void main() { printf("Rayon : ");scanf("%f",&R); S = 3.14 * R * R ; printf("Surface : %6.2 ",S); } PAGE N : 3 / 53

TRAVAUX PRATIQUES ALGORITHMIQUE & VISUAL C++ CURSUS T-TS NIVEAU I U.F. 4 SQUENCES 1 ET 2 T.P. N 2 OBJECTIF UTILISER LES STRUCTURES DE PROGRAMMATION CONTENU STRUCTURES CONDITIONNELLES A -CALCULER LA DCISION DE RUSSITE D'UN TUDIANT PARTIR DE TROIS NOTES. ALGORITHME TRADUCTION VISUAL C 1. Dbut 2. Lire N1, N2, N3 3. M = (N1+ N2 + N3) / 3 4. Si M >= 10 Alors D = Russi Sinon D = chou 5. Ecrire M, D 6. Fin // Programme de la Dcision de russite d'un tudiant // float n1, n2, n3, m; char *d; #include "stdio.h" void main() { printf("Premiere Note : ");scanf("%f",&n1); printf("Deuxieme Note : ");scanf("%f",&n2); printf("Troisieme Note : ");scanf("%f",&n3); m = (n1 + n2 + n3) /3; if (m >= 10) d = "Admis"; else d = "Echou"; printf("Moyenne des trois Notes : %6.2 ",m); printf("Dcision : %s ",d); } B -CALCULER LE PLUS GRAND DE DEUX NOMBRES. ALGORITHME TRADUCTION VISUAL C 1. Dbut 2. Lire N1, N2 3. Si N1 > N2 Alors PG = N1 Sinon PG = N2 4. Ecrire PG 5. Fin // Programme Plus grand de deux Nombres // float n1, n2, pg; char *d; #include "stdio.h" void main() { printf("Premier Nombre : ");scanf("%f",&n1); printf("Deuxieme Nombre : ");scanf("%f",&n2); if (n1 > n2) pg = n1; else pg = n2; printf("Moyenne des trois Notes : %6.2 ",m); printf("Dcision : %s ",d); }

PAGE N : 4 / 53

TRAVAUX PRATIQUES C -CALCULER LE PLUS GRAND DE QUATRE NOMBRES. 1. Dbut 2. Lire N1, N2, N3, N4 3. Si N1 > N2 Alors PG1 = N1 Sinon PG1 = N2 4. Si N3 > N4 Alors PG2 = N3 Sinon PG2 = N4 5. Si PG1 > PG2 Alors PG = PG1 Sinon PG = PG2 6. Ecrire PG 7. Fin D -UNE ENTREPRISE ACCORDE UNE PRIME SELON LA SITUATION FAMILIALE DE L'EMPLOY : Si Si Si Si C D V M (Clibataire) . 100 DH (Divorc) . 120 DH (Veuf) . 135 DH (Mari) . 150 DH

ALGORITHME TRADUCTION VISUAL C 1. Dbut 2. Lire SF 3. Si SF = C Alors P = 100 4. Si SF = D Alors P = 120 5. Si SF = V Alors P = 135 6. Si SF = M Alors P = 150 7. Ecrire P 8. Fin // Programme Du Calcul de La prime selon la Situation F // int P; char SF; #include "stdio.h" void main() { printf("Situation Familiale : ");scanf("%c",&SF); switch(SF) { case 'C' : P = 100; case 'D' : P = 120; case 'V' : P = 135; case 'M' : P = 150; } printf("Prime : %d ",P); } E -DANS UNE ENTREPRISE, NOUS DISPOSONS DES SERVICES SUIVANTS : - Gestion des ressources humaines . C - Direction commerciale . C - Direction financire . B -Section productivit . A Les anciennets sont classes dans les tranches suivantes : -< 10 Ans . X -Entre 10 et 20 Ans . Y

-> 20 Ans La valeur X Y Z A 100 120 B 130 150 C 180 195

. Z de la prime est calcule en respectant le tableau suivant : 140 170 200

Travail faire : Calculer le montant de la prime accorder un employ de la socit. PAGE N : 5 / 53

TRAVAUX PRATIQUES 1. Dbut 2. Lire S, AN 3. Si S = A Alors 4. Si An < 10 Alors P = 100 5. Si An >= 10 et An <= 20 Alors P = 120 6. Si An > 20 Alors P = 140 7. Fin Si 8. Si S = B Alors 9. Si An < 10 Alors P = 130 10. Si An >= 10 et An <= 20 Alors P = 150 11. Si An > 20 Alors P = 170 12. Fin Si 13. Si S = C Alors 14. Si An < 10 Alors P = 180 15. Si An >= 10 et An <= 20 Alors P = 195 16. Si An > 20 Alors P = 200 17. Fin Si 18. Ecrire P 19. Fin F -BULLETIN DE PAIE : Calculer le net payer d'un employ sachant : Rgles de calcul : 1. Calculer le taux de la prime d'anciennet sachant que : Tranche Taux 0 2 ans 0 % 2 5 ans 5 % 5 12 ans 10 % 12 20 ans 15 % + 20 ans 20 % 2. Calculer la prime d anciennet : ANCIENNETE = SB (Salaire de base) * TX (Taux Prime Anciennet) 3. Calculer le Total Brut (TB) = (SB + Prime d anciennet) : 4. Calculer la CNSS sachant qu elle est plafonne 6.000 DH, c est--dire, si le total brut est suprieur au plafond, l employ ne paye que sur les 6.000 DH (Taux de la CNSS est 4.29 %) : 5. La retraite est calcule en fonction du taux donn sur la base du Total Brut (Taux R etraite 3.5 %) : 6. Les frais professionnels mensuels ne dpassent jamais 2.000 DH sur la base du Tota l Brut (Le taux des Frais Professionnels est 17 %) : 7. Le Net imposable = Total Brut (CNSS + Retraite + Frais Professionnels) :

8. Calculer le taux de L'I.G.R. selon le tableau suivant : Tranche du Net Imposable Taux Somme dduire 0 1666,67 Dh 0 % 0 1666,67 2000 Dh 13 % 216,67 DH 2000 3000 Dh 21 % 276,67 DH 3000 5000 Dh 35 % 796,67 DH + 5000 Dh 44 % 1 246,67 DH 9. IGR = (Net Imposable * Taux) Somme dduire : 10. Net payer = Total Brut (CNSS + Retraite + IGR) : PAGE N : 6 / 53

TRAVAUX PRATIQUES 1. Dbut 2. Lire NHT, TH, AN 3. SB = NHT * TH 4. Si AN < 2 Alors PAN = 0 5. Si AN >= 2 et AN < 5 Alors PAN = SB * 0.05 6. Si AN >= 5 et AN < 12 Alors PAN = SB * 0.1 7. Si AN >= 12 et AN < 20 Alors PAN = SB * 0.15 8. Si AN >= 20 Alors PAN = SB * 0.2 9. TB = SB + PAN 10. Si TB > 6000 Alors CNSS = 6000 * 0.0429 Sinon CNSS = TB * 0.0429 11. RET = TB * 0.035 12. FP = TB * 0.17 13. Si FP > 2000 Alors FP = 2000 14. NI = TB (CNSS + RET + FP) 15. Si NI < 1666.67 Alors IGR = 0 16. Si NI >= 1666.67 et NI < 2000 Alors IGR = (NI * 0.13) 216.67 17. Si NI >= 2000 et NI < 3000 Alors IGR = (NI * 0.21) 276.67 18. Si NI >= 3000 et NI < 5000 Alors IGR = (NI * 0.35) 796.67 19. Si NI >= 5000 Alors IGR = (NI * 0.44) 1246.67 20. NAP = TB (CNSS + RET + IGR) 21. Ecrire TB 22. Ecrire CNSS 23. Ecrire RET 24. Ecrire IGR 25. Ecrire NAP 26. Fin PAGE N : 7 / 53

TRAVAUX PRATIQUES ALGORITHMIQUE & VISUAL C++ CURSUS T-TS NIVEAU I U.F. 4 SQUENCES 1 ET 2 T.P. N 3 OBJECTIF UTILISER LES TRAVAUX RPTITIFS CONTENU STRUCTURES RPTITIVES A -CALCULER LA SOMME S=1+2+3+4+5+..+N. ALGORITHME TRADUCTION VISUAL C 1. Dbut 2. Lire N 3. S = 0 4. Pour I = 1 N Faire 5. S = S + I (S . S + I) 6. Suivant 7. Ecrire S 8. Fin // Programme de la Somme des N Premiers Termes // int N,S,I; #include "stdio.h" void main() { printf("Nombre : ");scanf("%d",&N); S = 0; for (I=1; I<=N;I++) { S = S + I; } printf("Somme des %d 1ers Nombres : %d ",I,S); } B-CALCULER LA FACTORIELLE :F=1*2*3*4 *N 1. Dbut 2. Lire N 3. F = 1 4. Pour I = 1 N Faire 5. F = F * I (F . F * I) 6. Suivant 7. Ecrire F 8. Fin C -CALCULER LE PLUS GRAND DE 10 NOMBRES. 1. Dbut 2. Pour I = 1 10 Faire 3. Lire N 4. Si I = 1 Alors PG = N 5. Si PG < N Alors PG = N 6. Suivant 7. Ecrire PG 8. Fin PAGE N : 8 / 53

TRAVAUX PRATIQUES D -CALCULER LE PLUS GRAND DE N NOMBRES. LA SAISIE EST ARRTE LORSQUE L'UTILISATEUR INTRODUIT UNE VALEUR NULLE. ALGORITHME TRADUCTION VISUAL C // Programme Utilisant la structure Tant Que // float N,PG; char SF; 1. Dbut #include "stdio.h" 2. Lire N void main() 3. PG = N { 4. Faire tant que N <> 0 printf("Valeur Du Nombre : ");scanf("%d",&N); 5. Si PG < N Alors PG = N while (n != 0) 6. Lire N { 7. Fin Tant Que if (N>PG) PG = N; 8. crire PG printf("Valeur Du Nombre : "); 9. Fin scanf("%d",&N); } printf("Plus grand des Nombres : %10.2f ",PG); } PAGE N : 9 / 53

TRAVAUX PRATIQUES ALGORITHMIQUE CURSUS T-TS NIVEAU I U.F. 4 SQUENCES 1 ET 2 T.P. N 4 OBJECTIF PERFECTIONNER L'ALGORITHMIQUE CONTENU DIVERS EXERCICES (SANS VENTUELLEMENT LES TRADUIRE SOUS VISUAL C++) : EXERCICE : RECHERCHER UN LMENT DANS UNE LISTE COMPOSE DE N LMENTS. 1. Dbut 2. Lire ER (Elment Recherch) 3. TR = 0 (Tmoin de Recherche) 4. Pour I = 1 N Faire 5. Si El(I) = ER Alors TR = 1 6. Suivant 7. Si TR = 0 Alors R = Non Trouv Sinon R = Trouv 8. Ecrire R 9. Fin EXERCICE : RECHERCHER UN LMENT DANS UNE LISTE DONT LE DERNIER LMENT EST NUL. 1. Dbut 2. Lire ER (Elment Recherch) 3. TR = 0 (Tmoin de Recherche) 4. I = 1 5. Tant que El(I) <> 0 6. Si El(I) = ER Alors TR = 1 7. I = I + 1 8. Suivant 9. Si TR = 0 Alors R = Non Trouv Sinon R = Trouv 10. Ecrire R 11. Fin EXERCICE : LIRE UNE SRIE DE NOMBRES ET ADDITIONNER LES NOMBRES POSITIFS ENTRE EUX. L'ARRT EST ENGENDR PAR UNE VALEUR NULLE. 1. Dbut 2. Lire N 3. S = 0 4. Faire tant que N <> 0 5. Si N > 0 Alors S = S + N 6. Suivant 7. Ecrire S 8. Fin PAGE N : 10 / 53

TRAVAUX PRATIQUES EXERCICE : INVERSER UNE SRIE DE N NOMBRES. 1. Dbut 2. Pour I = 1 N Faire 3. El2(I) = El(N+1-I) 4. crire El2(i) 5. Suivant 6. Fin EXERCICE : CLASSER UNE SRIE DE N NOMBRES. 1. Dbut 2. Pour I = 1 N - 1 Faire 3. Pour J = I + 1 N Faire 4. If El(I) > EL(j) Alors 5. ZI = El(I) 6. EL(I) = El(J) 7. EL(J) = ZI 8. Fin Si 9. Suivant J 10. Suivant I 11. Fin EXERCICE : CRIRE UN ALGORITHME QUI DTECTE SI UN NOMBRE EST PREMIER OU NON. 1. Dbut 2. Lire N 3. I = 2 4. T = 0 5. Tant Que I <= N et T = 0 Faire 6. Si N / I = Entire(N / I) Alors T = 1 7. I = I + 1 8. Fin Tant Que 9. Si T = 0 Alors D = "Nombre est Premier" Sinon D = "Nombre Non Premier" 10. Ecrire D 11. Fin EXERCICE : EN PATINAGE ARTISTIQUE, UN CONCURRENT OBTIENT 8 NOTES DE 8 JUGES. LA MOYENNE EST CALCULE EN LIMINANT LA MEILLEURE NOTE ET LA MAUVAISE NOTE. LES NOTES SONT COMPRISES ENTRE 0 ET 6. CALCULER LA MOYENNE D'UN CONCURRENT. 1. Dbut 2. S = 0:PG = 0: PP = 6 3. Pour I = 1 8 Faire 4. Lire N 5. Si N < PP alors PP = N 6. Si N > PG alors PG = N 7. S = S + N 8. Suivant 9. M = (S (PG + PP)) / 6 10. Fin PAGE N : 11 / 53

TRAVAUX PRATIQUES VISUAL BASIC CURSUS T-TS NIVEAU I U.F. 4 SQUENCES 3 T.P. N 5 OBJECTIF UTILISER L'INTERFACE GUI ET UTILISER LES STRUCTURES DE VISUAL BASIC EXERCICE : EN UTILISANT LA STRUCTURE FOR, CALCULER LA FACTORIELLE D'UN NOMBRE.FACTORIELLE DE N: N!=1 X 2 X 3 X 4 X X (N 1) X N. ' Programme permettant la Factorielle ' Procdure associe au bouton Calculer Private Sub Command1_Click() a = Val(Text1.Text) F = 1 For I = 1 To a F = F * I Next Label3.Caption = Format(F, "### ### ##0") End Sub ' Procdure associe au bouton Terminer Private Sub Command2_Click() End End Sub EXERCICE : EN UTILISANT LA STRUCTURE WHILE, AFFICHER SI UN NOMBRE N EST PREMIER OU NON. RAPPEL : UN NOMBRE PREMIER EST UN NOMBRE ENTIER QUI NE PEUT TRE DIVIS QUE PAR 1 ET LUI-MME. ' Programme permettant de vrifier si un nombre est premier ou Non ' Avec utilisation de la structure While ' Procdure associe au bouton Vrifier Private Sub Command1_Click() A = Val(Text1.Text) I = 2: T = 0 While (I < A And T = 0) If A / I = Int(A / I) Then T = 1 I = I + 1 Wend Label2.Caption = IIf(T = 1, "Ce nombre n'est pas premier", "Ce nombre est premie

r") End Sub PAGE N : 12 / 53

TRAVAUX PRATIQUES ' Procdure associe au bouton Terminer Private Sub Command2_Click() End End Sub EXERCICE : EN UTILISANT LA TECHNIQUE DE LA RCURSIVIT, CALCULER LA FACTORIELLE D'UN NOMBRE N (ENTIER) LU PARTIR DU CLAVIER. ' Calcul de la Factorielle avec la mthode Rcursive ' Fonction Permettant le calcul de la Factorielle Public Function Fact(N As Integer) As Long If N = 0 Then Fact = 1 Else Fact = Fact(N - 1) * N End Function ' Procdure associe au bouton Calculer Private Sub Command1_Click() Dim a As Integer a = Val(Text1.Text) Label3.Caption = Fact(a) End Sub EXERCICE : AFFICHER LES 3 PREMIERS NOMBRES PARFAITS. UN NOMBRE PARFAIT EST UN NOMBRE DONT LA SOMME DE SES DIVISEURS EXCEPT LUI-MME EST GALE AU NOMBRE LUI-MME. ' Programme permettant d'afficher les 3 premiers nombres parfaits ' Procdure associe au dmarrage de la feuille Private Sub Form_Load() i = 1 While i <= 3 For j = 1 To 1000 s = 0 For k = 1 To j - 1 If j / k = Int(j / k) Then s = s + k Next If s = j Then Label1(i).Caption = j i = i + 1 End If Next Wend End Sub EXERCICE : LIRE DANS UNE ZONE DE TEXTE UNE VALEUR. AFFICHER "BIEN" SI ELLE CONTIENT L'EXPRESSION "ER". "MAUVAIS" DANS LE CAS CONTRAIRE. ET CECI AU

MOMENT DE LA SAISIE. ' Programme permettant de tester si une chane de caractres Contient l'expression " ER" ' Procdure associe au changement du contenu du texte de la zone de texte Private Sub Text1_Change() t = Text1.Text Like "*ER*" Label2.Caption = IIf(t, "Bien", "Mauvais") End Sub PAGE N : 13 / 53

TRAVAUX PRATIQUES EXERCICE : LIRE UNE CHANE DE CARACTRES CH1 ET UNE SOUS-CHANE CH2 PUIS CALCULER LE NOMBRE DE RPTITIONS DE CH2 DANS CH1. ' Programme permettant de calculer le nombre de rptitions d'une sous chane dans une autre Private Sub Command1_Click() a = Text1.Text b = Text2.Text l = Len(a) nr = 0 For i = 1 To l mc = Mid(a, i, Len(b)) If mc = b Then nr = nr + 1 Next Label3.Caption = "La chane " & b & " se rpte " & nr & " fois" End Sub EXERCICE : EN UTILISANT LA STRUCTURE IF, CALCULER LE PLUS GRAND ET LE PLUS PETIT DE QUATRE NOMBRES LUS PARTIR DU CLAVIER. ' Programme permettant le calcul du plus grand et plus petit Avec utilisation de la commande IF ' Procdure associe au bouton Calculer Private Sub Command1_Click() N1 = Val(Text1.Text) N2 = Val(Text2.Text) If N1 > N2 Then PG = N1: PP = N2 Else PG = N2: PP = N1 End If Text3.Text = PG Text4.Text = PP End Sub EXERCICE : EN UTILISANT LA COMMANDE D'AIGUILLAGE SELECT CASE, AFFICHER SI LE NOMBRE LU PARTIR DU CLAVIER EST "UN", "DEUX", "TROIS", "QUATRE" OU "AUTRES". ' Programme permettant de traduire un chiffre En utilisant la commande Select Ca se ' Procdure associe au bouton Traduire Private Sub Command1_Click() A = Val(Text1.Text)

Select Case A Case Case Case Case Case 1: R = "Un" 2 R = "Deux" 3 R = "Trois" 4: R = "Quatre" Else R = "Autres"

End Select Label3.Caption = R End Sub EXERCICE : LIRE LE MOIS EN CHIFFRES PUIS L'AFFICHER EN LETTRES (UTILISER LA FONCTION CHOOSE). PAGE N : 14 / 53

TRAVAUX PRATIQUES ' Programme permettant d'afficher le mois en lettres ' Procdure associe au bouton Afficher Private Sub Command1_Click() A = Val(Text1.Text) If A > 12 Or A < 1 Or A <> Int(A) Then M = "Erreur de saisie" Else M = Choose(A, "Janvier", "Fvrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aot ", _ "Septembre", "Octobre", "Novembre", "Dcembre") End If Label3 = M End Sub EXERCICE : LIRE L'ANNE PUIS AFFICHER SI ELLE EST BISSEXTILE. ' Programme permettant de tester si une anne est bissextile ' Procdure associe au bouton Tester Private Sub Command1_Click() A = Val(Text1.Text) R = IIf(A / 4 = Int(A / 4), "Bissextile", "Non bissextile") Label2.Caption = R End Sub EXERCICE : LIRE LE MOIS ET LE JOUR DE NAISSANCE PUIS AFFICHER LE SIGNE ASTROLOGIQUE. ' Programme permettant de calculer l'horoscope ' Procdure associe au bouton Calculer Private Sub Command1_Click() DN = Text1.Text MN = Month(DN): ' Calcul du mois de naissance JN = Day(DN): ' Calcul du jour de naissance Select Case MN Case Case Case Case Case Case Case Case Case Case Case Case 1: HOR = IIf(JN < 21, "Capricorne", "Verseau") 2: HOR = IIf(JN < 21, "Verseau", "Poissons") 3: HOR = IIf(JN < 21, "Poissons", "Belier") 4: HOR = IIf(JN < 21, "Belier", "Taureau") 5: HOR = IIf(JN < 21, "Taureau", "Gemeaux") 6: HOR = IIf(JN < 21, "Gemeaux", "Cancer") 7: HOR = IIf(JN < 21, "Cancer", "Lion") 8: HOR = IIf(JN < 21, "Lion", "Vierge") 9: HOR = IIf(JN < 21, "Vierge", "Balance") 10 : HOR = IIf(JN < 21, "Balance", "Scorption") 11: HOR = IIf(JN < 21, "Scorption", "Sagittaire") 12: HOR = IIf(JN < 21, "Sagittaire", "Capricorne")

End Select Label2.Caption = "Votre Horoscope est " & HOR End Sub PAGE N : 15 / 53

TRAVAUX PRATIQUES Exercice : Le club d'aviation priv "Public Air" dsire automatiser la facture suivante : Public Air 113 Bd D'Anfa Casablanca Facture N : Nom du client Adresse du client Nombre d'heures de vol ralis Taux horaire 450 DH Total Hors Taxe Remise Net TVA Net payer Rgles de calcul : Total Hors Taxe : Nombre de vols raliss * Taux horaire Remise : Selon le THT : o Si le THT < 15000 DH . Pas de remise o Si le THT est compris entre 15000 et 30000 . 10 % du THT o Dans le cas inverse . 15 % du THT Net Commercial = THT - Remise TVA = Net commercial * 20% TTC = Net commercial + TVA ' Programme permettant de raliser une facture ' Procdure associe au bouton calculer Private Sub Command1_Click() NHVR = Val(ZNHV.Text) THT = NHVR * 450 ZTHT.Caption = Format(THT, "### ##0.00 DH") RE = IIf(THT < 15000, 0, IIf(THT < 30000, THT * 0.1, THT * 0.15)) ZREM.Caption = Format(RE, "### ##0.00 DH") NET = THT - RE ZNET.Caption = Format(NET, "### ##0.00 DH") TVA = NET * 0.2

ZTVA.Caption = Format(TVA, "### ##0.00 DH") NAP = NET + TVA ZNAP.Caption = Format(NAP, "### ##0.00 DH") End Sub PAGE N : 16 / 53

TRAVAUX PRATIQUES Exercice : Une cole dsire automatiser la gestion des bulletins de notes de ses lves. Le format du bulletin est donn ci dessous : ECOLE AL MARIF 125, Bd Mohamed VI CASABLANCA Trimestre : Nom : Section : Prnom : ..

Matires Moyenne Coefficient Total Observation Comptabilit Mathmatiques Droit Organisation d'entreprises Informatique Calculer le total pour chaque matire : Calculer l observation sachant que si : Moyenne > 18 Excellent 16 = Moyenne < 18 Trs Bien 14 = Moyenne < 16 Bien 12 = Moyenne < 14 Assez Bien 10 = Moyenne < 12 Passable Dans le cas contraire Non admis Calculer la moyenne gnrale de l tudiant. Calculer l observation pour la moyenne du trimestre en respectant les mmes rgles que pour l observation par matire. ' Procdure associe au bouton Calculer ' Utilisation des Index Private Sub Command1_Click() TOM = 0: TOC = 0 Dim MO(1 To 5), CTO(1 To 5) As Double Dim CO(1 To 5) As Integer Dim OB(1 To 5) As String For I = 1 To 5 MO(I) = Val(MOY(I).Text) : CO(I) = Val(COE(I).Text) CTO(I) = MO(I) * CO(I): TOT(I) = CTO(I) N1 = MO(I)

OB(I) = IIf(N1 >= 18, "Excellent", IIf(N1 >= 16, "T. Bien", IIf(N1 >= 14, _ "Bien", IIf(N1 >= 12, "A.Bien", IIf(N1 >= 10, "Passable", "Non Admis"))))) OBS(I) = OB(I) TOM = TOM + CTO(I): TOC = TOC + CO(I) Next MOG = TOM / TOC: MGE = Format(MOG, "00.00") N1 = MOG OBSG = IIf(N1 >= 18, "Excellent", IIf(N1 >= 16, "T. Bien", IIf(N1 >= 14, _ "Bien", IIf(N1 >= 12, "A.Bien", IIf(N1 >= 10, "Passable", "Non Admis"))))) OGE = OBSG End Sub PAGE N : 17 / 53

TRAVAUX PRATIQUES Exercice : Une entreprise dsire automatiser ses bulletins de paie. Le format du bulletin est donn aprs les rgles de calcul.

Calculer le taux de la prime d'anciennet sachant que : Tranche d'anciennet Taux 0 2 ans 0,00 % 2 5 ans 5,00 % 5 12 ans 10,00 % 12 20 ans 15,00 % + 20 ans 20,00 % Calculer le montant de la prime d anciennet : Salaire_base * Taux_prime Calculer le total Brut (Salaire de base + Prime d anciennet) : Calculer la CNSS sachant qu elle est plafonne 5.000 DH, c est--dire, si le total brut est suprieur au plafond, l employ ne paye que sur les 5.000 DH : La retraite est calcule en fonction du taux donn sur la base du Total Brut : Les frais professionnels mensuels ne dpassent jamais 2.000 DH sur la base du Tota l Brut. Le Net imposable = Total Brut (CNSS + Retraite + Frais Professionnels) :

Calculer le taux de L'I.G.R. selon le tableau suivant : Tranche du Net Imposable Taux Somme dduire 0 1666,67 Dh 0 % 0,00 DH 1666,67 2000 Dh 13 % 216,67 DH 2000 3000 Dh 21 % 376,67 DH 3000 5000 Dh 35 % 796,67 DH + 5000 Dh 44 % 1 246,67 DH Calculer le montant de L IGR sachant IGR = (Net Imposable * Taux) Calculer le Net payer = Total Brut (CNSS + Retraite + IGR). Format du bulletin Entte Bulletin de Paie Nom : Prnom : Anne d'embauche : . Anciennet : lment Nombre Taux Montant Salaire de base 26 J Prime d Anciennet Total Brut Retraite (C.I.M.R.) 4,50 % C.N.S.S. 3,26 % Frais professionnels 17,00 % Somme dduire :

Total imposable Impt I.G.R. Net payer PAGE N : 18 / 53

TRAVAUX PRATIQUES ' Procdure associe au bouton Calculer Private Sub Command1_Click() ' Traitement de l'anciennet DEM = ZDEM.Text ANC = DateDiff("yyyy", DEM, Date) ZANC.Caption = Format(ANC, "#0 Ans") TPA = IIf(ANC < 2, 0, IIf(ANC < 5, 0.05, IIf(ANC < 12, 0.1, IIf(ANC < 20, 0.15, 0.2)))) ZTPA.Caption = Format(TPA, "#0.00 %") SAB = ZSAB.Text MPA = TPA * SAB ZMPA.Caption = Format(MPA, "# ##0.00 DH") ' Calcul du Total Brut TOB = SAB + MPA ZTOB.Caption = Format(TOB, "# ##0.00 DH") ' Traitement de la CNSS CNS = IIf(TOB > 5000, 163, TOB * 0.0326) ZCNS.Caption = Format(CNS, "# ##0.00 DH") ' Traitement de la retraite RET = TOB * 0.045 ZRET.Caption = Format(RET, "# ##0.00 DH") ' Traitement des Frais Professionnels FPR = IIf(TOB * 0.17 > 2000, 2000, TOB * 0.17) ZFPR.Caption = Format(FPR, "# ##0.00 DH") ' Calcul du Net Imposable NIM = TOB - (CNS + RET + FPR) ZNIM.Caption = Format(NIM, "# ##0.00 DH") ' Calcul de l'IGR TIG = IIf(NIM < 1666.67, 0, IIf(NIM < 2000, 0.13, IIf(NIM < 3000, 0.21, IIf(NIM < 5000, 0.35, 0.44)))) ZTIG.Caption = Format(TIG, "#0.00 %") IGR = (NIM * TIG) - IIf(NIM < 1666.67, 0, IIf(NIM < 2000, 216.67, IIf(NIM < 3000 , _

367.67, IIf(NIM < 5000, 796.67, 1246.67)))) ZIGR.Caption = Format(IGR, "## ##0.00 DH") 'Calcul du Net payer NAP = TOB - (CNSS + RET + IGR) ZNAP.Caption = Format(NAP, "## ##0.00 DH") End Sub EXERCICE : LA RGIE AUTONOME DE DISTRIBUTION DE L'EAU ET DE L'LECTRICIT A RGLEMENT LE PAIEMENT DE LA CONSOMMATION DE L'EAU ET DE L'LECTRICIT EN TROIS TRANCHES. ON FIXERA LES TRANCHES DE CONSOMMATION COMME SUIT : Tranche consommation en Eau Prix m3 Tranche cons. en lectricit Prix KW/H 0 20 m3 2.70 DH 0 100 KW/H 6.50 21 40 m3 10.00 DH 101 300 KW/H 13.25 Plus de 40 m3 18.00 DH Plus de 300 KW/H 19.75 En saisissant le montant de la consommation en Eau et lectricit, Calculer le monta nt payer (TTC) pour l'eau et l'lectricit. PAGE N : 19 / 53

TRAVAUX PRATIQUES ' Procdure pour calculer le Net payer pour l'lectricit et l'eau Private Sub Command1_Click() Dim c, p, t As Single c1 = Val(zt1.Text) c2 = Val(zt2.Text) 'procdure de tranche de l'eau If c1 > 0 And c1 < 20 Then p = c1 * 2.7 If c1 > 20 And c1 < 40 Then p = (c1 - 20) * 10 +54 If c1 > 40 Then p = (c1 - 40) * 18 +254 zp1.Caption = p 'procdure de tranche d'lectricit If c2 = 0 Then p = 0 If c2 > 0 And c1 < 100 Then p = c2 * 6.5 If c2 > 100 And c1 < 300 Then p = (c2 - 100) * 13.25 + 650 If c2 > 300 Then p = (c2 - 300) * 19.75 + 3300 zp2.Caption = p End Sub PAGE N : 20 / 53

TRAVAUX PRATIQUES VISUAL BASIC CURSUS T-TS NIVEAU I U.F. 4 SQUENCES 3 T.P. N 6 OBJECTIF UTILISATION DES FONCTIONS PRDFINIES DU VISUAL BASIC Exercice : En utilisant un nombre lu partir du clavier dans une zone de texte, c alculer : Sa valeur absolue ; Son signe ; Sa partie entire ; Sa partie fixe ; Son exponentiel ; Son logarithme nprien. ' Programme permettant de raliser des Calculs Mathmatiques sur des donnes numriques ' Procdure relative au calcul de la valeur absolue Private Sub Command1_Click() a = Val(Text1.Text) b = Abs(a) Text2.Text = b Label2.Caption = "Valeur Absolue :" End Sub ' Procdure associe au bouton Signe Private Sub Command2_Click() a = Val(Text1.Text) b = Sgn(a) Text2.Text = b Label2.Caption = "Signe de l'expression :" End Sub ' Procdure associe au bouton Partie Entire Private Sub Command3_Click() a = Val(Text1.Text) b = Int(a) Text2.Text = b

Label2.Caption = "Partie Entire :" End Sub ' Procdure associe au bouton Partie Fixe Private Sub Command4_Click() a = Val(Text1.Text) b = Fix(a) Text2.Text = b Label2.Caption = "Partie Fixe :" End Sub ' Procdure associe au bouton Exponentielle PAGE N : 21 / 53

TRAVAUX PRATIQUES Private Sub Command5_Click() a = Val(Text1.Text) b = Exp(a) Text2.Text = b Label2.Caption = "Exponentielle :" End Sub ' Procdure associe au bouton Logarithme Private Sub Command6_Click() a = Val(Text1.Text) b = Log(a) Text2.Text = b Label2.Caption = "Logarithme :" End Sub Exercice : Saisir une expression quelconque, puis : Calculer sa longueur ; Afficher les trois premiers caractres ; Afficher les trois derniers caractres ; Afficher les deux caractres qui suivent le troisime ; Convertir en majuscules ; Convertir en minuscules ; Inverser la chane. ' Programme de Traitement de chanes de caractres ' Procdure associe au calcul de la longueur de la chane Private Sub Command1_Click() a = Text1.Text b = Len(a) Text2.Text = b Label2.Caption = "Longueur de la chane :" End Sub ' Transfomer la chane en majuscules Private Sub Command2_Click() a = Text1.Text

b = UCase$(a) Text2.Text = b Label2.Caption = "La chane en majuscules :" End Sub ' Transfomer la chane en minuscules Private Sub Command3_Click() a = Text1.Text b = LCase$(a) Text2.Text = b Label2.Caption = "La chane en minuscules :" End Sub ' Extraire partir du dbut de la chane Private Sub Command4_Click() a = Text1.Text b = Left(a, 3) Text2.Text = b Label2.Caption = "Dbut de la chane :" End Sub ' Extraire partir de la fin de la chane Private Sub Command5_Click() PAGE N : 22 / 53

TRAVAUX PRATIQUES a = Text1.Text b = Right(a, 3) Text2.Text = b Label2.Caption = "Dbut de la chane :" End Sub ' Extraire partir du milieu de la chane Private Sub Command6_Click() a = Text1.Text b = Mid(a, 3, 2) Text2.Text = b Label2.Caption = "Milieu de la chane :" End Sub ' Inverser une chane de caractres Private Sub Command7_Click() a = Text1.Text b = "" For i = Len(a) To 1 Step -1 b = b + Mid(a, i, 1) Next Text2.Text = b Label2.Caption = "Dbut de la chane :" End Sub Exercice : Oprations sur les dates : Afficher la date systme ; Calculer la diffrence en jours entre deux dates ; Calculer la diffrence en annes entre deux dates ; Afficher le jour de semaine d une date. Afficher le jour en lettres d'une date donne. ' Programme de Traitement de Dates ' Diffrence en jours Private Sub Command1_Click() a = DateDiff("d", Text1.Text, Text2.Text) Text3.Text = a End Sub ' Diffrence en annes

Private Sub Command2_Click() a = DateDiff("yyyy", Text1.Text, Text2.Text) Text3.Text = a End Sub ' Procdure associe au bouton Jour de la semaine Private Sub Command3_Click() a = Weekday(Text1.Text) Text3.Text = a End Sub ' Affichage de la date systme au moment de dmarrage du projet Private Sub Form_Load() Label1.Caption = Date$ End Sub Exercice : Saisir une information. a) S il s agit d une date, Calculer : Le nombre de jours qui sparent la date saisie de la fin d anne ; PAGE N : 23 / 53

TRAVAUX PRATIQUES

Le nombre de mois qui la sparent du dbut de l anne ; La date du lundi le plus proche du 15 du mois suivant la date saisie. b) Dans le cas contraire : Afficher une bote de message expliquant l erreur Activer la zone de saisie Private Sub Command1_Click() D = Text1.Text If IsDate(D) Then d2 = "31/12/" & Year(D) NJ = DateDiff("d", D, d2) Label6.Caption = NJ NM = Month(D) Label7.Caption = NM A = Year(D) If NM = 12 Then NM = 1: A = A + 1 Else NM = NM + 1 D3 = "15/" & Format(NM, "00") & "/" & A Js = Weekday(D3) NJA = IIf(Js = 2, 0, IIf(Js = 1, 1, 9 - Js)) D4 = DateAdd("d", NJA, D3) Label8.Caption = D4 End If End Sub Exercice : Saisir une chane de caractres puis : Afficher uniquement la chane sans consonnes ; Afficher uniquement la chane sans voyelles ; Afficher la chane avec les caractres dont la position est impaire. Chane sans voyelles Private Sub Command1_Click() t = Text1.Text L = Len(t) CH2 = "" For i = 1 To L If InStr("AEIOUY", Mid(t, i, 1)) <> 0 Then CH2 = CH2 + Mid(t, i, 1) Next Label3.Caption = CH2 End Sub Chane sans Consonnes Private Sub Command2_Click() t = Text1.Text Effacer la zone de saisie puis

L = Len(t) CH2 = "" For i = 1 To L If InStr("ZRTPQSDFGHJKLMWXCVBN", Mid(t, i, 1)) <> 0 Then CH2 = CH2 + Mid(t, i, 1) Next Label3.Caption = CH2 End Sub Chaine sans espaces Private Sub Command3_Click() t = Text1.Text L = Len(t) PAGE N : 24 / 53

TRAVAUX PRATIQUES CH2 = "" For i = 1 To L Step 2 CH2 = CH2 + Mid(t, i, 1) Next Label3.Caption = CH2 End Sub Private Sub Command4_Click() If Text2.Visible = False Then Text2.Visible = True: Label5.Visible = True Command4.Caption = "Masquer Partie B" Command5.Visible = True Else Text2.Visible = False: Label5.Visible = False Command4.Caption = "Partie B" Command5.Visible = False End If End Sub Exercice : On dsire laborer un calendrier en introduisant le mois et l'anne (sous f orme des zones de texte puis sous forme des zones de liste). Le programme doit afficher l e calendrier du mois prcis. Le programme doit tre capable de naviguer entre les mois et les annes. ' Programme permettant d'afficher un calendrier ' Utilisation des Etiquettes pour l'affichage Dim MM As Integer ' Procdure associe l'affichage des donnes Public Sub aff() da = "01/" + Text1.Text + "/" + Text2.Text r = Weekday(da) For i = 1 To 37 jjj(i).Caption = " " jjj(i).BorderStyle = 0 jjj(i).BackColor = &H8000000F Next NJM = Choose(Month(da), 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) If Year(da) / 4 = Int(Year(da) / 4) Then NJM = 29 For i = 1 To NJM

jjj(r).Caption = i jjj(r).BorderStyle = 1 jjj(r).BackColor = RGB(255, 0, 150) r = r + 1 Next End Sub ' Procdure associe au Bouton Afficher Private Sub Command1_Click() da = "01/" + Text1.Text + "/" + Text2.Text Call aff End Sub ' Procdure associe au bouton Mois Suivant PAGE N : 25 / 53

TRAVAUX PRATIQUES Private Sub Command2_Click() MM = Val(Text1.Text) + 1 aa = Val(Text2.Text) If MM > 12 Then MM = 1: aa = aa + 1 da = "01/" + LTrim(Str(MM)) + "/" + LTrim(Str(aa)) Text1.Text = MM Text2.Text = aa Call aff End Sub ' Procdure associe au bouton Mois Prcdent Private Sub Command3_Click() MM = Val(Text1.Text) - 1 aa = Val(Text2.Text) If MM < 1 Then MM = 12: aa = aa - 1 da = "01/" + LTrim(Str(MM)) + "/" + LTrim(Str(aa)) Text1.Text = MM Text2.Text = aa Call aff End Sub Exercice : laborer la feuille et le code ncessaires pour afficher l'heure systme et d'afficher une alarme. L heure de l alarme est introduite par l utilisateur en cliquant n importe o sur la feuille. ' Programme D'alarme ' Dclaration de variable globale Dim ti As String ' Procdure permettant de lire l'heure du Rendez-vous Private Sub Form_Click() ti = InputBox("Entrez l'heure de rveil : ", "Saadani Ikram") End Sub ' Procdure associe au Contrle Timer Private Sub Timer1_Timer() Label1.Caption = Time$ Label1.FontSize = 30 If Time = ti Then aa = MsgBox("Rendez-Vous...", vbOKOnly, "Saadani Ikram") End If End Sub Exercice : Traduire un mot anglais en franais et inversement. ' Programme Traduction Anglais - Franais ' Et Inversement ' Procdure associe au bouton Traduire

Private Sub Command1_Click() Ang = Array("Computer", "Mouse", "Printer", "Hard Disk", _ "Floppy Disk", "Byte", "Keyboard", "Language", "Software", "Hardware") Fra = Array("Ordinateur", "Souris", "Imprimante", "Disque dur", _ "Disquette", "Octet", "Clavier", "Langage", "Logiciel", "Machine") Mat = UCase(Text1.Text): TMo = "" PAGE N : 26 / 53

TRAVAUX PRATIQUES For i = 0 To 9 If Mat = UCase(Ang(i)) Then TMo = Fra(i) If Mat = UCase(Fra(i)) Then TMo = Ang(i) Next If TMo = "" Then MsgBox "Mot Introuvable", vbOKOnly, "Programme de Traduction Anglais-Franais" Else Label3.Caption = TMo End If End Sub Exercice : Faire le dcompte montaire d'une somme quelconque. Dcompte Montaire Private Sub Command1_Click() VDEC = Array(200, 100, 50, 20, 10, 5, 1, 50, 20, 10, 5) MON = Val(Text1.Text): MONI = MON MONI = CInt((MONI - Int(MONI)) * 100) For i = 0 To 6 ZVDEC(i + 1).Caption = VDEC(i) & " DH" NBP = Int(MON / VDEC(i)) ZNBP(i + 1).Text = NBP MON = MON - NBP * VDEC(i) Next For i = 7 To 10 ZVDEC(i + 1).Caption = VDEC(i) & " Cts" NBP = Int(MONI / VDEC(i)) ZNBP(i + 1).Text = NBP MONI = MONI - NBP * VDEC(i) Next End Sub Exercice : Traduire un chiffre en lettres. ' Programme permettant de traduire un Chiffre En Lettres ' Dclaration de variables globales Dim Gli As String Dim N As Long ' Fonction de traduction d'un nombre compris entre 1 et 999 Public Sub FCT() Lib = Array("Un", "Deux", "Trois", "Quatre", "Cinq", "Six", "Sept", "Huit", "Neu f", "Dix", "Onze",

"Douze", "Treize", "Quatorze", "Quinze", "Seize", "Dix-Sept", "Dix-Huit", "Dix-N euf", "Vingt", "Trente", "Quarante", "Cinquante", "Soixante", "Quatre-Vingt") Vch = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 40, 50, 60, 80) If N <= 20 Then Gli = Gli + Lib(N - 1): Exit Sub ' Traitement de centaines c = Int(N / 100) If c = 1 Then Gli = Gli + " Cent" If c > 1 Then Gli = Gli + Lib(c - 1) & " Cent" ' Traitement de Dixaines et Units PAGE N : 27 / 53

TRAVAUX PRATIQUES If N Mod 100 > 20 Then d = Int((N - (c * 100)) / 10) * 10 u = N Mod 10 Else u = N Mod 100 End If If d = 70 Or d = 90 Then d = d - 10: u = u + 10 End If ' Recherche des dixaines dans la liste If d > 0 Then For i = 0 To 25 If Vch(i) = d Then Gli = Gli & " " & Lib(i): Exit For Next End If If u > 0 Then Gli = Gli & " " & Lib(u - 1) End Sub ' Procdure associe au bouton Traduire Private Sub Command1_Click() Dim Nat As Long Nat = Val(Text1.Text) Gli = "" ' Traitement de Millions N = Int(Nat / 1000000) If N > 1 Then Call FCT: Gli = Gli & " Million" If N > 1 Then Gli = Gli & "s " Else Gli = Gli & " " ' Traitement de Milliers N = Int((Nat - N * 1000000) / 1000) If N = 1 Then Gli = Gli + " Mille " If N > 1 Then Call FCT: Gli = Gli & " Milles " ' Traitement de Centaines N = Nat Mod 1000 Call FCT Label2.Caption = Gli

End Sub PAGE N : 28 / 53

TRAVAUX PRATIQUES VISUAL BASIC CURSUS T-TS NIVEAU I U.F. 4 SQUENCES 3 T.P. N 7 OBJECTIF PERFECTIONNER LA PROGRAMMATION DE PROBLMES SIMPLES CONTENU FONCTIONS PRDFINIES ET UTILISATION DES AUTRES CONTRLES Exercice : En utilisant la technique des menus droulants, laborer la feuille et le code qui permettent de : 1. Lire une date. 2. Si la chane lue n'est pas une date, afficher une bote message d'erreur. 3. Dans le cas contraire, afficher : Le jour en lettres ; Le jour en chiffres ; Le mois en lettres ; Le mois en chiffres. Selon le choix de l'utilisateur. ' Procdure associe au Chargement de la Feuille Private Sub Form_Load() Text2.Visible = False Label2.Visible = False End Sub ' Procdure associe l'option "Jour en Chiffres" Private Sub jch_Click() d = Text1.Text If Not IsDate(d) Then MsgBox "Date not valide", vbOKOnly, "Gestion des Dates" Else r = Weekday(d) Text2.Visible = True Label2.Visible = True Text2.Text = r Label2.Caption = "Jour en chiffre" End If End Sub Jour en lettres

Private Sub JL_Click() d = Text1.Text If Not IsDate(d) Then MsgBox "date not valide", vbOKOnly, "Gestion Des Dates" Else PAGE N : 29 / 53

TRAVAUX PRATIQUES r = Choose(Weekday(d), "Dimanche", "Lundi", "Mardi", _ "mercredi", "Jeudi", "Vendredi", "Samedi") Text2.Visible = True Text2.Text = r Label2.Visible = True Label2.Caption = "Jours en lettres" End If End Sub ' Procdure associe l'option "Mois en Lettres" Private Sub mch_Click() mo = Array("Janvier", "Fvrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aot", _ "Septembre", "Octobre", "Novembre", "Dcembre") d = Text1.Text If Not IsDate(d) Then MsgBox "date not valide", vbOKOnly, "Gestion des Dates" Else r = Month(d) Text2.Visible = True Label2.Visible = True Text2.Text = mo(r - 1) Label2.Caption = "Mois en lettres" End If End Sub ' Procdure associe l'option "Mois en Chiffres" Private Sub mchiffre_Click() d = Text1.Text If Not IsDate(d) Then MsgBox "date not valide", vbOKOnly, "Gestion des Dates" Else r = Month(d) Text2.Visible = True Label2.Visible = True Text2.Text = r Label2.Caption = "Mois en chiffres" End If End Sub Exercice : En utilisant la technique des menus, afficher :

1. Le nombre de Voyelles ; 2. Le nombre de Consonnes ; 3. Le nombre d'espaces ; 4. Le pourcentage des Voyelles ; 5. Le pourcentage des Consonnes ; 6. Le pourcentage des Espaces D'une chane de caractres saisie partir du clavier. ' Fonction permettant de calculer le nombre de voyelles dans une chane de caractre s Public Function NVOY(T As String) As Integer VOYE = "AEIUOY" For I = 1 To Len(T) If InStr(VOYE, Mid(T, I, 1)) <> 0 Then NVOY = NVOY + 1 PAGE N : 30 / 53

TRAVAUX PRATIQUES Next End Function ' Fonction permettant le calcul du nombre de consonnes Public Function NCONS(T As String) As Integer Cons = "ZRTPQSDFGHJKLMWXCVBN" For I = 1 To Len(T) If InStr(Cons, Mid(T, I, 1)) <> 0 Then NCONS = NCONS + 1 Next End Function ' Fonction permettant le calcul du nombre d'espaces Public Function NESP(T As String) As Integer For I = 1 To Len(T) If Mid(T, I, 1) = " " Then NESP = NESP + 1 Next End Function ' Procdure associe l'option "Nombre de Consonnes" Private Sub Con_Click() CH = Text1.Text Label3.Caption = "Nombre de Consonnes " Label2.Caption = NCONS(UCase(CH)) End Sub ' Procdure associe l'option "Nombre d'espaces" Private Sub esp_Click() CH = Text1.Text Label3.Caption = "Nombre d'espaces" Label2.Caption = NESP(UCase(CH)) End Sub ' Procdure associe l'option "Pourcentage des Consonnes" Private Sub Pcon_Click() CH = Text1.Text Label3.Caption = "Pourcentage de Consonnes" PCONS = NCONS(UCase(CH)) / Len(CH) Label2.Caption = Format(PCONS, "##0.00%") End Sub ' Procdure associe l'option "Pourcentage d'espaces" Private Sub Pesp_Click() CH = Text1.Text Label3.Caption = "Pourcentage d'espaces" PESPA = NESP(UCase(CH)) / Len(CH) Label2.Caption = Format(PESPA, "##0.00%")

End Sub ' Procdure associe l'option "Pourcentage de Voyelles" Private Sub PVoyl_Click() CH = Text1.Text Label3.Caption = "Pourcentage de Voyelles " PVOY = NVOY(UCase(CH)) / Len(CH) Label2.Caption = Format(PVOY, "##0.00%") End Sub ' Procdure associe l'option "Nombre de Voyelles" Private Sub voyl_Click() CH = Text1.Text Label3.Caption = "Nombre de Voyelles " Label2.Caption = NVOY(UCase(CH)) PAGE N : 31 / 53

TRAVAUX PRATIQUES End Sub Exercice : Programme Tlphone. Nous dsirons calculer le cot d'une communication tlphonique. Pour cela, nous introdu isons la dure de la communication (avec une zone de texte ou une barre de dfilement). En suite, il faut choisir une tarification de la communication. Les tarifs sont paramtrs d'avan ce (Intitul et prix). Des boutons de commandes sont proposs pour Ajouter, Supprimer, Effacer toutes les tarifications. Lorsque l'utilisateur choisisse une tarification, le cot de la communication est calcul automatiquement. Les jours fris sont comptabiliss 50 %. ' Procdure associe au bouton Calculer Public Sub Calcul() NM = Val(Text1.Text) PC = NM * Val(List2.Text) Label5.Caption = PC Timer1.Enabled = True End Sub ' Procdure associe au bouton Suppression d'une Tarification Private Sub Command1_Click() R = MsgBox("Etes-vous sr de vouloir supprimer la tarification", vbOKCancel, "Gest ion des Tarifications") If R = vbOK Then NL = List1.ListIndex List1.RemoveItem (NL) List2.RemoveItem (NL) End If End Sub ' Procdure Associe la suppression de toute la liste de Tarification Private Sub Command2_Click() R = MsgBox("Etes-vous sr de vouloir supprimer la liste entire", vbOKCancel, "Gesti on des Tarifications") If R = vbOK Then List1.Clear List2.Clear End If

End Sub ' Procdure Ajouter une Tarification Private Sub Command3_Click() If Text2.Text <> "" And Val(Text3.Text) <> 0 Then List1.AddItem Text2.Text List2.AddItem Text3.Text Text2.Text = "" Text3.Text = "" End If End Sub ' Procdure associe au changement de la valeur l'aide de la barre de dfilement Private Sub HScroll1_Change() Text1.Text = HScroll1.Value Call Calcul End Sub ' Procdure associe au Choix d'une Valeur dans la liste Tarification Private Sub List1_Click() PAGE N : 32 / 53

TRAVAUX PRATIQUES List2.ListIndex = List1.ListIndex Call Calcul End Sub ' Procdure Associe au Choix dans la deuxime Liste Private Sub List2_Click() List1.ListIndex = List2.ListIndex Call Calcul End Sub ' Modification Du Type Jour Ouvrable Private Sub Option1_Click() Label5.Caption = Val(Text1.Text) * Val(List2.Text) End Sub ' Modification Du Type Jour Fri Private Sub Option2_Click() Label5.Caption = Val(Label5) / 2 End Sub ' Choix l'aide des Images Private Sub Picture1_Click() Option1.Value = True Option2.Value = False End Sub ' Choix l'aide des Images Private Sub Picture2_Click() Option2.Value = True Option1.Value = False End Sub ' Lors de la saisie Private Sub Text1_Change() Call Calcul End Sub ' Contrle de la saisie Private Sub Text1_KeyPress(KA As Integer) If InStr("0123456789", KA) <> 0 And KA <> vbKeyBack Then KA = 0 End Sub Exercice : Jeu Pendu Nous dsirons laborer un jeu ducatif permettant de choisir un mot au hasard d'une li ste. L'utilisateur peut commettre jusqu' 5 erreurs. la sixime, notre ami est pendu.

La saisie va s'effectuer l'aide de boutons de commande contenant la liste de l'a lphabet. Si l'utilisateur trouve le mot complet, afficher un message de flicitations. Si l'utilisateur ne trouve pas le mot, afficher comme quoi il est pendu. Dim mot, motr, mp, motr2 As String Dim NE As Integer ' Procdure Affichage Public Sub aff1() For i = 0 To 20 Lin(i).Visible = True Next End Sub ' Procdure Initialisation Public Sub initialise() limot = Array("INFORMATIQUE", "HARDWARE", "STI", "TRAITEMENT", "VISUAL", "BASIC" , "TABLEUR", "SGBD", _ PAGE N : 33 / 53

TRAVAUX PRATIQUES "MICROSOFT", "PENTIUM") vh = Int(Rnd * 10) + 1: motr = limot(vh): a = Len(motr) For i = 1 + a To 13 mc(i).Visible = False Next motr2 = Space(a) End Sub ' Procdure associe au Dmarrage Private Sub Form_Load() a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ": Randomize Timer For i = 1 To 26 letr(i).Caption = Mid(a, i, 1) Next mot = "": Call initialise For i = 0 To 20 Lin(i).Visible = False Next Lin2.Visible = False: Lin3.Visible = False lin4(1).Visible = False: Shape1.Visible = False Line1.Visible = False: Line2.Visible = False: Line3.Visible = False: Line4.Visible = False: Line5.Visible = False: Line6.Visible = False: End Sub ' Procdure Choix d'une Lettre Private Sub letr_Click(Index As Integer) letr(Index).Enabled = False: trouve = False For i = 1 To Len(motr) If letr(Index).Caption = Mid$(motr, i, 1) Then mc(i).FontSize = 16 mc(i).Caption = letr(Index).Caption: trouve = True Mid(motr2, i, 1) = letr(Index).Caption If motr = motr2 Then Form2.Show End If End If Next If Not trouve Then NE = NE + 1 Select Case NE

Case 1: Call aff1 Case 2: Lin2.Visible = True Case 3: Lin3.Visible = True Case 4: lin4(1).Visible = True: Shape1.Visible = True Case 5: Line1.Visible = True: Line2.Visible = True: Line3.Visible = True Case 6: Line4.Visible = True: Line5.Visible = True: Line6.Visible = True: mp = " VOUS ETES PENDU" End Select End Sub PAGE N : 34 / 53

TRAVAUX PRATIQUES Exercice : Calculer la commission mensuelle d'un reprsentant sachant qu'elle dpend du Chiffre d'affaires : Tranche C.A. % commission 10000 -1,00 % 10000 -20000 2,00 % 20000 -30000 3,00 % 30000 -40000 4,00 % 40000 -50000 5,00 % + 50000 7,50 % N.B. : Dans tous les cas, la valeur de la commission ne doit dpasser le montant p lafond fix 10.000,00 DH. Remarques : Le programme est accessible l aide d un mot de passe. Sur la deuxime Feuille, Le titre Calcul des commissions doit s afficher caractre par caractre puis s effacer de la mme manire. Chaque caractre affich (ou effac) doit se dplacer partir de (ou vers) la bordure de la feuille. ' Module Associ La feuille 1 Dim NR As Integer Private Sub Command1_Click() If Text1.Text = "SaadIkr" Then Form2.Show Else MsgBox "Mot de passe erronn", vbOKOnly, "Gestion de Commissions" Text1.Text = "": Text1.SetFocus NR = NR + 1: If NR > 3 Then End End If End Sub Private Sub Form_Load() NR = 1 End Sub ' Module associ la Feuille 2 Dim CC As String Dim NC, PZ, PL, t, NCR As Integer ' Procdure associe au bouton Calculer Private Sub Command1_Click() CA = Val(Text1.Text) PC = IIf(CA < 10000, 0.01, IIf(CA < 20000, 0.02, IIf(CA < 30000, 0.03, IIf(CA < 40000, 0.04, IIf(CA < 50000, 0.05, 0.075))))) MC = CA * PC If MC > 10000 Then MC = 10000

Label3.Caption = Format(MC, "## ##0.00 DH") End Sub ' Procdure associe au Bouton Quitter Private Sub Command2_Click() End End Sub PAGE N : 35 / 53

TRAVAUX PRATIQUES ' Procdure Associe au Dmarrage Private Sub Form_Load() Form1.Hide NC = 1: PZ = 1: t = 0 PL = Form2.Width End Sub ' Procdure Validation de la saisie Private Sub Text1_KeyPress(KA As Integer) If InStr("0123456789.", Chr(KA)) = 0 And KA <> vbKeyBack And KA <> 25 Then KA = 0 PVD = InStr(Text1.Text, ".") If PVD <> 0 And Chr(KA) = "." Then KA = 0 If PVD <> 0 And Len(Text1) > PVD + 1 And KA <> 25 And KA <> vbKeyBack Then KA = 0 If KA = 25 Then Text1 = "" End Sub ' Procdure associe la Minuterie Private Sub Timer1_Timer() CH = "Calcul des commissions" ZTD = Mid(CH, PZ, 1) ZTD.Left = PL Randomize ZTD.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) ZT.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) If t = 0 Then PL = PL - 300 If PL < ZT.Left + ZT.Width Then ZT = ZT + ZTD: PL = Form2.Width: PZ = PZ + 1 If PZ > Len(CH) Then t = 1: NCR = 0 End If Else PL = PL + 300 If PL > Form2.Width Then ZT = Left(CH, Len(CH) - NCR): PL = Form2.Width - ZT.Width: PZ = PZ - 1 NCR = NCR + 1 If PZ < 1 Then t = 0: PZ = 1 End If End If End Sub

' Module associ la Feuille 2 Dim CC As String Dim NC, PZ, PL, t, NCR As Integer ' Procdure associe au bouton Calculer Private Sub Command1_Click() CA = Val(Text1.Text) PC = IIf(CA < 10000, 0.01, IIf(CA < 20000, 0.02, IIf(CA < 30000, 0.03, IIf(CA < 40000, 0.04, IIf(CA < 50000, 0.05, 0.075))))) MC = CA * PC If MC > 10000 Then MC = 10000 Label3.Caption = Format(MC, "## ##0.00 DH") End Sub ' Procdure Associe au Dmarrage Private Sub Form_Load() Form1.Hide PAGE N : 36 / 53

TRAVAUX PRATIQUES NC = 1: PZ = 1: t = 0 PL = Form2.Width End Sub ' Procdure Validation de la saisie Private Sub Text1_KeyPress(KA As Integer) If InStr("0123456789.", Chr(KA)) = 0 And KA <> vbKeyBack And KA <> 25 Then KA = 0 PVD = InStr(Text1.Text, ".") If PVD <> 0 And Chr(KA) = "." Then KA = 0 If PVD <> 0 And Len(Text1) > PVD + 1 And KA <> 25 And KA <> vbKeyBack Then KA = 0 If KA = 25 Then Text1 = "" End Sub ' Procdure associe la Minuterie Private Sub Timer1_Timer() CH = "Calcul des commissions" ZTD = Mid(CH, PZ, 1) ZTD.Left = PL Randomize ZTD.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) ZT.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) If t = 0 Then PL = PL - 300 If PL < ZT.Left + ZT.Width Then ZT = ZT + ZTD: PL = Form2.Width: PZ = PZ + 1 If PZ > Len(CH) Then t = 1: NCR = 0 End If Else PL = PL + 300 If PL > Form2.Width Then ZT = Left(CH, Len(CH) - NCR): PL = Form2.Width - ZT.Width: PZ = PZ - 1 NCR = NCR + 1 If PZ < 1 Then t = 0: PZ = 1 End If End If End Sub PAGE N : 37 / 53

TRAVAUX PRATIQUES VISUAL BASIC CURSUS T-TS NIVEAU I U.F. 4 SQUENCES 3 T.P. N 7 OBJECTIF UTILISATION DES LISTES ET GRILLES & INTRODUCTION L'UTILISATION DES FICHIERS ET BASES DE DONNES CONTENU GESTION DES FICHIERS SUR DISQUE PARTIR DU VB & LES LISTES ET GRILLES Exercice : Crer un gestionnaire de fichiers permettant de : Changer le lecteur actif Afficher l arborescence du disque tout en permettant la navigation entre les sousrpertoires. Afficher le contenu du rpertoire actif. Slectionner un fichier, puis soit de le : Copier Effacer Dplacer Renommer Crer un sous-rpertoire Effacer un sous-rpertoire ' Procdure associe au changement de Dossier Private Sub Dir1_Change() File1.Path = Dir1.Path End Sub ' Procdure Associe au changement de Lecteur Private Sub Drive1_Change() Dir1.Path = Drive1.Drive File1.Path = Dir1.Path End Sub ' Procdure Copie D'un Fichier Private Sub FC_Click() CHSOU = Dir1.Path + IIf(Right(Dir1.Path, 1) = "\", "", "\"): SOU = CHSOU + File1.FileName: On Error GoTo TErreur DE = InputBox("Unit Destination : ", "Gestion des Fichiers")

If DE Like "?:\" Then DE = DE + File1.FileName Label1.Caption = SOU FileCopy SOU, DE Exit Sub TErreur: If Err.Number = 32755 Then Exit Sub PAGE N : 38 / 53

TRAVAUX PRATIQUES MsgBox Err.Description, 16, "Erreur !" End Sub ' Procdure associe l'effacement d'un fichier Private Sub FE_Click() CHSOU = Dir1.Path + IIf(Right(Dir1.Path, 1) = "\", "", "\"): SOU = CHSOU + File1.FileName: On Error GoTo TErreur Kill (SOU): File1.Refresh: Exit Sub TErreur: If Err.Number = 32755 Then Exit Sub MsgBox Err.Description, 16, "Erreur !" End Sub ' Procdure associe au Changement du Nom d'un fichier Private Sub FR_Click() CHSOU = Dir1.Path + IIf(Right(Dir1.Path, 1) = "\", "", "\"): SOU = CHSOU + File1.FileName: On Error GoTo TErreur DE = InputBox("Nouveau Nom : ", "Gestion des Fichiers") DE = CHSOU + DE Name SOU As DE: File1.Refresh Exit Sub TErreur: If Err.Number = 32755 Then Exit Sub MsgBox Err.Description, 16, "Erreur !" End Sub ' Procdure Dplacement d'un Fichier Private Sub ss_Click() CHSOU = Dir1.Path + IIf(Right(Dir1.Path, 1) = "\", "", "\"): SOU = CHSOU + File1 .FileName: On Error GoTo TErreur DE = InputBox("Unit Destination : ", "Gestion des Fichiers") If DE Like "?:\" Then DE = DE + File1.FileName FileCopy SOU, DE: Kill (SOU) File1.Refresh: Exit Sub TErreur: If Err.Number = 32755 Then Exit Sub MsgBox Err.Description, 16, "Erreur !" End Sub ' Procdure associe au changement du Masque D'affichage des Fichiers Private Sub Text1_Change() File1.Pattern = Text1.Text End Sub

Exercice : Raliser un QCM (Contrle de connaissance la mthode canadienne). Pour chaq ue question pose, on offre trois rponses dont l une est correcte. Si l utilisateur clique sur une rponse dans les dlais (25 secondes), on affiche : Bravo, si la rponse est correcte. Dsol, dans le cas contraire. Si l utilisateur ne rpond pas dans les dlais, la rponse est compte fausse, puis on pas se la question suivante. Le programme doit poser 10 questions tires au hasard d une liste compose de 60 quest ions. PAGE N : 39 / 53

TRAVAUX PRATIQUES Dim NPO, NQP, TR, PQ As Integer ' Procdure associe aux Boutons de Rponses Private Sub BRT_Click(Index As Integer) For I = 1 To 3 BRT(I).Enabled = False Next Br = Array(2, 3, 2, 1, 1, 2, 1, 2, 3, 3, 3, 1, 2, 1, 3, 1, 3, 3, 3, 1) I = BRT(Index).Index If Br(PQ) = I Then MES = "Bravo": NPO = NPO + 4 Else MES = "Dsol !!!!!": NPO = NPO - 4 End If MsgBox MES, vbOKOnly, "Contrle QCM" TR = 0 End Sub ' Procdure Associe au Bouton Commencer Private Sub Command1_Click() Timer1.Enabled = True: Command1.Visible = False End Sub ' Procdure associe La Minuterie Private Sub Form_Load() NQP = 0: TR = 10: NPO = 0 End Sub ' Procdure associe Timer Private Sub Timer1_Timer() For I = 1 To 3 BRT(I).Enabled = True Next Label5.Caption = TR Label5.AutoSize = True: Label5.FontSize = 38 - (TR * 2) LQ = Array("Maroc", "Algrie", "Tunisie", "Libye", "Egypte", "Arabie Saoudite", "U .S.A", "Angleterre", "Mauritanie", "Inde", _

"Chine", "Russie", "France", "Espagne", "Portugal", "Canada", "Brsil", "Argentine ", "Prou", "Panama") R1 = Array("Tanger", "Oran", "Sfakse", "Tripoli", "Caire", "Jeddah", "Washington ", "Manchester", "Saoukene", "Indiana", _ "Hong Kong", "Moscow", "Lyon", "Madrid", "Farense", "Ottawa", "Sao Paolo", "Arge ntinos", "San Martin", "Panama City") R2 = Array("Rabat", "Costantines", "Tunis", "Anaba", "Alexandrie", "Riad", "Los Angeles", "Londres", "Nouakchout", "Tombouktou", _ "Shangai", "Kiev", "Paris", "Barcelone", "Porto", "Quebec", "Porto Alegre", "Lam i Mami ", "San Pettersburg", "San Morina") R3 = Array("Marrakech", "Alger", "Hamamate", "Skhounate", "Charam Cheick", "Mequ e", "San Fransisco", "Berlin", "Laguira", "New Delhi", _ "Pkin", "Varsovie", "Lens", "Lacorogne", "Lisbone", "Les 5 Lacs", "Brsilia", "Buen os Aires", "Lima", "Klimanjarou") If TR <= 0 Then NQP = NQP + 1: TR = 10: PQ = Int(Rnd * 19) + 1 Label1.Caption = LQ(PQ) ZR(1).Caption = R1(PQ) ZR(2).Caption = R2(PQ) ZR(3).Caption = R3(PQ) TR = TR - 1 If NQP >= 5 Then PAGE N : 40 / 53

TRAVAUX PRATIQUES MsgBox "Vous avez obtenu " & NPO, vbOKOnly End End If End Sub Exercice : laborer La feuille et le code qui permettent de : - Afficher une liste en Vrac d'lments gauche et une liste vide droite. -En utilisant des boutons de Commande : Effacer tout le contenu de liste gauche. Remplir la liste gauche. Effacer les lments slectionns dans la liste gauche. Ajouter les lments slectionns dans la liste gauche la liste droite. Enlever l'lment slectionn de la liste droite. ' Procdure associe au bouton Remplir la liste alatoirement Private Sub Command1_Click() Randomize NE = InputBox("Entrez le Nombre d'lments dsir :", "Gestion de Listes") For i = 1 To NE El = Int(Rnd * 150000) List1.AddItem El Next Li.Caption = "Liste Gauche ... " & List1.ListCount & " lements" End Sub ' Procdure associe au bouton Effacer la liste Private Sub Command2_Click() If List1.ListCount = 0 Then MsgBox "Liste Vide", vbInformation: Exit Sub R = MsgBox("Etes-vous sr de vouloir supprimer tous les lments de la liste", vbYesNo , "Gestion des Listes") If R = vbYes Then List1.Clear End Sub ' Procdure associe au bouton Effacer les lmnts slectionns Private Sub Command3_Click() For i = List1.ListCount - 1 To 0 Step -1 If List1.Selected(i) = True Then List1.RemoveItem i Next Li.Caption = "Liste Gauche ... " & List1.ListCount & " lements" End Sub

' Procdure associe au bouton Ajouter les lments slectionns la deuxime Liste Private Sub Command4_Click() For i = 0 To List1.ListCount - 1 If List1.Selected(i) = True Then List2.AddItem List1.List(i) Next End Sub ' Procdure associe au bouton Effacer un seul lment de la deuxime Liste Private Sub Command5_Click() El = List2.ListIndex R = MsgBox("Etes-vous sr de vouloir supprimer l'lments Slectionn ", vbYesNo, "Gestion des Listes") If R = vbYes Then List2.RemoveItem El End Sub Exercice : Afficher un message quelconque puis l'aide des botes de dialogue Coule urs modifier les couleurs d'criture et celle d'affichage. Afficher la bote de dialogue "Ouvrir" puis modifier le filtre des fichiers affich er. PAGE N : 41 / 53

TRAVAUX PRATIQUES ' Affichage de la bote de dialogue "Police" Private Sub Command1_Click() On Error GoTo TErreur CommonDialog1.Flags = 3 CommonDialog1.ShowFont Label1.Font = CommonDialog1.FontName Label1.FontSize = CommonDialog1.FontSize Label1.FontItalic = CommonDialog1.FontItalic Exit Sub TErreur: If Err.Number = 32755 Then Exit Sub MsgBox Err.Description, 16, "Erreur !" End Sub ' Affichage de la bote de dialogue "Couleurs" Pour la gestion de la couleur d'crit ure Private Sub Command2_Click() On Error GoTo TErreur CommonDialog1.Flags = 3 CommonDialog1.ShowColor Label1.ForeColor = CommonDialog1.Color Exit Sub TErreur: If Err.Number = 32755 Then Exit Sub MsgBox Err.Description, 16, "Erreur !" End Sub ' Affichage de la bote de dialogue "Couleurs" pour la gestion du Fonds de l'tiquet te Private Sub Command3_Click() On Error GoTo TErreur CommonDialog1.Flags = 3 CommonDialog1.ShowColor Label1.BackColor = CommonDialog1.Color Exit Sub TErreur: If Err.Number = 32755 Then Exit Sub MsgBox Err.Description, 16, "Erreur !" End Sub ' Procdure Quitter Private Sub Command4_Click() End End Sub Exercice : En utilisant le contrle Grille, afficher 8 colonnes et 6 lignes conten

ant des nombres tirs au hasard. Procdure permettant de tirer 6 Nombres (8 Fois) Private Sub Form_Load() Randomize For I = 1 To 8 With MSFlexGrid1 .Col = I: .Row = 0: .Text = "Grille N " & I For J = 1 To 6 .Col = I: .Row = J: .Text = Int(Rnd * 49) + 1 .Col = 0: .Text = "Nombre " & J Next End With PAGE N : 42 / 53

TRAVAUX PRATIQUES Next End Sub Exercice: Afficher une grille de Loto l'aide de 49 boutons de commande. Les nomb res choisis par l'utilisateur se dplaceront afin de se mettre l'un ct de l'autre. Exercice : Raliser le jeu suivant : ? ? ? ? ? ? ? ? ? Remarques : Si vous rpondez 3 questions formant une ligne droite, C est gagn. Le programme doit avoir sa disposition au minimum 30 questions. Sur les 9 questions proposes, 3 sont vides et contiennent une image souriante et sont places au hasard. Si la case a t utilise et la rponse est juste, un cercle rouge apparat l intrieur de la case. Dans le cas contraire, afficher un petit rectangle bleu. Dim TQ(1 To 9) As String Dim LQ(1 To 6), QP(1 To 6) As Integer Dim NQP As Integer Dim CHBR As String Private Sub BQ_Click(Index As Integer) LQAP = Array("Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7", "Q8", "Q9", "Q10") RP = Array("R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10") LCG = Array("123", "456", "789", "147", "258", "369", "159", "357") CH = "C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Misc\" If TQ(Index) = "Q" Then T = True While T = True T = False: A = Int(Rnd * 10) If NQP >= 1 Then For I = 1 To NQP If A = QP(I) Then T = True Next End If Wend NQP = NQP + 1: QP(NQP) = A R = InputBox(LQAP(A), "Jeu Culturel")

If R = RP(A) Then FI = "Face05": CHBR = CHBR & BQ(Index).Index Else FI = "Face04" Else FI = "Face01" End If BQ(Index).Caption = "" BQ(Index).Picture = LoadPicture(CH + FI + ".Ico") Label1.Caption = CHBR If Len(CHBR) >= 3 Then For I = 0 To 7 If InStr(CHBR, Mid(LCG(I), 1, 1)) <> 0 And InStr(CHBR, Mid(LCG(I), 2, 1)) <> 0 And InStr(CHBR, Mid(LCG(I), 3, 1)) <> 0 Then TT = True PAGE N : 43 / 53

TRAVAUX PRATIQUES Next If TT Then MsgBox "Flicitations.. Vous avez gagn" Exit Sub End If End If End Sub Private Sub Form_Load() NQP = 0: NBQ = 0: Randomize: CHBR = "" For I = 1 To 9 TQ(I) = " " Next While NBQ <> 6 PP = Int(Rnd * 9) + 1 T = True For I = 1 To NBQ: If LQ(I) = PP Then T = False Next If T Then NBQ = NBQ + 1: TQ(PP) = "Q": LQ(NBQ) = PP Wend End Sub Exercice : Devinette. Nous dsirons laborer un programme qui permet l utilisateur de jouer la devinette. Le programme calcule un nombre au hasard et l affiche sous forme d indication l aide d une barre de dfilement. L utilisateur doit trouver le numro cach en moins de 90 secondes.

Dim A, TE, NE As Integer ' Procdure Permettant de Commencer Une Nouvelle Partie Private Sub Command1_Click() Randomize: A = Int(Rnd * 32000) + 1: TE = 0: Timer1.Enabled = True HScroll1.Value = A: Text1.Text = "": Command3.Enabled = True: NE = 0 Text1.Enabled = True: Text1.SetFocus End Sub ' Procdure Fin De Session Private Sub Command2_Click() End End Sub ' Procdure Associe au Bouton "Ok"

Private Sub Command3_Click() B = Val(Text1.Text): MS = IIf(B > A, "Trop Grand", IIf(A = B, "Gagn", "Petit")) MsgBox MS, vbInformation, "Devinette" If A = B Then Command3.Enabled = False: Text1.Enabled = False: Timer1.Enabled = False _ Else Text1.SetFocus NE = NE + 1: Label3.Caption = NE & " Essais" End Sub Private Sub Timer1_Timer() TE = TE + 1 Label5.Caption = TE If TE = 90 Then MsgBox "Temps Ecoul", vbOKOnly Timer1.Enabled = False PAGE N : 44 / 53

TRAVAUX PRATIQUES Command3.Enabled = False MsgBox "Nombre Cach est " & A, vbOKOnly, "Devinette" Command3.Enabled = False: Text1.Enabled = False End If End Sub Exercice : Utilisation des Grilles Dans le cadre de la gestion d'une banque, nous dsirons laborer une grille compose des informations suivantes : Numro de Client Nom et Prnom Type Compte (Sur Carnet ou Courant) Date ouverture du compte Solde d'ouverture Solde actuel Type solde Actuel (Dbit ou Crdit). Travail faire : 1. Valider la saisie des donnes. 2. Ajouter les informations saisies dans la grille. 3. Calculer la somme, la moyenne, le plus grand et le plus petit des Soldes actuels. 4. Calculer la somme des soldes par Type solde. 5. Calculer l'anciennet en annes de chaque compte et l'afficher comme nouvelle colonne. 6. Calculer le jour d'ouverture pour chaque compte. Dim nl, nc As Integer Dim ne As Integer Procdure associe l ajout des donnes Private Sub ajou_Click() m = Text1.Text gestion.Row = nl: gestion.Col = nc: gestion.Text = m Text1 = "": Text1.SetFocus End Sub Procdure Calcul de l anciennet Private Sub anc_Click() For i = 1 To gestion.Rows - 1 gestion.Col = 4: gestion.Row = i If gestion.Text <> "" And IsDate(gestion.Text) Then r = DateDiff("yyyy", gestion.Text, Date) gestion.Cols = 10: gestion.Col = 9 gestion.Text = r End If Next End Sub

Procdure Calcul Private Sub cal_Click() gestion.Col = 6: gestion.Row = 1: ne = 1 pp = Val(gestion.Text): pg = Val(gestion.Text): s = Val(gestion.Text) For i = 2 To gestion.Rows - 1 gestion.Row = i If Val(gestion.Text) > 0 Then ne = ne + 1: s = s + Val(gestion.Text) PAGE N : 45 / 53

TRAVAUX PRATIQUES If pg < Val(gestion.Text) Then pg = Val(gestion.Text) If pp > Val(gestion.Text) Then pp = Val(gestion.Text) End If Next m = s / ne mes = "somme" + Str(s) + vbCrLf mes = mes + "moyenne" + Str(m) + vbCrLf mes = mes + "plus grand" + Str(pg) + vbCrLf mes = mes + "plus petit" + Str(pp) MsgBox mes End Sub Procdure Quitter Private Sub fin_Click() End End Sub Procdure associe au dmarrage Private Sub gestion.Row gestion.Col gestion.Col gestion.Col gestion.Col gestion.Col gestion.Col gestion.Col End Sub Au Clic sur la grille Private Sub gestion_Click() nc = gestion.Col: nl = gestion.Row Label2.Visible = True: Text1.Visible = True: Text1.SetFocus Select Case nc: Case Case Case Case Case Case Case 1: 2: 3: 4: 5: 6: 7: Label2 Label2 Label2 Label2 Label2 Label2 Label2 = = = = = = = "numro de compte" "nom et prnom" "type de compte" "date d'ouverture" "solde d'ouverture" "solde actuelle" "type solde" Form_Load(): nl = = 0 = 1: gestion.Text = 2: gestion.Text = 3: gestion.Text = 4: gestion.Text = 5: gestion.Text = 6: gestion.Text = 7: gestion.Text nl + 1 = = = = = = = "N Compte" "Nom et prnom" "type de compte" "date d'ouverture de compte" "solde d'ouverture" "solde actuelle" "type solde"

End Select End Sub Private Sub jl_Click()

For i = 1 To gestion.Rows - 1 gestion.Col = 4: gestion.Row = i If gestion.Text <> "" And IsDate(gestion.Text) Then s = Weekday(gestion.Text) jle = Choose(s, "dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", " samedi") gestion.Cols = 9: gestion.Col = 8 gestion.Text = jle End If Next End Sub Private Sub som_Click() PAGE N : 46 / 53

TRAVAUX PRATIQUES s = gestion.Text: gestion.Col r = InputBox("entrer les types For i = 1 To gestion.Rows - 1 gestion.Row = i: gestion.Col = If gestion.Text = r Then gestion.Col = 6: gestion.Row = s = s + gestion.Text End If Next MsgBox s End Sub Private Sub Text1_keypress(ka As Integer) Select Case nc: Case 1: If InStr("0123456789", Chr(ka)) = 0 And ka <> vbKeyBack And ka <> vbKeyReturn Then ka = 0 Case 2: If (UCase(Chr(ka)) < "A" Or UCase(Chr(ka)) > "Z") And ka <> vbKeyBack And ka <> vbKeyReturn Then ka = 0 Case 3: If InStr("carnetou", Chr(ka)) = 0 And ka <> vbKeyBack And ka <> vbKeyReturn Then ka = 0 Case 4: If InStr("0123456789/", Chr(ka)) = 0 And ka <> vbKeyBack And ka <> vbKeyReturn Then ka = 0 Case 5: If InStr("0123456789.", Chr(ka)) = 0 And ka <> vbKeyBack And ka <> vbKeyReturn Then ka = 0 Case 6: If InStr("0123456789.", Chr(ka)) = 0 And ka <> vbKeyBack And ka <> vbKeyReturn Then ka = 0 Case 7: If InStr("DEBITEURC", UCase(Chr(ka))) = 0 And ka <> vbKeyBack And ka <> vbKeyReturn Then ka = 0 End Select If ka = vbKeyReturn Then m = Text1.Text: gestion.Row = nl: gestion.Col = nc: gestion.Text = m gestion.Col = 0: gestion.Text = nl: gestion.Col = nc: nl = nl + 1 Text1 = "": Text1.SetFocus End If End Sub = 7: gestion.Row = 1 soldes", vbOKOnly) 7 i

PAGE N : 47 / 53

TRAVAUX PRATIQUES PROJETS INFORMATIQUES CURSUS T-TS NIVEAU II U.F. 4 OBJECTIF APPLIQUER LES NOTIONS THORIQUES ACQUISES DANS LES DIFFRENTES SQUENCES ET LES METTRE EN PRATIQUE 1. GESTION DE LA BILLETTERIE DE LA CTM 2. GESTION D'UNE BANQUE 3. GESTION D'UNE AGENCE DE VOYAGES 4. GESTION COMMERCIALE ET GESTION DU STOCK 5. GESTION COMPTABLE 6. GESTION DU PERSONNEL ET DE LA PAIE 7. GESTION D'UN CABINET MDICAL 8. GESTION DES LECTIONS MUNICIPALES 9. GESTION DES RSERVATIONS ET DES FACTURATIONS DANS UN HTEL 10. GESTION D'UNE BIBLIOTHQUE 11. GESTION D'UNE VIDOTHQUE 12. GESTION DES RGLEMENTS DES TUDIANTS D'UNE COLE PRIVE 13. GESTION DES SERVICES APRS VENTE D'UNE SOCIT DE VENTE D'APPAREILS LECTROMNAGERS 14. GESTION DU CONCOURS D'ENTRE DANS DES GRANDES COLES 15. GESTION D'UNE FDRATION SPORTIVE 16. GESTION D'UN CABINET D'ANALYSES MDICALES 17. PROJET PALAIS DES CONGRS PAGE N : 48 / 53

TRAVAUX PRATIQUES Travaux Pratiques Systme / Rseaux / Internet NIVEAU I PREMIRE ANNE T/TS TP1 : TP Observatoire de l architecture d un ordinateur. Vue exhaustive des diffrents composants : o Carte mre o Microprocesseur o R.A.M. o Diffrents priphriques Pr-requis : Connaissance thorique des diffrents composants hardware. TP2 : Dbrancher et Brancher les diffrents priphriques d un P.C. TP 3 : Installer un CD-ROM TP 4 : Assembler les diffrents organes la carte mre Exemples : -Ajouter une barrette mmoire -Vrification de l oprabilit de l organe ajout (Polycope : Maintenance Matrielle. Remarques gnrales : -Vrification de la cohrence d un matriel -On peut ventuellement offrir du matriel dfectueux aux tudiants (sans qu ils le sachent) et doivent le dtecter pratiquement. TP 5 : TP Observatoire de l architecture d un ordinateur dans un rseau Vue exhaustive des diffrents composants rseaux : o Cables o

Switch o Hubs o PAGE N : 49 / 53

TRAVAUX PRATIQUES TP 6 : Utilisation des cbles RJ 45 Connections des cbles aux ordinateurs dont les cartes rseaux sont pr- installes Connections des cbles aux switch avec un systme de numrotation TP 7 : Installation d une carte rseau : Mthode 1 : Plug and Play de Windows XP Mthode 2 : Utilisation d un driver externe.

Visualiser les proprits de la carte rseau Vrification Favoris rseau de l affichage du nom de l ordinateur. TP 8 : Formatage et Partitionnement d un disque dur en utilisant FDISK T P 9 : Installation de Windows XP T P 10 : Paramtrage de Windows XP : Cration de dossiers Gestion de fichiers Gestion du Bureau Proprits du Poste de travail T P 11 : Installation d autres logiciels : Microsoft Office XP (avec le choix des diffrents composants) Installation de Visual Studio (Personnalise) T P 12 : Bureautique (Word) : Cration de documents Saisie de documents

Mise en forme Utilisation des styles prdfinis PAGE N : 50 / 53

TRAVAUX PRATIQUES T P 13: Bureautique (Word) : Cration de styles personnaliss Utilisation de styles personnaliss Elaboration de tables de matires T P 14 : Bureautique (Word) : Cration de modles documents Utilisation de modles T P 15 : Bureautique (Excel) : Saisie de donnes dans les cellules Utilisation des formules simples T P 16 : Bureautique (Excel) : Calculs conditionnels Mises en forme des cellules T P 17 : Bureautique (Excel) : Calculs statistiques Graphiques (Utilisation des supports Pigier) Remarques gnrales : -La coordination entre le corps professoral est indispensable -Selon le niveau du groupe, le professeur pourra programmer d autres sances de TP supplmentaires de T.P. pour approfondir soit pour la mise niveau. PAGE N : 51 / 53

TRAVAUX PRATIQUES Travaux Pratiques Systme / Rseaux / Internet Niveau deuxime anne : T/TS au niveau matriel les mmes TP mais avec une vitesse plus rapide (du TP 1 au TP 11) TP en plus : TP 1 : Utilisation des systmes multi-boot TP 2 : -Gestion des noms et adresses -Paramtrage et Utilisation du DNS pour pouvoir naviguer sur Internet Pre-requis : -Partage de donnes -Gestion des utilisateurs (ajout utilisateurs ) -Ajout TCP.IP -Installation DNS TP3 : IDEM POUR LE WINS TP4 : idem pour le DHCP TP 5 : Installation de domaines Dclarations des utilisateurs Gestion de groupe Partage de priphrique TP : Installation de domaines Dclarations des utilisateurs Gestion de groupe Partage de priphrique ( exp. : imprimante ) Installation priphrique ( client / serveur) PAGE N : 52 / 53

TRAVAUX PRATIQUES TP : bureautique : TP 6 : exercice de rappel TP 7 : UTILISATIONS DES FONCTIONS AVANCES -Filtres -Tableaux croiss dynamiques -Sous totaux -Graphique TP 8 : -mise en forme conditionnelle -Mise en page -Scurit des fichiers -Consolidation PAGE N : 53 / 53

You might also like