Exercice VB: Fonctions et Procédures

Objectif:
  • Travailler avec les Fonctions et les Procédures 
Travail à Faire:
  1. Ecrire le code en VB qui demande à l’utilisateur d’entrer deux nombre et ensuite réalise les Fonctions et procédures suivantes
  • La somme
  • Le produit
  • La soustraction
  • La division
  1. Ajouter un Menu de Choix
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576Module fonction Public A, B As Double Sub menu() Console.WriteLine("1.saisie") Console.WriteLine("2.somme") Console.WriteLine("3.produit") Console.WriteLine("4.soustraction") Console.WriteLine("5.soustraction") Console.WriteLine("6.division") Console.WriteLine("7.Quitter") 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 saisie() Case 2 somme() Case 3 produit() Case 4 soustraction() Case 5 soustraction() Case 6 division() Case 7 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 saisie() Console.WriteLine("saisir la valeure de A") A = Console.ReadLine() Console.WriteLine("saisir la valeure de B") B = Console.ReadLine() End Sub Sub somme() Dim S As Double S = A + B Console.WriteLine("la somme est =" & A + B) Console.ReadLine() End Sub Sub produit() Dim P As Double P = A * B Console.WriteLine("le produit est =" & A * B) Console.ReadLine() End Sub Sub soustraction() Dim C As Double C = A - B Console.WriteLine("la resultat est =" & A - B) Console.ReadLine() End Sub Sub division() Dim D As Double If B 0 Then D = A / B Console.WriteLine("la division est =" & A / B) Console.ReadLine() Else Console.WriteLine("erreure") Console.ReadLine() End If End SubEnd Module

Exercice Visual Basic : Examen Passage 2007 TSDI Variante 4 POO

Un Individu est décrit par ses données membres privées :

  • un numéro de CIN
  • Un nom
  • Un prénom
  • Une adresse

1. Définir une classe Individu avec ses données membres et une méthode Affichage () qui affiche les informations de chaque objet créer a partir de cette classe. (2 points)

2. Créer  une classe de test pour dérouler un scénario activant des objets particuliers de cette classe : créer deux individus et afficher leurs informations. (2 points)

Exemple 

Objet 1 :                                                           Objet 2 :

CIN        : BH14501                                           CIN        : FG 254170

Nom       : Maraji                                                Nom       : Alaoui

Prénom   : Ahmed                                               Prénom   : Ilham

Adresse   : 59 rue tata Agadir                             Adresse   : 103 Place la gironde Casablanca

3. Créer un package pour faciliter l'accessibilité des classes. (1 point)

On dérive la classe Individu déjà vue par une classe Formateur

En plus des données membres Individu, la classe Formateur a comme données membres privées :

Masse horaire effective

Heure supplémentaire

Taux horaire effectif

Taux horaire supplémentaire

La méthode CalculSalaire () intègre un mode de calcul comme suit :

CalculSalaire = (Masse horaire effectif* taux horaire effectif)   + (Heure supplémentaire* taux horaire supplémentaire)

4. Construire la classe Formateur qui hérite de la classe Individu (2 points)

5. Au niveau de la Classe de Test : (3 points)

-          Prévoir deux Formateurs et les instancier avec les constructeurs adéquats.

-          Les afficher notamment CalculSalaire ( ).

On dérive la classe Individu déjà vue par une classe Stagiaire

En plus des données membres Individu, la classe Stagiaire a comme données membres privées:

Filière

Moyenne générale

6. Construire la classe Stagiaire qui hérite de la classe Individu (1.5 point)

7. Au niveau de la Classe de Test : (2 points)

Prévoir deux Stagiaires et les instancier avec les constructeurs adéquats.

8. On souhaite  Enregistrer des objets Stagiaires dans un fichier. (1.5 point)

9. Ecrire des procédures de mise a jour de ce fichier :

3.1       Ajout (1 point)

3.2       Modification (1 point)

3.3       Suppression(1 point)

10. Prévoir une procédure qui permet de recopier les enregistrements du fichier vers un Vecteur. (2.5 points)

11. afficher à partir du vecteur les Stagiaires ayant une moyenne >=10. (2.5 points)

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252Public Class Formateur Inherits Individu Private MassH As Double Private Heur_Sup As Double Private Taux_H_Effec As Double Private taux_H_Sup As Double Property _MassH() As Double Get Return MassH End Get Set(ByVal value As Double) MassH = value End Set End Property Property _Heur_Sup() As Double Get Return Heur_Sup End Get Set(ByVal value As Double) Heur_Sup = value End Set End Property Property _Taux_h_effec() As Double Get Return Taux_H_Effec End Get Set(ByVal value As Double) Taux_H_Effec = value End Set End Property Property _taux_H_Sup() As Double Get Return taux_H_Sup End Get Set(ByVal value As Double) taux_H_Sup = value End Set End Property Sub New() End Sub Public Sub New(ByVal N As String, ByVal No As String, ByVal P As String, ByVal A As String, ByVal M As Double, ByVal HS As Double, ByVal THE As Double, ByVal THS As Double) MyBase.New(N, No, P, A) _MassH = M _Heur_Sup = HS _Taux_h_effec = THE _taux_H_Sup = THS End Sub Public Sub New(ByVal M As Double, ByVal HS As Double, ByVal THE As Double, ByVal THS As Double) _MassH = M _Heur_Sup = HS _Taux_h_effec = THE _taux_H_Sup = THS End Sub Sub CalculSalaire() Console.WriteLine((MassH * Taux_H_Effec) + (Heur_Sup / taux_H_Sup)) End Sub Public Overrides Sub afficher() MyBase.afficher() Console.WriteLine(MassH & vbTab & Heur_Sup & vbTab & Taux_H_Effec & vbTab & taux_H_Sup) End SubEnd Class-------------------------------------------------------------------------------------------------Public Class Individu Private NumCin As String Private nom As String Private Prénom As String Private adresse As String Property _NumCin() As String Get Return NumCin End Get Set(ByVal value As String) NumCin = 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 _Adresse() As String Get Return adresse End Get Set(ByVal value As String) adresse = value End Set End Property Sub New() End Sub Sub New(ByVal Nu As String, ByVal No As String, ByVal P As String, ByVal A As String) _NumCin = Nu _nom = No _prénom = P _Adresse = A End Sub Public Overridable Sub afficher() Console.WriteLine(_NumCin & vbTab & _nom & vbTab & _prénom & vbTab & _Adresse) End SubEnd Class-------------------------------------------------------------------------------------------------------Module Module1 Dim st As New ArrayList Sub Main() Dim x As New test Dim k = New Stagiaire("AA123", "Alami", "Fadwa", "hay nahda", "TDI", 19) st.Add(k) FileOpen(1, "naziha.txt", OpenMode.Output) Dim i As Integer For i = 0 To st.Count - 1 PrintLine(1, k._NumCin & "/" & k._nom & "/" & k._prénom & "/" & k._Adresse & "/" & k._Filière & "/" & k._Moy_G) Next FileClose() Dim num, nom, prénom, adresse, filière As String Dim moye As Double Console.WriteLine("saisire le numCin du stagiairz") num = Console.ReadLine Console.WriteLine("saisire le nom du stagiaire") nom = Console.ReadLine Console.WriteLine("saisire le prénom du stagiaire") prénom = Console.ReadLine Console.WriteLine("saisire l'adresse du stagiaire") adresse = Console.ReadLine Console.WriteLine("saisire le filière du stagiaire") filière = Console.ReadLine Console.WriteLine("saisire la moyenne du stagiaire") moye = Console.ReadLine ajout(num, nom, prénom, adresse, filière, moye) copier() End Sub Sub ajout(ByVal num As String, ByVal nom As String, ByVal prénom As String, ByVal adresse As String, ByVal filière As String, ByVal moye As Double) Dim stag = New Stagiaire(num, nom, prénom, adresse, filière, moye) st.Add(stag) FileOpen(1, "naziha.txt", OpenMode.Append) Dim i As Integer For i = 0 To st.Count - 2 PrintLine(1, stag._NumCin & "/" & stag._nom & "/" & stag._prénom & "/" & stag._Adresse & "/" & stag._Filière & "/" & stag._Moy_G) Next FileClose() End Sub Sub copier() Dim R(), lin As String FileOpen(1, "naziha.txt", OpenMode.Input) While Not EOF(1) lin = LineInput(1) R = Split(lin, "/") FileClose(1) End While For i = 0 To R.GetUpperBound(0) Console.WriteLine(R(i) & vbTab) Next End SubEnd Module-----------------------------------------------------------------------------Public Class Stagiaire Inherits Individu Private Filière As String Private Moy_G As Double Property _Filière() As String Get Return Filière End Get Set(ByVal value As String) Filière = value End Set End Property Property _Moy_G() As Double Get Return Moy_G End Get Set(ByVal value As Double) Moy_G = value End Set End Property Public Sub New() End Sub Public Sub New(ByVal C As String, ByVal n As String, ByVal P As String, ByVal A As String, ByVal F As String, ByVal MG As Double) MyBase.New(C, n, P, A) _Filière = F _Moy_G = MG End Sub Public Overrides Sub afficher() MyBase.afficher() Console.WriteLine(_Filière & vbTab & _Moy_G) End SubEnd Class-----------------------------------------------------------------------------Public Class test Public Sub New() Console.WriteLine("********************* [Programme de teste] *********************") Console.WriteLine() Console.WriteLine("----------------------------------------------------------------") Console.WriteLine(" ---INDIVIDU---") Console.WriteLine() Dim individu1 As New Individu("AA192", "plplpl", "pppp", "adadadadad") Dim individu2 As New Individu("AA111", "aaaaa", "kkkkk", "rabat") individu1.afficher() Console.WriteLine() individu2.afficher() Console.WriteLine() Console.WriteLine() Console.WriteLine("----------------------------------------------------------------") Console.WriteLine("") Console.WriteLine(" ----FORMATEURS---") Console.WriteLine() Dim formateur1 As New Formateur(20, 40, 70, 33) Dim formateur2 As New Formateur(70, 22, 80, 65) Console.WriteLine("Salaire du premier formatteur" & vbTab & vbTab) formateur1.CalculSalaire() Console.WriteLine("Salaire du deuxième formatteur" & vbTab & vbTab) formateur2.CalculSalaire() Console.WriteLine() Console.WriteLine() Console.WriteLine("----------------------------------------------------------------") Console.WriteLine() Console.WriteLine(" ----STAGIAIRE----") Console.WriteLine() Dim stagiaire1 As New Stagiaire("AA190", "okokok", "mmmmm", "kkkkkkkkkk", "TDI", 15.75) Dim stagiaire2 As New Stagiaire("BB198", "kkki", "nnnnn", "llllllllllllll", "TDI", 19) stagiaire1.afficher() Console.WriteLine() stagiaire2.afficher() Console.WriteLine() Console.WriteLine() Console.WriteLine("------------------------------------------------------------------") Console.ReadLine() End SubEnd Class

Exercice Visual Basic : Fiche Client

Ecrire le code VB qui permet de réaliser les Interfaces suivantes:



123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112Public Class Form1 Dim N As Boolean Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.Close() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click DateTimePicker1.Value = Now txtAdresse.Clear() txtcode.Clear() txtNom.Clear() TxtPrénom.Clear() txtville.Clear() txtNom.Focus() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ErreurNom() ErreurPrénom() ErreurCode() If Not N Then Nom = txtNom.Text.Trim Prénom = TxtPrénom.Text.Trim Adresse = txtAdresse.Text.Trim Code = txtcode.Text.Trim Ville = txtville.Text.Trim Form2.Show() Me.Close() Else MsgBox("Veuillez vérifier la validité de vos données") End If End Sub Sub ErreurNom() If txtNom.Text = "" Then ErrorProvider1.SetError(txtNom, "Vous devez Saisir le Nom") ToolStripStatusLabel1.Text = "Erreur de Saisies" N = True Exit Sub End If For i = 0 To Len(txtNom.Text.Trim) - 1 If Not Char.IsLetter(txtNom.Text(i)) Then ErrorProvider1.SetError(txtNom, "Erreur de Saisies du Nom") ToolStripStatusLabel1.Text = "Erreur de Saisies" N = True Exit Sub End If Next ErrorProvider1.Clear() N = False End Sub Sub ErreurPrénom() If TxtPrénom.Text = "" Then ErrorProvider2.SetError(TxtPrénom, "Vous devez Saisir le Prénom") ToolStripStatusLabel1.Text = "Erreur de Saisies" N = True Exit Sub End If For i = 0 To Len(TxtPrénom.Text.Trim) - 1 If Not Char.IsLetter(TxtPrénom.Text(i)) Then ErrorProvider2.SetError(TxtPrénom, "Erreur de Saisies du Prénom") ToolStripStatusLabel1.Text = "Erreur de Saisies" N = True Exit Sub End If Next ErrorProvider2.Clear() N = False End Sub Sub ErreurCode() Dim L As Integer = Len(txtcode.Text.Trim) If L Then For i = 0 To Len(txtcode.Text.Trim) - 1 If Not Char.IsDigit(txtcode.Text(i)) Then ErrorProvider3.SetError(txtcode, "Code Postale doit comporter 5 chiffres") ToolStripStatusLabel1.Text = "Erreur de Saisies" N = True Exit Sub End If Next Else ErrorProvider3.SetError(txtcode, "Code Postale doit comporter 5 chiffres") ToolStripStatusLabel1.Text = "Erreur de Saisies" txtcode.Text.Remove(L - 5) N = True Exit Sub End If ErrorProvider3.Clear() N = False End SubEnd Class-----------------------------------------------------------------------------Public Class Form2 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Form1.Show() Me.Close() End Sub Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lblNom.Text = Prénom & " " & Nom lbladresse1.Text = Adresse lbladresse2.Text = Code & " " & Ville End SubEnd Class-----------------------------------------------------------------------------Module Module1 Public Nom, Prénom, Adresse, Code, Ville As StringEnd Module

Exercice Visual Basic : Gestion Commerciale

Ecrire le code VB qui permet de réaliser l'interface suivante:

Avant de commancer la programmation il faut créer une Base de Donnée avec les champs cités dans l'interface



1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283Imports System.Data.SqlClientPublic Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try tecli() ds.Clear() cn.Open() da = New SqlDataAdapter("select * from Client", cn) da.TableMappings.Add("Client", "Client") da.Fill(ds, "Client") bind.DataSource = ds.Tables("Client") DataGridView1.DataSource = bind cn.Close() Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click If MsgBox("Voulez vous vraimment quitter l'application", MsgBoxStyle.YesNo) = 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 Try da.InsertCommand = New SqlCommand("insert into Client (NumCli, NomCli, AdrCli, VilCli, TelCli) values(@a, @b, @c, @d, @e)", cn) da.InsertCommand.Parameters.Add("@a", SqlDbType.Int, "NumCli") da.InsertCommand.Parameters.Add("@b", SqlDbType.Char, "NomCli") da.InsertCommand.Parameters.Add("@c", SqlDbType.VarChar, "AdrCli") da.InsertCommand.Parameters.Add("@d", SqlDbType.Char, "VilCli") da.InsertCommand.Parameters.Add("@e", SqlDbType.Text, "TelCli") dr = dt.NewRow dr("NumCli") = txtnum.Text dr("NomCli") = txtnom.Text dr("AdrCli") = txtad.Text dr("VilCli") = txtvil.Text dr("TelCli") = txttel.Text Try dt.PrimaryKey = New DataColumn() {dt.Columns.Item(0)} dt.Rows.Add(dr) Catch ex As Exception MsgBox("Ce client est déjà dans la liste") Exit Sub End Try da.Update(ds, "Client") MsgBox("Ajout avec succes") Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub txtvil_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtvil.TextChanged End SubEnd Class-------------------------------------------------------------------------------Imports System.Data.SqlClientImports System.Data.SqlClient.SqlDataAdapterImports System.DataModule esseyer Public pos As Integer Public cn As New SqlConnection("datasource=PC-DE-COMPAQ\SQLEXPRESS; initial catalog=GESTION_COMMERCIALE; integrated security=true") Public cmd As SqlCommand Public da As SqlDataAdapter Public ds As New DataSet Public dt As New DataTable Public dr As DataRow Public bind As New BindingSource Public dtr As SqlDataReader Sub tecli() da = New SqlDataAdapter("select * from Client", cn) da.Fill(ds, "Client") dt = ds.Tables("Client") dt.PrimaryKey = New DataColumn() {dt.Columns.Item(0)} End SubEnd Module

Exercice Visual Basic : Gestion Magasin

Afin de faciliter la gestion de notre magasin, on souhaite développer une petite application qui répond aux fonctionnalités désirés :

  1. Créer une Interface de Mise à Jour des Articles
    1. Ajouter un Article (le contrôle de saisie est obligatoire et l’article ne doit pas être enregistré deux fois.)
    2. Modifier un article
    3. Rechercher un article
    4. Supprimer un article

Interface Graphique:

 




12345678910111213141516171819202122232425262728293031323334353637383940414243Public Class Form1 Public num As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click With art .numA = Textnum.Text .nomA = Textnom.Text .prixA = TextprixA.Text .prixV = TextprixV.Text For i = 0 To col.Count - 1 art = col(i) If col(art.numA) = .numA Then MsgBox("cette article existe déjà") Exit Sub Else End If Next col.Add(art) End With End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Textnum.SelectAll() If MessageBox.Show("voulez vous vraiment modifier cette article", "information", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then col.Insert(art.numA, art) End If End SubEnd Class------------------------------------------------------------------------------Module gestion_art Structure articles Public numA As Integer Public nomA As String Public prixA As Double Public prixV As Double End Structure Public art As articles Public col As New ArrayListEnd Module

Exercice Visual Basic : Horloge

Ecrire le code VB qui permet de réaliser li'interface suivante
Le Principe c'est de créer une Horloge.



123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383Imports SystemImports System.Windows.FormsImports System.DrawingImports System.ComponentModelNamespace Composant Public Class Horloge12 Inherits Control Private t As New Timer() Private fAiguilleSec As Boolean = True '-------------------------------------------------------- Public Sub New() 'constructeur SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or _ ControlStyles.AllPaintingInWmPaint, True) AddHandler t.Tick, AddressOf Tempo t.Interval = 1000 t.Start() End Sub 'New '-------------------------------------------------------- Protected Overrides ReadOnly Property DefaultSize() As Size Get Return New Size(121, 121) End Get End Property '-------------------------------------------------------- Private Sub Tempo(ByVal myObject As [Object], ByVal myEventArgs As EventArgs) Invalidate() End Sub '-------------------------------------------------------- ("Appearance"), Description("Affiche l'aiguille des secondes."), _ DefaultValue(True)> _ Public Property AiguilleSec() As Boolean Get Return fAiguilleSec End Get Set(ByVal value As Boolean) fAiguilleSec = value Invalidate() End Set End Property '-------------------------------------------------------- Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim blackPen As New Pen(Color.Black, 1) Dim rect As New Rectangle(2, 2, 118, 118) e.Graphics.DrawEllipse(blackPen, rect) Dim d As DateTime = DateTime.Now Dim n, z, u, x0, y0, x1, y1, x2, y2, x3, y3 As Single Dim aigPoints(3) As PointF '----------------------- ' Aiguille des Secondes (si propriété AiguilleSec à true) If AiguilleSec Then n = d.Second * 200 / 60 z = n / 100 * 3.14159F u = (n + 50) / 100 * 3.14159F x0 = CSng(Math.Sin(z)) * 50 y0 = CSng(-Math.Cos(z)) * 50 x1 = CSng(-Math.Sin(z)) * 10 y1 = CSng(Math.Cos(z)) * 10 x2 = CSng(Math.Sin(u)) * 2 y2 = CSng(-Math.Cos(u)) * 2 x3 = CSng(-Math.Sin(u)) * 2 y3 = CSng(Math.Cos(u)) * 2 Dim redBrush As New SolidBrush(Color.Red) aigPoints(0).X = x1 + 60 aigPoints(0).Y = y1 + 60 aigPoints(1).X = x2 + 60 aigPoints(1).Y = y2 + 60 aigPoints(2).X = x0 + 60 aigPoints(2).Y = y0 + 60 aigPoints(3).X = x3 + 60 aigPoints(3).Y = y3 + 60 e.Graphics.FillPolygon(redBrush, aigPoints) e.Graphics.DrawPolygon(blackPen, aigPoints) redBrush.Dispose() End If '----------------------- ' Aiguille des Minutes n = d.Minute * 200 / 60 z = n / 100 * 3.14159F u = (n + 50) / 100 * 3.14159F x0 = CSng(Math.Sin(z)) * 50 y0 = CSng(-Math.Cos(z)) * 50 x1 = CSng(-Math.Sin(z)) * 10 y1 = CSng(Math.Cos(z)) * 10 x2 = CSng(Math.Sin(u)) * 4 y2 = CSng(-Math.Cos(u)) * 4 x3 = CSng(-Math.Sin(u)) * 4 y3 = CSng(Math.Cos(u)) * 4 Dim limeBrush As New SolidBrush(Color.Lime) aigPoints(0).X = x1 + 60 aigPoints(0).Y = y1 + 60 aigPoints(1).X = x2 + 60 aigPoints(1).Y = y2 + 60 aigPoints(2).X = x0 + 60 aigPoints(2).Y = y0 + 60 aigPoints(3).X = x3 + 60 aigPoints(3).Y = y3 + 60 e.Graphics.FillPolygon(limeBrush, aigPoints) e.Graphics.DrawPolygon(blackPen, aigPoints) limeBrush.Dispose() '----------------------- ' Aiguille des Heures n = d.Hour * 200 / 12 + d.Minute * 200 / 60 / 12 z = n / 100 * 3.14159F u = (n + 50) / 100 * 3.14159F x0 = CSng(Math.Sin(z)) * 35 y0 = CSng(-Math.Cos(z)) * 35 x1 = CSng(-Math.Sin(z)) * 10 y1 = CSng(Math.Cos(z)) * 10 x2 = CSng(Math.Sin(u)) * 4 y2 = CSng(-Math.Cos(u)) * 4 x3 = CSng(-Math.Sin(u)) * 4 y3 = CSng(Math.Cos(u)) * 4 Dim yellowBrush As New SolidBrush(Color.Yellow) aigPoints(0).X = x1 + 60 aigPoints(0).Y = y1 + 60 aigPoints(1).X = x2 + 60 aigPoints(1).Y = y2 + 60 aigPoints(2).X = x0 + 60 aigPoints(2).Y = y0 + 60 aigPoints(3).X = x3 + 60 aigPoints(3).Y = y3 + 60 e.Graphics.FillPolygon(yellowBrush, aigPoints) e.Graphics.DrawPolygon(blackPen, aigPoints) yellowBrush.Dispose() '----------------------- ' Chiffres Dim drawFont As New Font("Arial", 8) Dim drawBrush As New SolidBrush(Color.Black) e.Graphics.DrawString("12", drawFont, drawBrush, 55, 6) e.Graphics.DrawString("6", drawFont, drawBrush, 58, 101) e.Graphics.DrawString("3", drawFont, drawBrush, 105, 53) e.Graphics.DrawString("9", drawFont, drawBrush, 8, 53) '----------------------- drawFont.Dispose() drawBrush.Dispose() blackPen.Dispose() MyBase.OnPaint(e) End Sub 'OnPaint '-------------------------------------------------------- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing And Not (t Is Nothing) Then t.Dispose() t = Nothing End If MyBase.Dispose(disposing) End Sub 'Dispose End Class 'HorlogeEnd Namespace 'Composant**********************************************************************************************Imports SystemImports System.Windows.FormsImports System.DrawingImports System.ComponentModelNamespace Composant Public Class Horloge123 Inherits Control Private t As New Timer() Private fAiguilleSec As Boolean = True '-------------------------------------------------------- Public Sub New() 'constructeur SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or _ ControlStyles.AllPaintingInWmPaint, True) AddHandler t.Tick, AddressOf Tempo t.Interval = 1000 t.Start() End Sub 'New '-------------------------------------------------------- Protected Overrides ReadOnly Property DefaultSize() As Size Get Return New Size(121, 121) End Get End Property '-------------------------------------------------------- Private Sub Tempo(ByVal myObject As [Object], ByVal myEventArgs As EventArgs) Invalidate() End Sub '-------------------------------------------------------- ("Appearance"), Description("Affiche l'aiguille des secondes."), _ DefaultValue(True)> _ Public Property AiguilleSec() As Boolean Get Return fAiguilleSec End Get Set(ByVal value As Boolean) fAiguilleSec = value Invalidate() End Set End Property '-------------------------------------------------------- Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim blackPen As New Pen(Color.Black, 1) Dim rect As New Rectangle(2, 2, 118, 118) e.Graphics.DrawEllipse(blackPen, rect) Dim d As DateTime = DateTime.Now Dim n, z, u, x0, y0, x1, y1, x2, y2, x3, y3 As Single Dim aigPoints(3) As PointF '----------------------- ' Aiguille des Secondes (si propriété AiguilleSec à true) If AiguilleSec Then n = d.Second * 200 / 60 z = n / 100 * 3.14159F u = (n + 50) / 100 * 3.14159F x0 = CSng(Math.Sin(z)) * 50 y0 = CSng(-Math.Cos(z)) * 50 x1 = CSng(-Math.Sin(z)) * 10 y1 = CSng(Math.Cos(z)) * 10 x2 = CSng(Math.Sin(u)) * 2 y2 = CSng(-Math.Cos(u)) * 2 x3 = CSng(-Math.Sin(u)) * 2 y3 = CSng(Math.Cos(u)) * 2 Dim redBrush As New SolidBrush(Color.Red) aigPoints(0).X = x1 + 60 aigPoints(0).Y = y1 + 60 aigPoints(1).X = x2 + 60 aigPoints(1).Y = y2 + 60 aigPoints(2).X = x0 + 60 aigPoints(2).Y = y0 + 60 aigPoints(3).X = x3 + 60 aigPoints(3).Y = y3 + 60 e.Graphics.FillPolygon(redBrush, aigPoints) e.Graphics.DrawPolygon(blackPen, aigPoints) redBrush.Dispose() End If '----------------------- ' Aiguille des Minutes n = d.Minute * 200 / 60 z = n / 100 * 3.14159F u = (n + 50) / 100 * 3.14159F x0 = CSng(Math.Sin(z)) * 50 y0 = CSng(-Math.Cos(z)) * 50 x1 = CSng(-Math.Sin(z)) * 10 y1 = CSng(Math.Cos(z)) * 10 x2 = CSng(Math.Sin(u)) * 4 y2 = CSng(-Math.Cos(u)) * 4 x3 = CSng(-Math.Sin(u)) * 4 y3 = CSng(Math.Cos(u)) * 4 Dim limeBrush As New SolidBrush(Color.Lime) aigPoints(0).X = x1 + 60 aigPoints(0).Y = y1 + 60 aigPoints(1).X = x2 + 60 aigPoints(1).Y = y2 + 60 aigPoints(2).X = x0 + 60 aigPoints(2).Y = y0 + 60 aigPoints(3).X = x3 + 60 aigPoints(3).Y = y3 + 60 e.Graphics.FillPolygon(limeBrush, aigPoints) e.Graphics.DrawPolygon(blackPen, aigPoints) limeBrush.Dispose() '----------------------- ' Aiguille des Heures n = d.Hour * 200 / 12 + d.Minute * 200 / 60 / 12 z = n / 100 * 3.14159F u = (n + 50) / 100 * 3.14159F x0 = CSng(Math.Sin(z)) * 35 y0 = CSng(-Math.Cos(z)) * 35 x1 = CSng(-Math.Sin(z)) * 10 y1 = CSng(Math.Cos(z)) * 10 x2 = CSng(Math.Sin(u)) * 4 y2 = CSng(-Math.Cos(u)) * 4 x3 = CSng(-Math.Sin(u)) * 4 y3 = CSng(Math.Cos(u)) * 4 Dim yellowBrush As New SolidBrush(Color.Yellow) aigPoints(0).X = x1 + 60 aigPoints(0).Y = y1 + 60 aigPoints(1).X = x2 + 60 aigPoints(1).Y = y2 + 60 aigPoints(2).X = x0 + 60 aigPoints(2).Y = y0 + 60 aigPoints(3).X = x3 + 60 aigPoints(3).Y = y3 + 60 e.Graphics.FillPolygon(yellowBrush, aigPoints) e.Graphics.DrawPolygon(blackPen, aigPoints) yellowBrush.Dispose() '----------------------- ' Chiffres Dim drawFont As New Font("Arial", 8) Dim drawBrush As New SolidBrush(Color.Black) e.Graphics.DrawString("12", drawFont, drawBrush, 55, 6) e.Graphics.DrawString("6", drawFont, drawBrush, 58, 101) e.Graphics.DrawString("3", drawFont, drawBrush, 105, 53) e.Graphics.DrawString("9", drawFont, drawBrush, 8, 53) '----------------------- drawFont.Dispose() drawBrush.Dispose() blackPen.Dispose() MyBase.OnPaint(e) End Sub 'OnPaint '-------------------------------------------------------- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing And Not (t Is Nothing) Then t.Dispose() t = Nothing End If MyBase.Dispose(disposing) End Sub 'Dispose End Class 'HorlogeEnd Namespace 'Composant

Exercice Visual Basic : Impression

Ecrire le programme qui permet de réaliser les Inerfaces suivantes:
lorsqu'on clique sur la boutton Imprimer la deuxième Forme s'affiche.

Remarque:
vous devez créer une base de données contenant les champs cités dans la première interface afin de charger la liste. 

 

 

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121Public Class Form1 Inherits System.Windows.Forms.Form Private gocnx As New ADODB.Connection Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i As Integer Dim rs As New ADODB.Recordset ' pour récupérer les fonctions de la dll Dim MySortClass As New ListViewEx.ListViewEx ListViewEx1.View = View.Details ListViewEx1.GridLines = True ' connection à la base gocnx.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\immo.mdb;Persist Security Info=True" gocnx.Open() ' pour faire moins d'enregistrements rs = gocnx.Execute("select * from immo ") 'where montant>21000") i = 1 ' permet de gagner du temps car pas de repaint durant le chargement ListViewEx1.BeginUpdate() Do While Not rs.EOF With ListViewEx1.Items.Add(CStr(i)) ' ajout des champs .SubItems.Add(CStr(rs.Fields("Noinv").Value)) ' test si le champ est null If Not IsDBNull(rs.Fields("Natinv").Value) Then .SubItems.Add(CStr(rs.Fields("Natinv").Value)) Else .SubItems.Add("") End If .SubItems.Add(CStr(rs.Fields("datesaisie").Value)) .SubItems.Add(Format(rs.Fields("duree").Value, "#0.0000")) .SubItems.Add(Format(rs.Fields("Taux").Value, "#0.0000")) .SubItems.Add(CType(rs.Fields("Type").Value, String)) .SubItems.Add(Format(rs.Fields("Montant").Value, "C")) ' je ne le fait que pour le colonne montant If CDbl(.SubItems.Item(7).Text) Then ' ceci pour que la couleur change pour la colonne .UseItemStyleForSubItems = False .SubItems.Item(7).ForeColor = ListViewEx1.CouleurNombreNegatif End If End With i = i + 1 rs.MoveNext() Loop ' ajout des entêtes et position ' inutile de dimensionner les colonne, la dll le fera ListViewEx1.Columns.Add("", 0, HorizontalAlignment.Left) ListViewEx1.Columns.Add("Code ", 0, HorizontalAlignment.Right) ListViewEx1.Columns.Add("Nature", 0, HorizontalAlignment.Left) ListViewEx1.Columns.Add("Date", 0, HorizontalAlignment.Center) ListViewEx1.Columns.Add("Durée", 0, HorizontalAlignment.Right) ListViewEx1.Columns.Add("Taux", 0, HorizontalAlignment.Right) ListViewEx1.Columns.Add("Type", 0, HorizontalAlignment.Center) ListViewEx1.Columns.Add("Montant", 0, HorizontalAlignment.Right) rs.Close() ' parametres la listView puis mode 0 auto titre ou contenu , 1 contenu MySortClass.AjusterLargeurDesColonnes(ListViewEx1, ListViewEx.ListViewEx.emode.TitreouContenu) ' colore une ligne sur deux ' vous pouvez passer color.blue par exemploe au lieu de color.fromArgb MySortClass.DessinerArrièrePlanFaçonListing(ListViewEx1, ListViewEx1.StandardCouleur, ListViewEx1.AlternateCouleur) ListViewEx1.Items(0).Selected = True ' ici j'adapte la fenêtre à la largeur de la ListView car elle ne dépassera pas l'écran ' sinon je ne le ferai pas Dim w As Integer = 2 For i = 0 To ListViewEx1.Columns.Count - 1 w = w + ListViewEx1.Columns(i).Width + 4 Next Me.Width = w ' je n'oublie pas le complément de BeginUpdate ListViewEx1.EndUpdate() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim MySortClass As New ListViewEx.ListViewEx ListViewEx1.PrintListview() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim frm As New Frmpropos frm.ShowDialog() frm.Dispose() End Sub Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing gocnx.Close() End Sub Private Sub ListViewEx1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListViewEx1.MouseWheel MsgBox("mouseweel") End Sub Private Sub ListViewEx1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListViewEx1.MouseDown ' MsgBox(e.X) End Sub Private Sub ListViewEx1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewEx1.DoubleClick MsgBox("Désignation= " & ListViewEx1.SelectedItems(0).SubItems(2).Text & vbCrLf & "Montant= " & ListViewEx1.SelectedItems(0).SubItems(7).Text) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim i As Integer, j As Integer Dim indice As Integer Dim MySortClass As New ListViewEx.ListViewEx On Error Resume Next For i = 0 To ListViewEx1.SelectedItems.Count - 1 indice = ListViewEx1.SelectedItems.Item(j).Index ListViewEx1.Items.Remove(ListViewEx1.Items(indice)) Next MySortClass.DessinerArrièrePlanFaçonListing(ListViewEx1, ListViewEx1.StandardCouleur, ListViewEx1.AlternateCouleur) End SubEnd Class

Exercice Visual Basic : Interface Couleur

Ecrire le code VB qui permet de réaliser l'interface suivante avec les 3 étapes dans la même Forme:

 

123456789101112131415161718192021222324252627282930Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Close() End Sub Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged If CheckBox1.Checked Then Me.Height = 160 Else Me.Height = 87 End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Height = 87 End Sub Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged Me.BackColor = Color.Red End Sub Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged Me.BackColor = Color.Green End Sub Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged Me.BackColor = Color.Blue End SubEnd Class

Exercice Visual Basic : Les Fichiers Séquentiels

Faire un programme en VB qui permet de Gérer les Notes des Stagiaires sur Fichiers Séquentiel :

Chaque stagiaire est connu par son:

  • Numéro
  • Nom
  • Prénom
  • Note1
  • Note2
  • Note3
  • Moyenne

A- Réaliser les Procédures suivantes :

1-      Ecriture des données de stagiaire dans un Fichier

2-      Lecture à partir d’un fichier

3-      Ajout d’un nouveau stagiaire

4-      Modification des données d’un stagiaire

5-      Suppression d'une ligne du tableau

6-      Recherche d'un étudiant

B– Ajouter un Menu de choix d’opérations pour l’utilisateur.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290Imports System.ioImports System.TextModule Module1 Public fichier1 As String = "fichier1.txt" Public fichier2 As String = "fichier2.txt" Public fichier3 As String = "fichier2.txt" Structure Etudiant Dim num As Integer Dim nom As String Dim prenom As String Dim note1, note2, note3, moy As Integer End Structure Public Sub Menu() Console.WriteLine("APPLICATION POUR GERER LES NOTES DES STAGIAIRES SUR FICHIERS ") Console.WriteLine(".................1.ECRITURE.............................") Console.WriteLine(".................2.LECTURE..............................") Console.WriteLine(".................3.ajout ...............................") Console.WriteLine(".................4.MODIFICATION ........................") Console.WriteLine(".................5.SUPPRESSION d'une ligne du tableau...") Console.WriteLine(".................6.RECHERCHE d'un etudiant..............") Console.WriteLine("--------------------------------------------------------") End Sub Sub Main() Dim REP As String Dim choix As Integer Do Menu() Console.WriteLine("Taper votre choix") choix = Console.ReadLine Select Case choix Case 1 ECRITURE(fichier1) Case 2 Console.WriteLine("") Console.WriteLine("LE CONTENU DU fichier1") LECTURE(fichier1) Case 3 ajouter(fichier1) Case 4 Dim numod As Integer Console.WriteLine("saisir le numéro de l'etudiant à modifier ") numod = Console.ReadLine Modification(fichier1, fichier3, numod) Case 5 Dim numero As Integer Console.WriteLine("Saisir le numéro de l'etudiant à supprimer ") numero = Console.ReadLine Suppression(fichier1, fichier2, numero) Case 6 Dim numrech As Integer Console.WriteLine("saisir le numéro de l'etudiant à rechercher ") numrech = Console.ReadLine recherche(fichier1, fichier3, numrech) Case Else Console.WriteLine("ce chois n'est pas traité ") End Select Console.WriteLine("voulez-vous continuez O/N ") REP = Console.ReadLine().ToUpper Loop While (REP.Equals("O")) End Sub Sub ECRITURE(ByVal fich As String) Dim nb As Integer Dim note1, note2, note3, moy As Integer Dim etud As Etudiant Dim sw As StreamWriter = File.AppendText(Path.GetFullPath(fich)) Console.WriteLine("combien d'etudiants voulez vous saisir") nb = Console.ReadLine For i As Integer = 0 To nb - 1 With etud Console.WriteLine("saisir le numéro de l'etudiant " & i + 1) .num = Console.ReadLine Console.WriteLine("saisir le nom de l'etudiant " & i + 1) .nom = Console.ReadLine Console.WriteLine("saisir le prénom de l'etudiant " & i + 1) .prenom = Console.ReadLine Console.WriteLine("saisir la note 1:") .note1 = Console.ReadLine Console.WriteLine("saisir la note 2:") .note2 = Console.ReadLine Console.WriteLine("saisir la note 3:") .note3 = Console.ReadLine .moy = (.note1 + .note2 + .note3) / 3 ' sw.WriteLine(.num & "/" & .nom & "/" & .prenom & "/" & .note1 & "/" & .note2 & "/" & .note3 & "/" & .moy) sw.WriteLine("Numéro :" & "/" & .num & "/" & "Nom : " & .nom & "/" & "Prénom : " & .prenom & "/" & "Note1 : " & .note1 & "/" & "Note2 : " & .note2 & "/" & "Note3 : " & .note3 & "/" & "Moyen : " & .moy) End With Next sw.Flush() sw.Close() End Sub Public Function CompteNombreChamp(ByVal fich As String) As Integer Dim sR As StreamReader sR = File.OpenText(fich) Dim sM As String = sR.ReadLine Dim SLACH, I As Integer If sM = Nothing Then SLACH = 0 Else For I = 1 To sM.Length If Mid(sM, I, 1) = "/" Then SLACH = SLACH + 1 End If Next End If sR.Close() Return SLACH End Function Public Function NombreEnreg(ByVal fich As String) As Integer Dim sR As StreamReader = File.OpenText(fich) Dim sM As String Dim M As Integer sM = sR.ReadLine Try Do M = M + 1 sM = sR.ReadLine Loop Until sM Is Nothing Catch e As Exception End Try sR.Close() Return M End Function Public Sub LECTURE(ByVal fich As String) Dim n As Integer 'Dim tst As String Dim sR As StreamReader = File.OpenText(fich) Dim sM As String = sR.ReadLine Dim t() As String Dim M As Integer M = NombreEnreg(fich) n = CompteNombreChamp(fich) 'tst = Saisie(fich) If n = 0 Then Console.WriteLine() Console.WriteLine("*****Aucun enregistrement trouvé********") Console.WriteLine() Else Do t = sM.Split("/") Try For j As Integer = 0 To n Console.WriteLine(t(j) & vbTab) Next Catch e As Exception End Try Console.WriteLine() sM = sR.ReadLine Loop Until sM Is Nothing End If sR.Close() End Sub Sub ajouter(ByVal fich As String) Dim etud As Etudiant Dim sw As StreamWriter = File.AppendText(Path.GetFullPath(fich)) 'Dim sr As StreamWriter = File.AppendText(Path.GetFullPath(fich1)) With etud Console.WriteLine("saisir le numero de l'etudiant") .num = Console.ReadLine Console.WriteLine("saisir la nom de l'etudiant") .nom = Console.ReadLine Console.WriteLine("saisir la prenom de l'etudiant") .prenom = Console.ReadLine Console.WriteLine("saisir la note1 de l'etudiant") .note1 = Console.ReadLine Console.WriteLine("saisir la note2 de l'etudiant") .note2 = Console.ReadLine Console.WriteLine("saisir la note3 de l'etudiant") .note3 = Console.ReadLine .moy = .note1 + .note2 + .note3 .moy = .moy / 3 sw.WriteLine("Numéro :" & "/" & .num & "/" & "Nom : " & .nom & "/" & "Prénom : " & .prenom & "/" & "Note1 : " & .note1 & "/" & "Note2 : " & .note2 & "/" & "Note3 : " & .note3 & "/" & "Moyen : " & .moy) End With sw.Flush() sw.Close() 'sr.Close() End Sub 'On ouvre deux fichiers Public Sub Modification(ByVal fich As String, ByVal fich2 As String, ByVal numod As Integer) Dim sM As String Dim choix As Integer Dim t() As String Dim trouve As Boolean = False Dim sR As StreamReader = New StreamReader(Path.GetFileName(fich)) Dim sW As StreamWriter = New StreamWriter(fich2) sM = sR.ReadLine 'on lit une ligne Do Until sM Is Nothing t = sM.Split("/") If numod = t(1) Then 'on compare le numéro à supprimer avec la case t(0) Console.WriteLine("************1.modifier le nom******") Console.WriteLine("************2.modifier le prénom***") Console.WriteLine("************3.modifier la note1****") Console.WriteLine("************4.modifier la note2****") Console.WriteLine("************5.modifier la note3****") Console.WriteLine() Console.WriteLine("entrez votre choix") choix = Console.ReadLine Select Case choix Case 1 Console.WriteLine("entrez le nouveau nom") t(2) = Console.ReadLine sM = String.Join("/", t) Case 2 Console.WriteLine("entrez le nouveau nom") t(3) = Console.ReadLine sM = String.Join("/", t) Case 3 Console.WriteLine("entrez la nouvelle note 1") t(4) = Console.ReadLine sM = String.Join("/", t) Case 4 Console.WriteLine("entrez la nouvelle note 2") t(5) = Console.ReadLine sM = String.Join("/", t) Case 5 Console.WriteLine("entrez la nouvelle note 3") t(6) = Console.ReadLine sM = String.Join("/", t) End Select trouve = True sW.WriteLine(sM) ' sinon copie la ligne dans le nouveau fichier1 End If sM = sR.ReadLine ' t.Clear(t, 0, t.GetUpperBound(0)) 'on supprime les element du tbleau Loop If trouve = False Then Console.WriteLine(" élément non trouvé ") End If sW.Close() sR.Close() File.Delete(fich) Rename(fich2, fich) File.Delete(fich2) End Sub 'On ouvre deux fichiers Public Sub Suppression(ByVal fich As String, ByVal fich1 As String, ByVal numero As Integer) Dim sM As String Dim t() As String Dim trouve As Boolean = False Dim sR As StreamReader = New StreamReader(Path.GetFileName(fich)) Dim sW As StreamWriter = New StreamWriter(fich1) sM = sR.ReadLine 'on lit une ligne Do Until sM Is Nothing t = sM.Split("/") If numero = t(1) Then 'on compare le numéro à supprimer avec la case t(0) 'on ne copie pas la ligne dans le nouveau fichier1 Console.WriteLine("Suppression avec succès") trouve = True Else : sW.WriteLine(sM) ' sinon copie la ligne dans le nouveau fichier1 End If sM = sR.ReadLine t.Clear(t, 0, t.GetUpperBound(0)) 'on supprime les element du tbleau Loop If trouve = False Then Console.WriteLine(" élément non trouvé ") End If sW.Close() sR.Close() File.Delete(fich) Rename(fich1, fich) File.Delete(fich1) End Sub Sub recherche(ByVal fich As String, ByVal fich1 As String, ByVal numrech As Integer) Dim t() As String Dim trouve As Boolean = False Dim sM As StreamReader = File.OpenText(fich) Dim sw As StreamReader = File.OpenText(fich1) Dim sr As String = sM.ReadLine Dim a As String = sw.ReadLine Do Until sr Is Nothing t = sr.Split("/") If numrech = t(1) Then Console.Write(sr) Console.WriteLine(a) trouve = True End If sr = sM.ReadLine a = sw.ReadLine Loop If trouve = False Then Console.WriteLine("ce numero n'existe pas") End If sM.Close() sw.Close() End SubEnd Module

Exercice Visual Basic : Les Opérations Arithmétique

Ecrire le code VB qui permet de réaliser l'interface suivante:



123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100Public Class Form1 Dim TypeOpération As String Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click txtN1.Clear() txtN2.Clear() txtResult.Clear() txtN1.Focus() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load RadioButton1.Checked = True TypeOpération = "+" ' Button2.Enabled = False txtN1.TextAlign = HorizontalAlignment.Right txtN2.TextAlign = HorizontalAlignment.Right txtResult.TextAlign = HorizontalAlignment.Right End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim Nbr1, Nbr2 As Double Dim Nbr3 As String = "" Nbr1 = Val(txtN1.Text) Nbr2 = Val(txtN2.Text) Select Case TypeOpération Case "+" Nbr3 = Nbr1 + Nbr2 Case "-" Nbr3 = Nbr1 - Nbr2 Case "*" Nbr3 = Nbr1 * Nbr2 Case "/" Nbr3 = Nbr1 / Nbr2 Case "V" Label2.Text = "V" If txtN1.Text "" Then If txtN2.Text "" Then Nbr3 = Format(Math.Sqrt(Nbr1), "0.0000") Nbr3 &= vbTab & Format(Math.Sqrt(Nbr2), "0.0000") Else Nbr3 = Format(Math.Sqrt(Nbr1), "0.0000") End If Else If txtN2.Text "" Then Nbr3 = Format(Math.Sqrt(Nbr2), "0.0000") End If End If End Select txtResult.Text = Nbr3 End Sub 'Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged ' If TextBox1.Text = "" Then ' Button2.Enabled = False ' Else ' If TextBox2.Text = "" Then ' Button2.Enabled = False ' Else ' Button2.Enabled = True ' End If ' End If 'End Sub 'Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged ' If TextBox2.Text = "" Then ' Button2.Enabled = False ' Else ' If TextBox1.Text = "" Then ' Button2.Enabled = False ' Else ' Button2.Enabled = True ' End If ' End If 'End Sub Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged TypeOpération = "-" Label2.Text = "-" End Sub Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged TypeOpération = "*" Label2.Text = "*" End Sub Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged TypeOpération = "/" Label2.Text = "/" End Sub Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged TypeOpération = "V" Label2.Text = "V" End Sub Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged TypeOpération = "+" Label2.Text = "+" End SubEnd Class
Article publié le 01 Janvier 2012 Mise à jour le Samedi, 17 Décembre 2022 15:56 par Babachekhe Mohamed