Exercice VB: Saisie et Calcule

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).

1234567891011121314151617181920212223242526272829303132333435363738394041424.Module Module1Dim i, n, max, Pmax As IntegerSub Main()Console.Write("Entrez le nombre numéro 1 : ")n = Console.ReadLinemax = nPmax = 1For i = 2 To 20Console.Write("Entrez le nombre numéro " & i & " : ")n = Console.ReadLineIf n > max Thenmax = nPmax = iEnd IfNextConsole.WriteLine("Le plus grand nombre est : " & max)Console.WriteLine("Sa position est : " & Pmax)Console.ReadLine()End SubEnd Module5.Module Module1Dim i, a, b, Cpt As IntegerSub Main()Console.Write("Entrez un chiffre : ")a = Console.ReadLineCpt = 0For i = 1 To 20Console.Write("Entrez un chiffre : ")b = Console.ReadLineIf a = b ThenCpt = Cpt + 1End IfNextConsole.WriteLine("Le nombre de fois de saisie de " & a & " est :" & Cpt)Console.ReadLine()End SubEnd 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!+ ………………

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263641.Module Module1Dim i, e, X, P, F As DoubleSub Main()Console.Write("Entrez la valeur de x : ")X = Console.ReadLineConsole.Write("Entrez la puissance : ")P = Console.ReadLinee = 1F = 1For i = 1 To PF = F * ie = e + ((X ^ i) / F)NextConsole.Write("e est : " & e)Console.ReadLine()End SubEnd Module2.Module Module1Dim i, e, X, EPS, F As DoubleSub Main()Console.Write("Entrez la valeur de x : ")X = Console.ReadLineConsole.Write("Entrez la valeur d'EPS : ")EPS = Console.ReadLinee = 1F = 1i = 1DoF = F * ie = e + ((X ^ i) / F)i += 1Loop Until (e )Console.Write("e est : " & e)Console.ReadLine()End SubEnd Module3.Module Module1Dim i, X, F, P, S, L, j, k As DoubleSub Main()Console.Write("Entrez la valeur de X : ")X = Console.ReadLineConsole.Write("Entrez la puissance : ")P = Console.ReadLineS = 0For i = 0 To PF = 1L = 1For j = 1 To (4 * i + 1)F = F * jNextFor k = 1 To (4 * i + 3)L = L * kNextS = S + ((X ^ (4 * i + 1)) / F) - ((X ^ (4 * i + 3)) / L)NextConsole.Write("S est : " & S)Console.ReadLine()End SubEnd 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

\

1234567891011121314151617181920212223242526272829303132331.Module Module1Dim i, S, N As DoubleSub Main()Console.Write("Entrez la valeur de N : ")N = Console.ReadLineS = 1For i = 1 To NS = (3 * S + 5)NextConsole.Write("S est : " & S)Console.ReadLine()End SubEnd Module2.Module Module1Dim i, N, X, Y, S As DoubleSub Main()X = 1 / 2Y = 1Console.Write("Entrez la valeur de N : ")N = Console.ReadLineS = 0For i = 1 To NS = (3 * Y) - (5 * X)X = YY = SNextConsole.Write("S est : " & S)Console.ReadLine()End SubEnd 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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116Imports System.CollectionsModule 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 SubEnd 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 :

5

1

7

8

4

-6

12

  1. rassembler deux Tableaux
1234567891011121314151617181920212223242526272829303132333435363738' directivesOption Strict OnOption Explicit On' importsImports System' classe de testModule 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 SubEnd 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:



123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246Public 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 SubEnd 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 SubEnd 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).
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369Imports System.Data.SqlClientPublic 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 SubEnd Class------------------------------------------------------------------------------Imports System.Data.SqlClientPublic Class Form4 Inherits System.Windows.Forms.FormPrivate 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 SubEnd Class-----------------------------------------------------------------------------Imports System.Data.SqlClientPublic 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 SubEnd Class----------------------------------------------------------------------------Imports System.Data.SqlClientPublic Class Etat_postes Inherits System.Windows.Forms.FormPrivate 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 SubEnd 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 SubEnd Class-----------------------------------------------------------------------------Imports System.Data.SqlClientPublic 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 SubEnd Class-----------------------------------------------------------------------------Imports System.Data.SqlClientModule 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 = 0End Module-----------------------------------------------------------------------------Imports System.Data.SqlClientPublic 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 SubEnd 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;

 

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139Imports System.Drawing.ImagingPublic 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 SubEnd Class
Article publié le 02 Janvier 2012 Mise à jour le Vendredi, 16 Décembre 2022 23:05 par Babachekhe Mohamed