Chapitre 2 les structures de controle 1
Langage de programmation Visual Basic pour Applications VBA Responsable Dr Fadoua BOUAFIF Filière Mastère Profestionel Ingénierie Economique et Financière langage de programmation VBA F BOUAFIF CChapitre Les structures de Contrôles langage de programmation VBA F BOUAFIF CPlan du chapitre Structures conditionnelles ? If ? then ? elseif ? else ? end if ? Select ? case Structures répétitives ? While ? wend ? Do While ? loop ? Do ? loop while ? Do Until ? loop ? Do ? loop Until ? For ? step ? Next ? For Each ? IN ? Next F BOUAFIF langage de programmation VBA CLes structures condionnelles langage de programmation VBA F BOUAFIF CIf ? Then ? Elseif ? Else ? End If ? Syntaxe sur une seule ligne If condition Then Else End If Exemple If Moyenne Then Résultat Admis End If If Moyenne Then Résultat Admis Else Résultat Ajourné End If F BOUAFIF langage de programmation VBA CIf ? Then ? Elseif ? Else ? End If ? ElseIf permet d'ajouter plusieurs conditions à la suite Syntaxe Exemple If condition Then ElseIf condition then ? ? ? ? Else End If If Moy and moy Then Résultat Admis passable ElseIf Moy and moy Then Résultat Admis assezbien ElseIf Moy and moy Then Résultat Admis bien ElseIf Moy Then Résultat Admis trèsbien Else Résultat Etudiant Ajourné End If langage de programmation VBA F BOUAFIF CSelect ? case ? ? Lorsque l ? on aura besoin de faire des tests multiples sur une variable on utilisera select ? case ? Syntaxe Select Case Variable Case valeur Case valeur ? ? ? Case Else End Select ? facultative F BOUAFIF langage de programmation VBA CSelect ? case ? Exemple A ?cher le type d ? un caractère donné selon son code ASCII Public Sub testSelest Dim code as integer code InputBox ? ? tapez le code ASCII du caractère ? ? Select Case code Case MsgBox C ? est une voyelle ? a ?che résultat Case To MsgBox C ? est une consonne ? a ?che résultat Case Else MsgBox Ce n ? est pas une lettre ? a ?che résultat End select End Sub F BOUAFIF langage de programmation VBA CLes structures répétitives langage de programmation VBA F BOUAFIF CLes Boucles While ? Wend ? Lorsque l ? on voudra répéter une portion de programme tant qu ? une condition est vrai on utilisera une boucle While ? Wend ? Une condition est une comparaison entre deux valeurs à travers un opérateur de comparaison Syntaxe While condition Wend La condition est évaluée au début du traitement Si elle est vraie les instructions sont exécutées Ensuite la condition est réévaluée et ainsi de suite Exemple Sub TestWhile Dim x As integer x while x MsgBox valeur de x x x x- Wend End Sub langage de programmation VBA F BOUAFIF CLes Boucles Do While ? Loop On utilisera une boucle Do while Loop lorsque l ? on veut que la boucle continue tant que
Documents similaires
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/11702804111mwavmhxfbsytusyufpx7dqfrpnphlddozimrkoih7bojpknpyeeofblzcfpwxqzouhm3tv4vdnp38dwadf2aa753gkrpd6mskpc4.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/117027546408osclf0wxnrntrhns1jx7oa76vzr4gmqcqopzekhbliju5glyth8zkmxovy66b5fve2btfimbmobtkvexrdfmz0wbi18gkx6zvif.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/vtV501jmTXSiCPVQtcBNriv86dRwqVUkApe9MkbTSqKKvCTHs1FvLnDXLrUuDDkXftPH10DhdKYHbM2BhWekuu0P.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/11702741748icjo9vojtztwhgk5jdk3bcggli5vubguddbpfomlb70kksvpvsxi8rsvsvizqoj0hipd93eysg9neuvrbaqxqwi1ogaesfny1akg.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/Xflbt0iUqkVdNFU75lMZG5cKUf6ECronxuYpa7amHpfS7lexHTJ5PKo9oSEYyKv68VFXGB3VjZAGtNhjrh25aLyr.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/RXDDZ1C4n5uYHMmwBr4Y3BxNFuxtBH2ovlVVwFuEHNahqdf9jBcn3k3408vD0MTc4Tx03UvYrcXRjCcUpT8judBi.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/Wtxg2eLwulIqJAoj8XVx26tKVyHRTR7fPEYQiJbjjINuRMj6TnQrPr3yFoaN2jJY4fewadjJoHWfr97mwHxNJEef.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/bDEJxpcU3v8CSMWz78LwBMWRker1jTBgL25Voz9ZaxS71eACQQELKb2fUbfdBYpsEpfOg2QpPBhw8wwFTW82MJLp.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/TH2M3XjuPVZ9hpJQF3EmDRnAW0bSVHBoN8L6NRD6q0a1z2DTpziQpYv8fh5sdbrHcwJK4X7wheWExvV1aET7KawV.png)
![](https://b3c3.c12.e2-4.dev/disserty/uploads/preview/11702334746fuwjpkv7cc9nqmwrjgtmuldjk24mnzww0rwbrvtdkkqfnp6wxlyvbcz6iwnhndeqn0uff7eftzf1fji2coknxie1efufkghqyxpw.png)
-
35
-
0
-
0
Licence et utilisation
Gratuit pour un usage personnel Aucune attribution requise- Détails
- Publié le Aoû 12, 2022
- Catégorie Heavy Engineering/...
- Langue French
- Taille du fichier 48.2kB