Cours-Gratuit
  • Accueil
  • Blog
  • Cours informatique
home icon Cours gratuits » Cours informatique » Cours programmation » Cours visual basic » Exercices VB »

Articles similaires

  • Tutoriel Excel : formulaire de saisie
  • Exercice Comptabilité Générale: Bordereau de saisie
  • Exercice Algorithme : Jeu de dames
  • Tutoriel Excel : comment créer un graphique de comparaison
  • Exercice VB: Somme Matrice
  • Exercice : comptabiliser des opérations financières sur bordereau de saisie
  • Excel : comment afficher un message d'erreur ou de saisie
  • Exercice VB: Calcule dans un tableau à une seule dimension
  • Excel : Comment modifier un champ calculé dans un tableau croisé dynamique
  • Exercice Access : Requêtes affichage, Calcule et Fonction
  • Exercice Algorithme : Les Tableaux - Le Tri - Les Fichiers
  • Exercice VB: Fonctions et Procédures

Documents similaires

  • Cours mathematiques financieres : interet simple

  • Exercice de bureautique pour débutant

  • Application Excel pour la gestion des suites arithmétiques

  • Exercice bureautique pour réviser ensemble

  • Application Excel calculatrice de montant TVA

  • Modèle de tableau amortissement immobilisation sur Excel

  • Étudier en BTS tourisme : établissements de formation, lettre de motivation et débouchés du métier 

  • TP programmation web pour débutant

Exercice VB: Saisie et Calcule

Rédigé par GC Team, Publié le 02 Janvier 2012, Mise à jour le Vendredi, 16 Décembre 2022 23:05
Participez au vote ☆☆☆☆☆★★★★★

Travail à Faire :

4. Ecrire un Programme qui demande successivement 20 nombres à l’utilisateur, et qui lui dise ensuite quel était le plus grand parmi ces 20 nombres :

 

Entrez le nombre numéro 1 : 12

Entrez le nombre numéro 2 : 14

…

Entrez le nombre numéro 20 : 6

Le plus grand de ces nombres est : 14

Modifiez ensuite l’Programme pour que le programme affiche de surcroît en quelle position avait été saisie ce nombre :

C’était le nombre numéro 2

5. Ecrire un Programme qui :

- lit d’abord une valeur

- ensuite il va lire successivement 20 nombres.

- enfin il va déterminer combien de fois la première valeur a été saisie (sans compter la première saisie).


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
4.
Module Module1
Dim i, n, max, Pmax As Integer
Sub Main()
Console.Write("Entrez le nombre numéro 1 : ")
n = Console.ReadLine
max = n
Pmax = 1
For i = 2 To 20
Console.Write("Entrez le nombre numéro " & i & " : ")
n = Console.ReadLine
If n > max Then
max = n
Pmax = i
End If
Next
Console.WriteLine("Le plus grand nombre est : " & max)
Console.WriteLine("Sa position est : " & Pmax)
Console.ReadLine()
End Sub
End Module

5.
Module Module1
Dim i, a, b, Cpt As Integer
Sub Main()
Console.Write("Entrez un chiffre : ")
a = Console.ReadLine
Cpt = 0
For i = 1 To 20
Console.Write("Entrez un chiffre : ")
b = Console.ReadLine
If a = b Then
Cpt = Cpt + 1
End If
Next

Console.WriteLine("Le nombre de fois de saisie de " & a & " est :
" & Cpt)
Console.ReadLine()
End Sub
End Module

Exercice VB: Les suites et Fonctions de Calcule

Objectif :

Travailler avec les Suites et Fonctions.

Travail à Faire :

1. Donnez un programme pour calculer :

    ex = 1 + X + X2 /2!+ X3/3!+ ……. + XN/N!NB : avec N un donnée d'entrée.

2. Donnez un programme pour calculer :

    ex = 1 + X + X2 /2!+ X3/3!+ ……. + XN/N!NB : avec N un donnée d'entrée.

    Le calcule de ex s'arrête quand XN/N! Devient inférieur strictement à EPS (EPS est une donnée d'entrée).

3. Donnez un programme pour calculer :

    S = SIN(X) = X – X3 /3!+ X5/5!– X7/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
1.
Module Module1
Dim i, e, X, P, F As Double
Sub Main()
Console.Write("Entrez la valeur de x : ")
X = Console.ReadLine
Console.Write("Entrez la puissance : ")
P = Console.ReadLine
e = 1
F = 1
For i = 1 To P
F = F * i
e = e + ((X ^ i) / F)
Next
Console.Write("e est : " & e)
Console.ReadLine()
End Sub
End Module

2.
Module Module1
Dim i, e, X, EPS, F As Double
Sub Main()
Console.Write("Entrez la valeur de x : ")
X = Console.ReadLine
Console.Write("Entrez la valeur d'EPS : ")
EPS = Console.ReadLine
e = 1
F = 1
i = 1
Do
F = F * i
e = e + ((X ^ i) / F)
i += 1
Loop Until (e < EPS)
Console.Write("e est : " & e)
Console.ReadLine()
End Sub
End Module

3.
Module Module1
Dim i, X, F, P, S, L, j, k As Double
Sub Main()
Console.Write("Entrez la valeur de X : ")
X = Console.ReadLine
Console.Write("Entrez la puissance : ")
P = Console.ReadLine
S = 0
For i = 0 To P
F = 1
L = 1
For j = 1 To (4 * i + 1)
F = F * j
Next
For k = 1 To (4 * i + 3)
L = L * k
Next
S = S + ((X ^ (4 * i + 1)) / F) - ((X ^ (4 * i + 3)) / L)
Next
Console.Write("S est : " & S)
Console.ReadLine()
End Sub
End Module

Exercice VB: Les suites Matricielles

Objectif :

Travailler avec les Suites et Fonctions.

Travail à Faire :

1. Donnez un programme pour calculer :

/

| S0 = 1

| Sn = 3Sn-1 + 5

\

2. Donnez un programme pour calculer :

/

| S0 = 1/2

| S1 = 1

| Sn+1 = 3Sn – 5Sn-1

\


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
1.
Module Module1
Dim i, S, N As Double
Sub Main()
Console.Write("Entrez la valeur de N : ")
N = Console.ReadLine
S = 1
For i = 1 To N
S = (3 * S + 5)
Next
Console.Write("S est : " & S)
Console.ReadLine()
End Sub
End Module

2.
Module Module1
Dim i, N, X, Y, S As Double
Sub Main()
X = 1 / 2
Y = 1
Console.Write("Entrez la valeur de N : ")
N = Console.ReadLine
S = 0
For i = 1 To N
S = (3 * Y) - (5 * X)
X = Y
Y = S
Next
Console.Write("S est : " & S)
Console.ReadLine()
End Sub
End Module

Exercice VB: Manipulation dans une ArrayListe

Ecrire le code VB qui permet de faire:

1-      Ecriture d'un élément dans une Arrayliste

2-      Lecture d'un élément dans une Arrayliste

3-      Ajout d'un élément dans une Arrayliste

4-      Suppression d'un élément dans une Arrayliste

5-      Insertion d'un élément dans une Arrayliste

6-      Tri dans une Arrayliste

7-      Vider la collection par la méthode Clear

8-      La supprision par la méthode Removeat

9-      Quiter


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
Imports System.Collections
Module Module1
    Dim lst As New ArrayList
    Dim i As Integer
    Sub menu()
        Console.WriteLine("1.ecriture")
        Console.WriteLine("2.lecture")
        Console.WriteLine("3.ajout")
        Console.WriteLine("4.suppression")
        Console.WriteLine("5.insertion")
        Console.WriteLine("6.tri")
        Console.WriteLine("7.clear")
        Console.WriteLine("8.removeat")
        Console.WriteLine("9.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()
                Case 3
                    ajout()
                Case 4
                    'Console.WriteLine("saisir l'élément supprimer")
                    'Dim elem = Console.ReadLine
                    Dim ele As Integer
                    Console.WriteLine("entrez l'èlement à supprimer ")
                    ele = Console.ReadLine
                    If lst.Contains(ele) = True Then
                        suppression(ele)
                    Else
                        Console.WriteLine("l'element n'existe pas")
                    End If
                Case 5
                    insertion()
                Case 6
                    tri()
                Case 7
                    clear()
                Case 8
                    removeat(i)
                Case 9
                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
    Sub ecriture()
        lst.Add(10)
        lst.Add(20)
        lst.Add(88)
        lst.Add(86)
        lst.Add(1)
        lst.Add(60)
    End Sub
    Sub lecture()
        For i = 0 To lst.Count - 1
            Console.WriteLine(lst(i))
        Next
    End Sub
    Sub ajout()
        Dim i As Integer
        Dim rep As String
        Do
            Console.WriteLine("saisir l'élément", i + 1)
            lst.Add(Console.ReadLine)
            i += 1
            Console.WriteLine("voulez vous ajouter un autre O/N")
            rep = Console.ReadLine.ToUpper
        Loop Until rep = "N"
    End Sub
    Sub suppression(ByVal objet As Object)
        lst.Remove(objet)
    End Sub
    Sub removeat(ByVal i As Integer)
        Console.WriteLine("saisir la position de l'élément à supprimer")
        i = Console.ReadLine
        lst.RemoveAt(i)
        lst.RemoveAt(i)
    End Sub
    Sub insertion()
        Dim ele As Integer
        Dim i As Integer
        Console.WriteLine("saisir l'élément à inserer ")
        ele = Console.ReadLine
        Console.WriteLine("saisir le position ou vous voulez inserer cette ele")
        i = Console.ReadLine
        lst.Insert(i, ele)
    End Sub
    'Function recherche()
    '    Dim ele, i, k As Integer
    '    Console.WriteLine("saisir l'élément à rechercher")
    '    ele = Console.ReadLine
    '    If lst.Contains(ele) = True Then
    '        k = lst.IndexOf(ele)
    '        Return k
    '    Else
    '    End If
    '    Return -1
    'End Function
    Sub clear()
        lst.Clear()
    End Sub
    Sub tri()
        lst.Sort()
    End Sub
End Module

Exercice VB: Manipulation des Tableaux

Objectif :

Travailler avec les Tableaux

Travail à Faire :

Ecrire le code en VB qui permet de :

  1. Créer un le Tableau T (0, 10, 20, 30)
  2. Créer le Tableau suivant :

0

5

1

7

8

4

-6

12

  1. rassembler deux Tableaux

 

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
' directives
Option Strict On
Option Explicit On
' imports
Imports System
' classe de test
Module test
    Sub main()
        ' un tableau à 1 dimension initialisé
        Dim entiers() As Integer = {0, 10, 20, 30}
        Dim i As Integer
        For i = 0 To entiers.Length - 1
            Console.Out.WriteLine("entiers[" & i & "]=" & entiers(i))
        Next
        ' un tableau à 2 dimensions initialisé
        Dim réels(,) As Double = {{0.5, 1,7}, {8.4, -6,12}}
        Dim j As Integer
        For i = 0 To entiers.Length - 1
            Console.Out.WriteLine("entiers[" & i & "]=" & entiers(i))
        Next
        ' un tableau°de tableaux
        Dim noms()() As String = New String(3)() {}
        ' initialisation
        For i = 0 To noms.Length - 1
            noms(i) = New String(i) {}
            For j = 0 To noms(i).Length - 1
                noms(i)(j) = "nom" & i & j
            Next
        Next
        ' affichage
        For i = 0 To noms.Length - 1
            For j = 0 To noms(i).Length - 1
                Console.Out.WriteLine("noms[" & i & "][" & j & "]=" & noms(i)(j))
            Next
        Next
        Console.ReadLine()
    End Sub
End Module

 Exercice VB.Net : Examen passage 2007 v 11 Ista, Parti Application

 

On souhaite maintenant re-développer quelques fonctionnalités de cette application (de la Partie JAVA) en Vb

  1. Créer un formulaire permettant d’ajouter, modifier, supprimer et rechercher un contact (1 Pt)
  2. Programmer les fonctionnalités suivantes :
    1. Ajout (1 Pt)
    2. Modification (2 Pts)
    3. Suppression (2 Pts)
    4. Recherche (2 Pts)
  3. Ajouter un bouton permettant d’afficher la liste des contacts d’un établissement donné après avoir saisie le nom de l’établissement dans une zone de texte (2 Pts)
  4. Ajouter dans un autre formulaire une liste affichant les contacts triés par établissement et par âge (2 Pts)

Interface Graphique:

ExerciceVB-id2104

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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
Public Class Form1
    Public c As New contact
    Dim i, pos As Integer
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        c._num += 1
        TextBox1.Text = c._num
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        MaskedTextBox1.Text = ""
    End Sub
    Sub lire(ByVal pos As Integer)
        c = lst(pos)
        remplirez()
    End Sub
    Sub remplirez()
        TextBox1.Text = c._num
        TextBox2.Text = c._nom
        TextBox3.Text = c._prénom
        TextBox4.Text = c._poste
        TextBox5.Text = c._Entreprise
        TextBox6.Text = pos
        MaskedTextBox1.Text = c._date_n
    End Sub
    Sub raz()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        MaskedTextBox1.Text = ""
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        c._num += 1
        TextBox1.Text = c._num
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim c As New contact(TextBox2.Text, TextBox3.Text, TextBox4.Text, MaskedTextBox1.Text, TextBox5.Text)
        c._num += 1
        c._num = TextBox1.Text
        c._nom = TextBox2.Text
        c._prénom = TextBox3.Text
        c._poste = TextBox4.Text
        c._Entreprise = TextBox5.Text
        c._date_n = MaskedTextBox1.Text
        lst.Add(c)
    End Sub
    '
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If MsgBox("Voulez vous vraiment Modifier cette enregestrement", MsgBoxStyle.YesNo Or MsgBoxStyle.Question, "Confirmation Modification") = MsgBoxResult.Yes Then
            For Each elem In lst
                If elem._num = TextBox1.Text Then
                    Try
                        lst.RemoveAt(i)
                        If lst.Count < 1 Then
                            lst.Add(elem)
                        Else
                            lst.Insert(i, elem)
                        End If
                    Catch ex As Exception
                        MsgBox(ex.Message, MsgBoxStyle.Information)
                    End Try
                    Exit For
                End If
                i += 1
            Next
        End If
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If MsgBox("Voulez vous vraiment Supprimer cette enregestrement", MsgBoxStyle.YesNo Or MsgBoxStyle.Question, "Confirmation Suppression") = MsgBoxResult.Yes Then
            For Each el In lst
                If el._num = TextBox1.Text Then
                    lst.RemoveAt(i)
                    Try
                        lire(i)
                        pos = i
                    Catch ex As Exception
                        If lst.Count < 1 Then
                            raz()
                        Else
                            lire(i - 1)
                            pos = i - 1
                        End If
                    End Try
                    Exit For
                End If
                i += 1
            Next
        End If
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Dim a As Integer = InputBox("entrer le numéro de l'enregestrement à rechercher", "Recherche")
        For i = 0 To lst.Count - 1
            c = lst(i)
            If a = c._num Then
                remplirez()
                pos = i
                Exit Sub
            End If
        Next
        i += 1
        MsgBox("l'élément rechercher n'existe pas", MsgBoxStyle.Critical, "recherche")
    End Sub
    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        If MsgBox("Voulez vous vraiment Quitter l'application ", MsgBoxStyle.YesNo Or MsgBoxStyle.Question, "Confirmation Sortie") = MsgBoxResult.Yes Then
            End
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        pos = 0
        lire(pos)
        TextBox6.Text = pos + 1
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        pos = lst.Count - 1
        lire(pos)
        TextBox6.Text = pos + 1
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            pos -= 1
            lire(pos)
            TextBox6.Text = pos + 1
        Catch ex As Exception
        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Try
            pos += 1
            lire(pos)
            TextBox6.Text = pos + 1
        Catch ex As Exception
        End Try
    End Sub
End Class

----------------------------------------------------------------------------


Public Class contact
    Private num As Integer
    Private nom As String
    Private prénom As String
    Private Date_n As Date
    Private poste As String
    Private entreprise As String
    Property _num() As Integer
        Get
            Return num
        End Get
        Set(ByVal value As Integer)
            num = value
        End Set
    End Property
    Property _nom() As String
        Get
            Return nom
        End Get
        Set(ByVal value As String)
            nom = value
        End Set
    End Property
    Property _prénom() As String
        Get
            Return prénom
        End Get
        Set(ByVal value As String)
            prénom = value
        End Set
    End Property
    Property _date_n() As Date
        Get
            Return Date_n
        End Get
        Set(ByVal value As Date)
            Date_n = value
        End Set
    End Property
    Property _poste() As String
        Get
            Return poste
        End Get
        Set(ByVal value As String)
            poste = value
        End Set
    End Property
    Property _Entreprise() As String
        Get
            Return entreprise
        End Get
        Set(ByVal value As String)
            entreprise = value
        End Set
    End Property
    Sub New()
    End Sub
    Public Sub New(ByVal N As String, ByVal P As String, ByVal po As String, ByVal DN As Date, ByVal En As String)
        _nom = N
        _prénom = P
        _date_n = DN
        _poste = po
        _Entreprise = En
    End Sub
    Public Sub afficher()
        Console.WriteLine(_num & vbTab & _nom & vbTab & _poste & vbTab & _date_n & vbTab & _poste & vbTab & _Entreprise)
    End Sub
    Public Function age() As String
        Return DateDiff(DateInterval.Year, Date_n, Today)
    End Function
    Sub N_poste(ByVal new_poste As String)
        '
        Do
            Console.WriteLine("entrer le nouveau poste")
            new_poste = Console.ReadLine
            If new_poste  "" Then
                poste = new_poste
                Exit Do
            Else
                Dim postexception As New Exception("entrer le nouveau poste correctement")
                Console.WriteLine(postexception)
            End If
        Loop Until new_poste = ""
    End Sub
    Public Sub new_ent(ByVal newE As String)
        Do
            Console.WriteLine("saisire le nouvelle entreprise")
            newE = Console.ReadLine
            If newE  "" Then
                entreprise = newE
                Exit Do
            Else
                Dim enexception As New Exception("saisire la nouvelle entreprise correctement")
                Console.WriteLine(enexception)
            End If
        Loop Until newE = ""
    End Sub
End Class

Exercice VB.Net : Examen TSDI juin 2007 Variante 5

Considérant le schéma relationnel, de la gestion d’un parc informatique, suivant :

SEGMENT (N_SEGMENT, NOM_SEGMENT)

SALLE (N_SALLE, NOM_S, NB_POSTE, #N_SEGMENT)

POSTE (N_POSTE, NOM_P, #N_SEGMENT, AD, TYPE_P, #N_SALLE)

LOGICIEL (N_LOG, NOM_L, DATE_ACH, VERSION, TYPE_L)

INSTALLER (#N_POSTE, #N_LOG, DATE_INS)

Les types des colonnes sont les suivants :

N_SEGMENT           : 3 premiers groupes IP (ex : ’130.120.80’)               VARCHAR(10)

NOM_SEGMENT     : nom attribué au segment                                         VARCHAR(20)

N_SALLE                  : numéro la salle (ex : ’s01’, ’s02’...)                          VARCHAR(7)

NOM_S                      : nom de la salle                                                         VARCHAR(20)

NB_POSTE               : nombre de postes de travail dans la salle                INT

N_POSTE                  : code interne associé au poste (ex : ’p1’)                 VARCHAR(7)

NOM_P                      : nom (ou alias) donné au poste                                 VARCHAR(20)

AD                             : dernier groupe de chiffre ip                                                VARCHAR(2)

TYPE_P                     : type du poste (ex : ’UNIX’, ’TX’,....)                     VARCHAR(6)

DATE_INS                : date d’installation du logiciel sur le poste               DATETIME

N_LOG                      : numéro interne du logiciel                                       VARCHAR(5)

NOM_L                     : nom du logiciel                                                        VARCHAR(20)

DATE_ACH              : date d’achat du logiciel                                           DATETIME

VERSION                 : version du logiciel (ex : ’8.0’)                                 VARCHAR(7)

TYPE_L                     : type du logiciel (ex : ’UNIX’, ’PCWS’...)              VARCHAR(6)

I-                   Création de la base de données: 

  1. Créer cette base de données dans SQLServer (Tables + Relations) (2pts).
  2. Ecrire le ou les triggers qui permettent de gérer l’attribut NB_POSTE (1pt). 

II-                VB.Net

  1. Concevoir un formulaire qui permet d’enregistrer les Salles et de stocker les informations dans la base de données (2pts).
    1. i.      Le programme doit vérifier l’existence d’un enregistrement et renvoyer un message utilisateur dans le cas contraire.
    2. ii.      Un combo box qui charge automatiquement les Segements.
  2. Concevoir un deuxième formulaire qui permet la mise à jour des enregistrements et faire les programmes correspondants (Suppression, Modification) (2pts).
  3. Concevoir un troisième formulaire qui permet d’afficher les informations des Postes par Salle (2pts).
  4. Concevoir un quatrième formulaire qui permet d’afficher les informations des logiciels installés sur un poste choisi dans le troisième formulaire (2pts).
  5. Concevoir un cinquième formulaire qui sert de menu pour appeler les différents formulaires (1pt).
  6. Créer un état qui liste toutes les Salles et leurs Postes (3pts).
  7. Créer un état qui liste tous les postes et les logiciels qui y sont installés pour une salle bien définie (3pts).

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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
Imports System.Data.SqlClient
Public Class Form5
    Inherits System.Windows.Forms.Form
    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If conn.State = ConnectionState.Open Then
            conn.Close()
            conn.Open()
        Else
            conn.Open()
        End If

        cmd = New SqlCommand
        cmd.CommandText = "select N_POSTE from POSTE"
        cmd.Connection = conn
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader
        While dr.Read()
            numero.Items.Add(dr("N_POSTE"))
        End While
        dr.Close()

        cmd = New SqlCommand
        cmd.CommandText = "select * from LOGICIEL"
        cmd.Connection = conn
        da = New SqlDataAdapter(cmd)
        da.Fill(ds, "LOGICIEL")
    End Sub

    Private Sub afficher_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles afficher.Click
        ds.Clear()
        Try
            cmd = New SqlCommand

            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "logiciels"
            cmd.Connection = conn

            cmd.Parameters.Add("@post", SqlDbType.VarChar, 7)
            cmd.Parameters(0).Value = numero.Text

            da = New SqlDataAdapter(cmd)
            da.Fill(ds, "logiciels")
            DataGrid1.DataSource = ds.Tables("logiciels")

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub
End Class
------------------------------------------------------------------------------

Imports System.Data.SqlClient
Public Class Form4
    Inherits System.Windows.Forms.Form

Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If conn.State = ConnectionState.Open Then
            conn.Close()
            conn.Open()
        Else
            conn.Open()
        End If

        cmd = New SqlCommand
        cmd.CommandText = "select N_SALLE from SALLE"
        cmd.Connection = conn
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader
        While dr.Read()
            numero.Items.Add(dr("N_SALLE"))
        End While
        dr.Close()
    End Sub

    Private Sub afficher_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles afficher.Click
        ds.Clear()
        Try
            cmd = New SqlCommand
            cmd.CommandText = "select * from POSTE where N_SALLE = '" & numero.Text & "'"
            cmd.Connection = conn

            da = New SqlDataAdapter(cmd)
            da.Fill(ds, "POSTE")
            DataGrid1.DataSource = ds.Tables("POSTE")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub


End Class
-----------------------------------------------------------------------------
Imports System.Data.SqlClient
Public Class Form3
    Inherits System.Windows.Forms.Form


    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If conn.State = ConnectionState.Open Then
            conn.Close()
            conn.Open()
        Else
            conn.Open()
        End If

        cmd = New SqlCommand
        cmd.CommandText = "select N_SEGMENT from SEGMENT"
        cmd.Connection = conn
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader
        While dr.Read()
            numero.Items.Add(dr("N_SEGMENT"))
        End While
        dr.Close()

        cmd = New SqlCommand
        cmd.CommandText = "select * from SALLE"
        cmd.Connection = conn
        da = New SqlDataAdapter(cmd)
        da.Fill(ds, "SALLE")

    End Sub

    Private Sub ajouter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ajouter.Click

        Try
            ds.Tables("SALLE").Constraints.Add("pk1", ds.Tables("SALLE").Columns("N_SALLE"), True)
            row = ds.Tables("SALLE").NewRow
            row.Item(0) = TextBox1.Text
            row.Item(1) = TextBox2.Text
            row.Item(2) = 0
            row.Item(3) = numero.SelectedItem

            ds.Tables("SALLE").Rows.Add(row)
            ocbuilder = New SqlCommandBuilder(da)
            da.Update(ds, "SALLE")
            ds.Clear()
            da.Fill(ds, "SALLE")
            MessageBox.Show("enregistrement effectué...", "Enregistrer", MessageBoxButtons.OK)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try



    End Sub

End Class
----------------------------------------------------------------------------

Imports System.Data.SqlClient
Public Class Etat_postes
    Inherits System.Windows.Forms.Form
Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load
        cmd = New SqlCommand
        cmd.CommandText = "select N_SALLE from SALLE"
        cmd.Connection = conn
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader
        While dr.Read()
            ComboBox1.Items.Add(dr("N_SALLE"))
        End While
        dr.Close()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim etat As New Etat_PosteLogiciel
        CrystalReportViewer1.ReportSource = etat
        CrystalReportViewer1.SelectionFormula = "{SALLE.N_SALLE}='" & ComboBox1.Text & "'"
    End Sub
End Class
-----------------------------------------------------------------------------

Public Class Etat_sallePost
    Inherits System.Windows.Forms.Form

    Private Sub Etat_sallePost_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim etat As New Etat_Salles
        CrystalReportViewer1.ReportSource = etat
    End Sub
End Class
-----------------------------------------------------------------------------
Imports System.Data.SqlClient
Public Class Form2
    Inherits System.Windows.Forms.Form
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If conn.State = ConnectionState.Open Then
            conn.Close()
            conn.Open()
        Else
            conn.Open()
        End If

        cmd = New SqlCommand
        cmd.CommandText = "select N_SALLE from SALLE"
        cmd.Connection = conn
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader
        While dr.Read()
            numero.Items.Add(dr("N_SALLE"))
        End While
        dr.Close()

        cmd = New SqlCommand
        cmd.CommandText = "select N_SEGMENT from SEGMENT"
        cmd.Connection = conn
        Dim dr1 As SqlDataReader
        dr1 = cmd.ExecuteReader
        While dr1.Read()
            ComboBox1.Items.Add(dr1("N_SEGMENT"))
        End While
        dr1.Close()

        cmd = New SqlCommand
        cmd.CommandText = "select * from SALLE"
        cmd.Connection = conn
        da = New SqlDataAdapter(cmd)
        da.Fill(ds, "SALLE")
    End Sub



    Private Sub modifier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modifier.Click
        ds.Clear()
        cmd = New SqlCommand
        cmd.CommandText = "select * from SALLE"
        cmd.Connection = conn
        da = New SqlDataAdapter(cmd)
        da.Fill(ds, "SALLE")
        For j = 0 To ds.Tables("SALLE").Rows.Count - 1
            If ds.Tables("SALLE").Rows(j).Item(0) = numero.Text Then
                ds.Tables("SALLE").Rows(j).Item(1) = TextBox2.Text
                ds.Tables("SALLE").Rows(j).Item(2) = TextBox3.Text
                ds.Tables("SALLE").Rows(j).Item(3) = ComboBox1.Text

            End If
        Next
        Try
            Dim ocbuilder As New SqlCommandBuilder(da)
            da.Update(ds, "SALLE")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        MessageBox.Show("modification effectuée", "Modifier", MessageBoxButtons.OK)
    End Sub



    Private Sub suprimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles suprimer.Click
        Dim var As String
        var = MessageBox.Show("voulez vous suprimer cette enregistrement", "Supprimer", MessageBoxButtons.YesNo)
        If var = vbYes Then
            ds.Tables("SALLE").Rows(i).Delete()
            Dim ocbuilder As New SqlCommandBuilder(da)
            da.Update(ds, "SALLE")
            MessageBox.Show("suppression effectuée", "Supprimer", MessageBoxButtons.OK)
        ElseIf var = vbNo Then
            MessageBox.Show("suppression annulée", "Supprimer", MessageBoxButtons.OK)
        End If

    End Sub

    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click

    End Sub

    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click

    End Sub

    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

    End Sub

    Private Sub numero_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles numero.SelectedIndexChanged

    End Sub

    Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

    End Sub
End Class
-----------------------------------------------------------------------------
Imports System.Data.SqlClient
Module Module1
    Public strconn As String = "data source='.'; initial catalog=V5_2007; integrated security=true"
    Public conn As New SqlConnection(strconn)
    Public cmd As SqlCommand
    Public da As SqlDataAdapter
    Public ds As New DataSet
    Public row As DataRow
    Public ocbuilder As SqlCommandBuilder
    Public j As Integer
    Public i As Integer = 0
End Module
-----------------------------------------------------------------------------
Imports System.Data.SqlClient
Public Class Form1
    Inherits System.Windows.Forms.Form


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If conn.State = ConnectionState.Open Then
            conn.Close()
            conn.Open()
        Else
            conn.Open()
        End If


    End Sub

    Private Sub ajouter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


    End Sub

    Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
        Dim frm As New Form2
        frm.Show()
    End Sub



    Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
        Dim frm As New Form4
        frm.Show()
    End Sub

    Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click
        Dim frm As New Form5
        frm.Show()
    End Sub

    Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
        Dim frm As New Etat_sallePost
        frm.Show()
    End Sub

    Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
        Dim frm As New Form3
        frm.Show()

    End Sub

    Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.Click
        Dim frm As New Etat_postes
        frm.Show()
    End Sub

    Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.Click
        Dim frm As New Apropos
        frm.Show()
    End Sub
End Class

Exercice VB.Net: Transparence

Créer le code vb ui permet de réaliser l'interface suivante:

Le Principe c'est lorsque l'utilisateur clique sur une image elle s’affiche au milieu du Formulaire et en cliquant sur l(image du petit poussin la Forme devient transparente;

ExerciceVB-id2107 


 

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
Imports System.Drawing.Imaging

Public Class frm_main

    Dim valeur = 1
    Dim valeur2 = 0
    Dim mem As Bitmap
    Dim actu As Bitmap

    Private Sub PictureBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.Click
        actu = sender.Image
        fusion()
        mem = sender.Image
    End Sub

    Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
        actu = sender.Image
        fusion()
        mem = sender.Image
    End Sub

    Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
        actu = sender.Image
        fusion()
        mem = sender.Image
    End Sub

    Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click
        actu = sender.Image
        fusion()
        mem = sender.Image
    End Sub

    Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click
        actu = sender.Image
        fusion()
        mem = sender.Image
    End Sub

    Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click
        actu = sender.Image
        fusion()
        mem = sender.Image
    End Sub

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
        actu = sender.Image
        fusion()
        mem = sender.Image
    End Sub


    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

        If actu Is Nothing And mem Is Nothing Then Exit Sub
        If Not actu Is Nothing And mem Is Nothing Then mem = actu

        Dim bitmap As New Bitmap(actu)
        Dim bitmap1 As New Bitmap(mem)

        Dim matrixItems As Single()() = { _
           New Single() {1, 0, 0, 0, 0}, _
           New Single() {0, 1, 0, 0, 0}, _
           New Single() {0, 0, 1, 0, 0}, _
           New Single() {0, 0, 0, valeur, 0}, _
           New Single() {0, 0, 0, 0, 1}}

        Dim matrixItems1 As Single()() = { _
           New Single() {1, 0, 0, 0, 0}, _
           New Single() {0, 1, 0, 0, 0}, _
           New Single() {0, 0, 1, 0, 0}, _
           New Single() {0, 0, 0, valeur2, 0}, _
           New Single() {0, 0, 0, 0, 1}}

        Dim colorMatrix As New ColorMatrix(matrixItems)
        Dim imageAtt As New ImageAttributes()
        imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap)

        Dim colorMatrix1 As New ColorMatrix(matrixItems1)
        Dim imageAtt1 As New ImageAttributes()
        imageAtt1.SetColorMatrix(colorMatrix1, ColorMatrixFlag.Default, ColorAdjustType.Bitmap)

        Dim iWidth1 As Integer = sender.Width
        Dim iHeight1 As Integer = sender.Height
        e.Graphics.DrawImage(bitmap1, New Rectangle(0, 0, iWidth1, iHeight1), 0.0F, 0.0F, bitmap1.Width, bitmap1.Height, GraphicsUnit.Pixel, imageAtt1)

        Dim iWidth As Integer = sender.Width
        Dim iHeight As Integer = sender.Height
        e.Graphics.DrawImage(bitmap, New Rectangle(0, 0, iWidth, iHeight), 0.0F, 0.0F, bitmap.Width, bitmap.Width, GraphicsUnit.Pixel, imageAtt)

        e.Dispose()
        bitmap.Dispose()
        bitmap = Nothing
        bitmap1.Dispose()
        bitmap1 = Nothing
        matrixItems = Nothing
        matrixItems1 = Nothing
        imageAtt.Dispose()
        imageAtt = Nothing
        imageAtt1.Dispose()
        imageAtt1 = Nothing
        PictureBox1.CreateGraphics()

    End Sub

    Private Sub fusion()

        PictureBox1.Visible = True
        If mem Is Nothing Then
            valeur2 = 0
            For x = 0 To 200
                valeur = x / 200
                PictureBox1.Refresh()
            Next

        ElseIf mem Is actu Then
            Exit Sub
        Else

            For x = 0 To 200
                valeur2 = 1 - (x / 200)
                valeur = x / 200
                PictureBox1.Refresh()
            Next
        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Active le double buffer pour fluidité image
        Me.DoubleBuffered = True
        PictureBox1.Visible = False

    End Sub

    Private Sub PictureBox9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox9.Click
        TransparencyKey = BackColor
    End Sub
End Class

 

  • Contactez-nous
  • A propos de nous
  • On recrute
  • Rechercher dans le site
  • Politique de confidentialité
  • Droit d'auteur/Copyright
  • Conditions générales d'utilisation
  • Plan du site
  • Accueil
  • Blog
  • Finance et compta.
  • Formations Pro.
  • Logiciels & Apps
  • Organisation
  • Cours informatique
  • Aide à la rédaction
  • Etudes et Metiers
  • Science et Tech
  • Titans de la Tech
id 11354 02