Exercice VB: Gestion d'Article
Rédigé par GC Team, Publié le 01 Janvier 2012, Mise à jour le Vendredi, 16 Décembre 2022 21:33
Participez au vote ☆☆☆☆☆★★★★★
Ecrire le code VB qui permet de :
1- Faire l’écriture des données d'un Article dans un Fichier
2- Faire la lecture des données d'un Article dans un Fichier
3- Faire l’ajout d’un article
4- Faire la suppression d’un article
5- Copier des données d'un Article dans un Fichier
6- Quitter
7- Un menu de Choix
Un Produit est connu par :
- Le numéro de référence
- La désignation de produit
- Le type de produit (A, B ou C)
- Le prix unitaire
- La Quantité
- Le prix totale en TTC
a. Si le type est A alors la TVA est 20%
b. Si le type est B alors la TVA est 14%
c. Si le type est C alors la TVA est 7%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
Imports System Module Module1 Public tcl() As article Public O As Char Public nb As Integer Public Structure article (4)> Public ref As Integer (12)> Public desig As String (2)> Public prix As Double (10)> Public typ As String (12)> Public tva As Double (5)> Public qut As Integer (10)> Public ttc As Double End Structure Sub menu() Console.WriteLine("1.ecriture") Console.WriteLine("2.lecture") Console.WriteLine("3.ajout") Console.WriteLine("4.suppression") Console.WriteLine("5.copier") Console.WriteLine("6.quiter") End Sub Sub Main() Dim choix As String Dim rep As String Do menu() Console.WriteLine(" tapez votre choix") choix = Console.ReadLine Select Case choix Case 1 ecriture() Case 2 lecture(tcl) Case 5 copier() Case 6 quiter() Case 3 'ReDim Preserve tab(tab.GetUpperBound(0) + 1) ajout() Case 4 Console.WriteLine("saisir l'élément supprimer") Dim elem = Console.ReadLine suppression(tcl, elem) Case Else Console.WriteLine("le choix que vous avez tapez est introuvable") End Select Console.WriteLine("voulez-vous contunier ?o/n") rep = Console.ReadLine Loop Until (rep = "n") End Sub Public Sub lecture(ByRef tcl() As article) For i = 0 To tcl.GetUpperBound(0) With tcl(i) Console.WriteLine(tcl(i).ref & vbTab & tcl(i).desig & vbTab & tcl(i).typ & vbTab & tcl(i).prix & vbTab & tcl(i).qut & vbTab & tcl(i).tva & vbTab & tcl(i).ttc) End With Next End Sub Public Sub ecriture() Console.WriteLine("nombre d'article") nb = Console.ReadLine ReDim tcl(nb - 1) For i = 0 To tcl.GetUpperBound(0) With tcl(i) Console.WriteLine("entrez le numero de reference") .ref = Console.ReadLine Console.WriteLine("entrez la designation de produit") .desig = Console.ReadLine Console.WriteLine("entrez le type(A,B ou C) de produit ") .typ = Console.ReadLine Console.WriteLine("entrez le prix unitaire du produit") .prix = Console.ReadLine Console.WriteLine("entrez la Quantité du produit") .qut = Console.ReadLine If .typ = "A" Then .tva = 20% ElseIf .typ = "B" Then .tva = 14% ElseIf .typ = "C" Then .tva = 7% End If .ttc = (CDbl(.prix) * CDbl(.qut)) + (CDbl(.prix) * (CDbl(.qut) * 0.07)) End With Next End Sub Sub ajout() ReDim Preserve tcl(tcl.GetUpperBound(0) + 1) With tcl(tcl.GetUpperBound(0)) Console.WriteLine("entrez le numero de reference") .ref = Console.ReadLine Console.WriteLine("entrez la designation de produit") .desig = Console.ReadLine Console.WriteLine("entrez le type(A,B ou C) de produit ") .typ = Console.ReadLine Console.WriteLine("entrez le prix unitaire du produit") .prix = Console.ReadLine Console.WriteLine("entrez la Quantité du produit") .qut = Console.ReadLine If .typ = "A" Then .tva = 20% ElseIf .typ = "B" Then .tva = 14% ElseIf .typ = "C" Then .tva = 7% End If .ttc = (CDbl(.prix) * CDbl(.qut)) + (CDbl(.prix) * (CDbl(.qut) * 0.07)) End With End Sub Function recherche_par_ref(ByVal tab() As article, ByVal ref As Integer) As Integer For i = 0 To tab.GetUpperBound(0) Next End Function Public Function suppression(ByRef t() As article, ByVal ele As Integer) Dim i As Integer Dim pos = recherche(t, ele) If pos -1 Then i = 0 If pos t.GetUpperBound(0) Then Do t(pos + i) = t(pos + i + 1) i += 1 Loop Until t(pos + i).ref = t(t.GetUpperBound(0)).ref Else ReDim Preserve t(t.Length - 1) Return t End If End If ReDim Preserve t(t.Length - 1) Return t With (i) Console.WriteLine("entrez le numero de reference") tcl(i).ref = Console.ReadLine Console.WriteLine("entrez la designation de produit") tcl(i).desig = Console.ReadLine Console.WriteLine("entrez le type(A,B ou C) de produit ") tcl(i).typ = Console.ReadLine Console.WriteLine("entrez le prix unitaire du produit") tcl(i).prix = Console.ReadLine Console.WriteLine("entrez la Quantité du produit") tcl(i).qut = Console.ReadLine If tcl(i).typ = "A" Then tcl(i).tva = 20% tcl(i).ttc = (CDbl(tcl(i).prix) * CDbl(tcl(i).qut)) + (CDbl(tcl(i).prix) * ((CDbl(tcl(i).qut)) * 0.2)) ElseIf tcl(i).typ = "B" Then tcl(i).tva = 14% tcl(i).ttc = (CDbl(tcl(i).prix) * CDbl(tcl(i).qut)) + (CDbl(tcl(i).prix) * (CDbl(tcl(i).qut) * 0.14)) ElseIf tcl(i).typ = "c" Then tcl(i).tva = 7% tcl(i).ttc = (CDbl(tcl(i).prix) * CDbl(tcl(i).qut)) + (CDbl(tcl(i).prix) * (CDbl(tcl(i).qut) * 0.07)) End If End With End Function Function recherche(ByRef t() As article, ByVal ele As Integer) As Integer For i As Integer = 0 To t.GetUpperBound(0) If t(i).ref = ele Then Return i Exit Function Else End If Next Return -1 End Function Sub copier() FileOpen(1, "fichier.txt", OpenMode.Output) For i = 0 To nb - 1 PrintLine(1, tcl(i).ref & "/" & tcl(i).desig & "/" & tcl(i).typ & "/" & tcl(i).prix & "/" & tcl(i).tva & "/" & tcl(i).ttc) Next FileClose(1) FileOpen(1, "fichier.txt", OpenMode.Input) While Not EOF(1) Console.WriteLine(LineInput(1)) End While FileClose(1) End Sub Public Sub quiter() Exit Sub End Sub End Module |