Exercice VB: les Instructions Len, Left, Right, Mid

Objectif :

Travaillez avec les Instructions :

  • Len()
  • Left()
  • Right()
  • Mid()

Travail à Faire :

Ecrire le code en VB qui permet de :

  1. Donner le nombre de lettre dans un mot
  2. Donner le nombre de mots dans une phrase
  3. Donnez le nombre de voyelles dans une phrase
  4. D’entrer une nouvelle phrase avec le rangement selon le choix de l'utilisateur
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475761. Donner le nombre de lettre dans un motModule Module1 Sub Main() Dim mot As String Dim nbr As Integer Console.WriteLine("entrer un mot") mot = Console.ReadLine() nbr = Len(mot) Console.WriteLine("le nombre de lettre du mot est=" & Len(mot)) nbr = Console.ReadLine() End SubEnd Module2. Donner le nombre de mots dans une phraseModule phrase Sub Main() Dim ph As String Dim nbr, i As Integer Console.WriteLine("saisir une phrase") ph = Console.ReadLine() nbr = 0 For i = 1 To Len(ph) If Mid(ph, i, 1) = " " Then nbr = nbr + 1 End If Next Console.WriteLine("le nombre de mots de cette fhrase est =" & nbr & " " & "+" & " " & 1 & "=" & nbr + 1) nbr = Console.ReadLine() End SubEnd Module3. Donnez le nombre de voyelles dans une phraseModule voyelle Sub Main() Dim ph As String Dim nb, k As Integer Console.WriteLine("saisir une phrase") ph = Console.ReadLine() nb = 0 For k = 1 To Len(ph) If Mid(ph, k, 1) = "a" Or "i" Or "o" Or "u" Or "y" Or "e" Then nb = nb + 1 End If Next Console.WriteLine("le nombre de voyelles dans cette phrase est=" & nb & "+" & 1 & "=" & nb + 1) nb = Console.ReadLine() Console.ReadLine() End SubEnd Module4. D’entrer une nouvelle phrase avec le rangement selon le choixModule supprimer_char Sub Main() Dim phr As String Dim rang, x, l As Integer Console.WriteLine("saisir une phrase") phr = Console.ReadLine() Console.WriteLine("entrer le rang") rang = Console.ReadLine() l = Len(phr) phr = Left(phr, rang - 1) & Right(phr, l - rang) Console.WriteLine("la nouvelle phrase est=" & Left(phr, rang - 1) & Right(phr, l - rang)) phr = Console.ReadLine() End SubEnd Module

Exercice VB: Tp Gestion Stagiaires Simplifié

Ecrire le Programme qui permet de réaliser l'interfac suivante:

 

Avant de commancer la réalisation du programme vous devez créer une Base de Donnée nomée " Gestion Stagiaire " qui contient les champs suivant:

Table Stagiaire:

  • Numéro :(Numérique)
  • Nom : (Chaine de caractères)
  • Prénom : (Chaine de caractères)
  • Adresse : (Chaine de caractères)
1234567891011121314151617181920Imports System.Data.SqlClient.SqlDataReaderImports System.Data.SqlClientModule Module1 Public cn As New SqlConnection("data source=Exercicesgratuit\SQLEXPRESS;initial catalog=Exercicesgratuit;integrated security=true") Public cmd As New SqlCommand Public da As SqlDataAdapter Public ds As New DataSet Public dt As New DataTable Public bind As New BindingSource Public dtr As DataRelation Public dr As DataRow Public cm As CurrencyManager Public dr1 As SqlDataReader Sub inni() da = New SqlDataAdapter("select * from sta", cn) da.Fill(ds, "sta") dt = ds.Tables("sta") dt.PrimaryKey = New DataColumn() {dt.Columns.Item(0)} End SubEnd Module
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181Imports System.Data.SqlClientImports System.Data.CommonImports System.DataImports SystemPublic Class Form1 Dim pos As Integer Dim d As DataRow Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click End End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load inni() ds.Clear() cn.Open() da = New SqlDataAdapter("select * from sta", cn) da.TableMappings.Add("sta", "sta") da.Fill(ds, "sta") bind.DataSource = ds.Tables("sta") DataGridView1.DataSource = bind cn.Close() End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click txtname.Text = "" txtnom.Text = "" txtpre.Text = "" txtad.Text = "" txtname.Focus() End Sub Sub vider() txtname.Text = "" txtnom.Text = "" txtpre.Text = "" txtad.Text = "" txtname.Focus() 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) = MsgBoxResult.Yes Then End End If End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Try da.InsertCommand = New SqlCommand("insert into sta (num,nom,prenom,adress) values(@a,@b,@c,@d)", cn) da.InsertCommand.Parameters.Add("@a", SqlDbType.Int, 10, "num") da.InsertCommand.Parameters.Add("@b", SqlDbType.VarChar, 50, "nom") da.InsertCommand.Parameters.Add("@c", SqlDbType.VarChar, 50, "prenom") da.InsertCommand.Parameters.Add("@d", SqlDbType.Text, 50, "adress") d = dt.NewRow d("num") = txtname.Text d("nom") = txtnom.Text d("prenom") = txtpre.Text d("adress") = txtpre.Text Try dt.PrimaryKey = New DataColumn() {dt.Columns.Item(0)} dt.Rows.Add(d) Catch ex As Exception MsgBox("Se Num existe déjà", MsgBoxStyle.Information) Exit Sub End Try da.Update(ds, "sta") MsgBox("Ajouter avec Succée") Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Try da.UpdateCommand = New SqlCommand("update sta set nom=@b,prenom=@c,adress=@d where num=@a", cn) da.UpdateCommand.Parameters.AddWithValue("@a", txtname.Text) da.UpdateCommand.Parameters.AddWithValue("@b", txtnom.Text) da.UpdateCommand.Parameters.AddWithValue("@c", txtpre.Text) da.UpdateCommand.Parameters.AddWithValue("@d", txtad.Text) Try cn.Open() da.UpdateCommand.ExecuteNonQuery() da.Update(ds, "sta") MsgBox("Modification avec succée", MsgBoxStyle.Information) vider() Catch ex As Exception MsgBox(ex.Message) Finally cn.Close() End Try Catch ex As Exception MsgBox(ex.Message) End Try 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 Personne de la liste", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then Try Dim dra As DataRow() da.DeleteCommand = New SqlCommand("Delete from sta where num=@a", cn) da.DeleteCommand.Parameters.Add("@a", SqlDbType.Int, 10, "num") dt = ds.Tables("sta") dra = dt.Select("num=" & txtname.Text) Try dt.PrimaryKey = New DataColumn() {dt.Columns.Item(0)} dra(0).Delete() Catch ex As Exception MsgBox("Cette personne n'existe pas", MsgBoxStyle.Information) Exit Sub End Try da.Update(ds, "sta") MsgBox("Suppression avec succéé", MsgBoxStyle.Information) vider() Catch ex As Exception MsgBox(ex.Message) End Try End If End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click Try Dim str As String = InputBox("Entrer le numéro du Persone à chercher") dr = dt.Rows.Find(str) If dr Is Nothing Then MsgBox("Se personne n'existe pas") Else With dr txtname.Text = .Item(0) txtnom.Text = .Item(1) txtpre.Text = .Item(2) txtad.Text = .Item(3) End With End If Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Sub afficher(ByVal i As Integer) With dt.Rows(i) txtname.Text = .Item(0) txtnom.Text = .Item(1) txtpre.Text = .Item(2) txtad.Text = .Item(3) End With End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If dt.Rows.Count > 0 Then pos = 0 afficher(pos) TextBox5.Text = pos + 1 End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If pos > 0 Then pos -= 1 afficher(pos) TextBox5.Text = pos + 1 End If End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If pos Then pos += 1 afficher(pos) TextBox5.Text = pos + 1 End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click If dt.Rows.Count > 0 Then pos = dt.Rows.Count - 1 afficher(pos) TextBox5.Text = pos + 1 End If End Sub Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click Me.Hide() Form2.Show() End SubEnd Class

Exercice VB: Interface MS Word

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


123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217Imports System.IOPublic Class Form1 Public lblrs As Label Private Sub NouveauToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NouveauToolStripMenuItem.Click End Sub Private Sub OuvrirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OuvrirToolStripMenuItem.Click 'Dim opendlg As New OpenFileDialog 'With opendlg ' .InitialDirectory = IO.Directory.GetCurrentDirectory ' If .ShowDialog() = DialogResult.OK Then ' lblrs.Text = "filename = " & .FileName ' Else ' lblrs.Text = "annulé" ' End If 'End With If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Dim nomfichier As String = OpenFileDialog1.FileName Dim str As StreamReader = New StreamReader(nomfichier) RichTextBox1.Text = str.ReadToEnd str.Close() End If End Sub Private Sub FermerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FermerToolStripMenuItem.Click End End Sub Private Sub EnregestrerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnregestrerToolStripMenuItem.Click FileOpen(1, "stagiaire.txt", OpenMode.Random, OpenAccess.Write, Len(RichTextBox1)) End Sub Private Sub EnregestrerSousToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnregestrerSousToolStripMenuItem.Click SaveFileDialog1.InitialDirectory = Application.ExecutablePath SaveFileDialog1.Filter = "Enregestrer Sous (*.doc)|*.doc|All files (*.*)|*.*" SaveFileDialog1.FilterIndex = 0 If SaveFileDialog1.ShowDialog() = DialogResult.OK Then Dim nomFichier As String = SaveFileDialog1.FileName Dim fichier As StreamWriter = Nothing Try fichier = New StreamWriter(nomFichier) Catch ex As Exception MessageBox.Show("Problème à l'écriture du fichier (" + ex.Message + ")", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error) Return Finally Try fichier.Close() Catch End Try End Try End If End Sub Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click If ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then ' choix d'une couleur de texte RichTextBox1.ForeColor = ColorDialog1.Color ' on change la propriété forecolor du TextBox End If End Sub Private Sub ToolStripButton11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton11.Click If FontDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then RichTextBox1.Font = FontDialog1.Font End If End Sub Private Sub MiseEnPageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MiseEnPageToolStripMenuItem.Click Dim pagedlg As New PageSetupDialog With pagedlg Dim pd As New Drawing.Printing.PrintDocument() .Document = pd If .ShowDialog = DialogResult.OK Then With .PageSettings.PaperSize lblrs.Text = String.Format("papier : {0] * {1]", .Width, .Height) End With With .PageSettings.Margins lblrs.Text += String.Format("-marges {0],{1],{2],{3]", .Left, .Top, .Right, .Bottom) End With Else lblrs.Text = "annulé" End If End With End Sub Private Sub CouperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CouperToolStripMenuItem.Click RichTextBox1.Cut() End Sub Private Sub CopierToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopierToolStripMenuItem.Click RichTextBox1.Copy() End Sub Private Sub CollerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CollerToolStripMenuItem.Click RichTextBox1.Paste() End Sub Private Sub SelectionnerToutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectionnerToutToolStripMenuItem.Click RichTextBox1.SelectAll() End Sub Private Sub EffacerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EffacerToolStripMenuItem.Click RichTextBox1.Clear() End Sub 'Private Sub RechercherToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RechercherToolStripMenuItem.Click ' Dim dlgrecherche As New DialogResult ' Dim i As Integer = RichTextBox1.Text.IndexOf(Text, RichTextBox1.selectionstatr + RichTextBox1.selectionlenght) 'End Sub Private Sub ImprimerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImprimerToolStripMenuItem.Click Dim printdlg As New PrintDialog With printdlg Dim pd As New Drawing.Printing.PrintDocument() .Document = pd .AllowSelection = True .AllowSomePages = True pd.PrinterSettings.MaximumPage = 5 If .ShowDialog = DialogResult.OK Then With pd.PrinterSettings lblrs.Text = String.Format("imprimante : {0]-copier : {1] - page : {2] -{3]", .PrinterName, .Copies, .FromPage, .ToPage) End With Else lblrs.Text = "annuler" End If End With End Sub Private Sub PoliceToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PoliceToolStripMenuItem.Click If FontDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then RichTextBox1.Font = FontDialog1.Font End If End Sub Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click Dim opendlg As New OpenFileDialog With opendlg .InitialDirectory = IO.Directory.GetCurrentDirectory If .ShowDialog() = DialogResult.OK Then lblrs.Text = "filename = " & .FileName Else lblrs.Text = "annulé" End If End With End Sub Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click Dim printdlg As New PrintDialog With printdlg Dim pd As New Drawing.Printing.PrintDocument() .Document = pd .AllowSelection = True .AllowSomePages = True pd.PrinterSettings.MaximumPage = 5 If .ShowDialog = DialogResult.OK Then With pd.PrinterSettings lblrs.Text = String.Format("imprimante : {0]-copier : {1] - page : {2] -{3]", .PrinterName, .Copies, .FromPage, .ToPage) End With Else lblrs.Text = "annuler" End If End With End Sub Private Sub ToolStripButton8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click RichTextBox1.Cut() End Sub Private Sub ToolStripButton9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton9.Click RichTextBox1.Copy() End Sub Private Sub ToolStripButton10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton10.Click RichTextBox1.Paste() End Sub Private Sub ToolStripButton12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton12.Click RichTextBox1.Undo() End Sub Private Sub ToolStripButton13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton13.Click RichTextBox1.Update() End Sub Private Sub ToolStripButton14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button14.Click Try Dim nouveaustyle As FontStyle = RichTextBox1.SelectionFont.Style If sender.button14.pushed Then nouveaustyle = nouveaustyle Or FontStyle.Bold Else nouveaustyle = nouveaustyle And Not FontStyle.Bold End If RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, nouveaustyle) Catch ex As Exception 'button14.pushed = RichTextBox1.SelectionFont.Bold End Try End Sub Private Sub ToolStripComboBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripComboBox1.Click Dim t As Integer Dim fnt As New Font("arial", 20, FontStyle.Bold) sender.richtextbox1.drawstring(fnt.Style.ToString, fnt, Brushes.Blue, 10, t) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ToolStripComboBox1.Items.Add("Arial") End SubEnd Class

 Exercice VB: StreamReader et StreamWriter

Objectif :

Travailler avec :

  • StreamReader
  • StreamWriter

Travail à Faire :

Ecrire le code en VB qui permet de :

  1. Chercher si un Fichier existe ou pas S’il n'existe pas. On le crée
  2. Ouverture du fichier et Ecriture du contenu du fichier sur la console
123456789101112131415161718192021222324252627282930313233Imports System.IOModule Module1 Sub maine() End Sub Sub FichierTexte(ByVal mixt As String) Dim sr As StreamReader Dim sw As StreamWriter Dim sLine As String Try If Not File.Exists(mixt) Then 'Le fichier n'existe pas. On le crée sw = New StreamWriter(mixt) sw.WriteLine("Bonjour. Il nous sommes le {0} et il est {1} ", DateTime.Now.ToLongDateString, DateTime.Now.ToLongTimeString) sw.Close() sw = Nothing End If 'Ouverture du fichier et Ecriture du contenu du fichier sur la console sr = New StreamReader(mixt) Console.WriteLine("Debut du fichier") sLine = sr.ReadLine() While Not sLine Is Nothing Console.WriteLine(sLine) sLine = sr.ReadLine() End While Console.WriteLine("Fin du fichier") Finally 'Fermeture streamreader If Not IsNothing(sr) Then sr.Close() End Try Console.ReadLine() End SubEnd Module

 Exercice VB: Carré Magique

Objectif :

Travailler avec les Tableaux à deux dimensions.

Travail à Faire :

1. Ecrire le programme qui détermine le plus grand élément et le petit élément ainsi, la position de plus grand élément et le petit élément d'une matrice.

2. Un carré magique d'ordre n est une matrice carrée n x n telle que la somme des entiers de chaque ligne, chaque colonne et des deux diagonales sont identiques.

Exemple de carré magique d'ordre 3 :

2

9

4

7

5

3

6

1

8

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586871.Module Module1Dim i, j, n, m, Max, Min, Pmax_x, Pmax_y, Pmin_x, Pmin_y As IntegerSub Main()Console.Write("Entrez le nombre de lignes : ")n = Console.ReadLineConsole.Write("Entrez le nombre de colonnes : ")m = Console.ReadLineDim T(n, m) As IntegerFor i = 0 To n - 1For j = 0 To m - 1Console.Write("t(" & i + 1 & " , " & j + 1 & ") = ")T(i, j) = Console.ReadLineNextNextMax = T(0, 0)Min = T(0, 0)Pmax_x = 1Pmax_y = 1Pmin_x = 1Pmin_y = 1For i = 0 To n - 1For j = 0 To m - 1If T(i, j) > Max ThenMax = T(i, j)Pmax_x = i + 1Pmax_y = j + 1End IfIf T(i, j) ThenMin = T(i, j)Pmin_x = i + 1Pmin_y = j + 1End IfNextNextConsole.WriteLine("Le plus grand élément est : " & Max)Console.WriteLine("Sa postion est : " & "T(" & Pmax_x & ";" &Pmax_y & ")")Console.WriteLine("Le petit élément est : " & Min)Console.WriteLine("Sa postion est : " & "T(" & Pmin_x & ";" &Pmin_y & ")")Console.ReadLine()End SubEnd Module2.Module Module1Dim n, i, j, s, c, c1, s1, Cmpt As IntegerSub Main()Cmpt = 0Console.Write("Entrez le nombre de lignes : ")n = Console.ReadLineDim T(n, n) As IntegerFor i = 0 To n - 1For j = 0 To n - 1Console.Write("T(" & i + 1 & " , " & j + 1 & ") = ")T(i, j) = Console.ReadLineNextNextc1 = 0s1 = 0For j = 0 To n - 1s1 = s1 + T(j, j)c1 = c1 + T(j, n - 1 - j)NextIf s1 = c1 ThenCmpt = Cmpt + 2End IfFor i = 0 To n - 1c = 0s = 0For j = 0 To n - 1s = s + T(i, j)c = c + T(j, i)NextIf (s = c) And (s = s1) ThenCmpt = Cmpt + 2End IfNextIf Cmpt = (2 * n) + 2 ThenConsole.WriteLine("carré magique")ElseConsole.WriteLine("carré pas magique")End IfConsole.ReadLine()End SubEnd Module

 Exercice VB: Transférer une matrice à deux dimension

Objectif :

Travailler avec les Tableaux à deux dimensions.

Travail à Faire :

Ecrire un programme qui transfère une matrice M à deux dimension L et C (dimensions maximales : 10 lignes et 10 colonnes) dans un tableau V à une dimension L * C.

Exemple :

 /           \

| a b c d  |                    /                               \

| e f g h  | =======> | a b c d e f g h i j k l |

| i j k l     |                     \                              /

\            /

12345678910111213141516171819202122232425262728293031323334353637Module Module1Dim i, j, L, C, x, y As IntegerSub Main()Console.Write(" L : ")L = Console.ReadLineConsole.Write(" C : ")C = Console.ReadLineWhile (L > 10 Or C > 10) Or (L 0 Or C 0)Console.WriteLine("SVP, L et C devent être compris entre 0 et10")Console.Write(" L : ")L = Console.ReadLineConsole.Write(" C : ")C = Console.ReadLineEnd WhileDim M(L, C) As StringDim V(L * C) As Stringx = 0y = L * CFor i = 0 To L - 1For j = 0 To C - 1Console.Write("M(" & i + 1 & " ; " & j + 1 & ") = ")M(i, j) = Console.ReadLineNextNextFor i = 0 To L - 1For j = 0 To C - 1V(x) = M(i, j)x += 1NextNextFor i = 0 To y - 1Console.Write(V(i) & " ")NextConsole.ReadLine()End SubEnd Module

Exercice VB: Gestion d'Article

Ecrire le code VB qui permet de :

1-      Faire l’écriture des données d'un Article dans un Fichier 

2-      Faire la lecture des données d'un Article dans un Fichier

3-      Faire l’ajout d’un article

4-      Faire la suppression d’un article

5-      Copier des données d'un Article dans un Fichier

6-      Quitter

7-      Un menu de Choix

Un Produit est connu par :

  1. Le numéro de référence
  2. La désignation de produit
  3. Le type de produit (A, B ou C)
  4. Le prix unitaire
  5. La Quantité
  6. Le prix totale en TTC
a.     Si le type est A alors la TVA est 20%b.     Si le type est B alors la TVA est 14%c.     Si le type est C alors la TVA  est 7%
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186Imports SystemModule Module1 Public tcl() As article Public O As Char Public nb As Integer Public Structure article (4)> Public ref As Integer (12)> Public desig As String (2)> Public prix As Double (10)> Public typ As String (12)> Public tva As Double (5)> Public qut As Integer (10)> Public ttc As Double End Structure Sub menu() Console.WriteLine("1.ecriture") Console.WriteLine("2.lecture") Console.WriteLine("3.ajout") Console.WriteLine("4.suppression") Console.WriteLine("5.copier") Console.WriteLine("6.quiter") End Sub Sub Main() Dim choix As String Dim rep As String Do menu() Console.WriteLine(" tapez votre choix") choix = Console.ReadLine Select Case choix Case 1 ecriture() Case 2 lecture(tcl) Case 5 copier() Case 6 quiter() Case 3 'ReDim Preserve tab(tab.GetUpperBound(0) + 1) ajout() Case 4 Console.WriteLine("saisir l'élément supprimer") Dim elem = Console.ReadLine suppression(tcl, elem) Case Else Console.WriteLine("le choix que vous avez tapez est introuvable") End Select Console.WriteLine("voulez-vous contunier ?o/n") rep = Console.ReadLine Loop Until (rep = "n") End Sub Public Sub lecture(ByRef tcl() As article) For i = 0 To tcl.GetUpperBound(0) With tcl(i) Console.WriteLine(tcl(i).ref & vbTab & tcl(i).desig & vbTab & tcl(i).typ & vbTab & tcl(i).prix & vbTab & tcl(i).qut & vbTab & tcl(i).tva & vbTab & tcl(i).ttc) End With Next End Sub Public Sub ecriture() Console.WriteLine("nombre d'article") nb = Console.ReadLine ReDim tcl(nb - 1) For i = 0 To tcl.GetUpperBound(0) With tcl(i) Console.WriteLine("entrez le numero de reference") .ref = Console.ReadLine Console.WriteLine("entrez la designation de produit") .desig = Console.ReadLine Console.WriteLine("entrez le type(A,B ou C) de produit ") .typ = Console.ReadLine Console.WriteLine("entrez le prix unitaire du produit") .prix = Console.ReadLine Console.WriteLine("entrez la Quantité du produit") .qut = Console.ReadLine If .typ = "A" Then .tva = 20% ElseIf .typ = "B" Then .tva = 14% ElseIf .typ = "C" Then .tva = 7% End If .ttc = (CDbl(.prix) * CDbl(.qut)) + (CDbl(.prix) * (CDbl(.qut) * 0.07)) End With Next End Sub Sub ajout() ReDim Preserve tcl(tcl.GetUpperBound(0) + 1) With tcl(tcl.GetUpperBound(0)) Console.WriteLine("entrez le numero de reference") .ref = Console.ReadLine Console.WriteLine("entrez la designation de produit") .desig = Console.ReadLine Console.WriteLine("entrez le type(A,B ou C) de produit ") .typ = Console.ReadLine Console.WriteLine("entrez le prix unitaire du produit") .prix = Console.ReadLine Console.WriteLine("entrez la Quantité du produit") .qut = Console.ReadLine If .typ = "A" Then .tva = 20% ElseIf .typ = "B" Then .tva = 14% ElseIf .typ = "C" Then .tva = 7% End If .ttc = (CDbl(.prix) * CDbl(.qut)) + (CDbl(.prix) * (CDbl(.qut) * 0.07)) End With End Sub Function recherche_par_ref(ByVal tab() As article, ByVal ref As Integer) As Integer For i = 0 To tab.GetUpperBound(0) Next End Function Public Function suppression(ByRef t() As article, ByVal ele As Integer) Dim i As Integer Dim pos = recherche(t, ele) If pos -1 Then i = 0 If pos t.GetUpperBound(0) Then Do t(pos + i) = t(pos + i + 1) i += 1 Loop Until t(pos + i).ref = t(t.GetUpperBound(0)).ref Else ReDim Preserve t(t.Length - 1) Return t End If End If ReDim Preserve t(t.Length - 1) Return t With (i) Console.WriteLine("entrez le numero de reference") tcl(i).ref = Console.ReadLine Console.WriteLine("entrez la designation de produit") tcl(i).desig = Console.ReadLine Console.WriteLine("entrez le type(A,B ou C) de produit ") tcl(i).typ = Console.ReadLine Console.WriteLine("entrez le prix unitaire du produit") tcl(i).prix = Console.ReadLine Console.WriteLine("entrez la Quantité du produit") tcl(i).qut = Console.ReadLine If tcl(i).typ = "A" Then tcl(i).tva = 20% tcl(i).ttc = (CDbl(tcl(i).prix) * CDbl(tcl(i).qut)) + (CDbl(tcl(i).prix) * ((CDbl(tcl(i).qut)) * 0.2)) ElseIf tcl(i).typ = "B" Then tcl(i).tva = 14% tcl(i).ttc = (CDbl(tcl(i).prix) * CDbl(tcl(i).qut)) + (CDbl(tcl(i).prix) * (CDbl(tcl(i).qut) * 0.14)) ElseIf tcl(i).typ = "c" Then tcl(i).tva = 7% tcl(i).ttc = (CDbl(tcl(i).prix) * CDbl(tcl(i).qut)) + (CDbl(tcl(i).prix) * (CDbl(tcl(i).qut) * 0.07)) End If End With End Function Function recherche(ByRef t() As article, ByVal ele As Integer) As Integer For i As Integer = 0 To t.GetUpperBound(0) If t(i).ref = ele Then Return i Exit Function Else End If Next Return -1 End Function Sub copier() FileOpen(1, "fichier.txt", OpenMode.Output) For i = 0 To nb - 1 PrintLine(1, tcl(i).ref & "/" & tcl(i).desig & "/" & tcl(i).typ & "/" & tcl(i).prix & "/" & tcl(i).tva & "/" & tcl(i).ttc) Next FileClose(1) FileOpen(1, "fichier.txt", OpenMode.Input) While Not EOF(1) Console.WriteLine(LineInput(1)) End While FileClose(1) End Sub Public Sub quiter() Exit Sub End SubEnd Module

Exercice VB: TP Distances inter-atomiques

On se propose d'écrire un programme permettant le calcul de la longueur d'une liaison entre deux atomes dans un matériau, à partir des paramètres de maille (a, b, c, a , b , g ) et des coordonnées atomiques (x, y, z). Pour cela, on transforme les coordonnées (x,y,z) de chaque atome en coordonnées cartésiennes (Xt, Yt, Zt) de la façon suivante:

Une fois la transformation faite, l'expression pour la distance entre les atomes A1 et A2 est simplement:

Programme demandé :

  1. Interface (voir exemple ci-dessous):
  • Six zones de texte pour saisir les paramètres de maille (a, b, c, a , b , g )
  • Six autres pour la saisie des coordonnées (x, y, z) des atomes A1 et A2
  • Un bouton Calcul
  • Six zones de texte pour afficher les coordonnées pour A1 et A2 après transformation – repère cartésien
  • Une zone de texte pour l'affichage de la distance calculée entre A1 et A2 dans le nouveau repère
  1. Vous devrez écrire trois fonctions à placer de préférence dans un module (Public Function) :
  • DegRad, la première, aura pour simple objectif de convertir des degrés en radians. Elle recevra donc un seul argument de type double pour retourner une valeur du même type.
  • MTransform recevra les paramètres de la maille et les coordonnées d'un atome exprimées dans ce système. Le but de cette fonction est de retourner les coordonnées de cet atome transformées selon la formule expliquée plus haut.
  • Distance, enfin, retournera la distance entre les deux atomes dont les coordonnées respectives lui auront été passées en arguments. Le résultat de ce calcul sera de type double.
  1. Le bouton Calcul ordonnera successivement les trois taches suivantes :
  • Lecture des valeurs des paramètre de la maille avec conversion des angles (a , b et g ) en radians à l'aide de DegRad. Lecture des coordonnées (x, y, z) des atomes A1 et A2.
  • Transformation des coordonnées de A1 et A2 dans le nouveau repère – à l'aide de MTransform. Affichage des nouvelles coordonnées.
  1. Calcul de la distance et affichage

Interface graphique :

Voici les étapes à suivre pour construire l’interface

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172Code de la feuille Form1 :Private Sub Command1_Click() 'Lecture des valeurs M.a = Val(Ta.Text) M.b = Val(Tb.Text) M.c = Val(Tc.Text) M.alpha = degrad(Val(Talpha.Text)) M.beta = degrad(Val(Tbeta.Text)) M.gamma = degrad(Val(Tgamma.Text)) A1.x = Val(TA1x.Text) A1.y = Val(TA1y.Text) A1.z = Val(TA1z.Text) A2.x = Val(TA2x.Text) A2.y = Val(TA2y.Text) A2.z = Val(TA2z.Text) 'Transformation des coordonnées At1 = MTransform(M, A1) At2 = MTransform(M, A2) 'Affichage des coordonnées transformées TTA1x.Text = Str(At1.x) TTA1y.Text = Str(At1.y) TTA1z.Text = Str(At1.z) TTA2x.Text = Str(At2.x) TTA2y.Text = Str(At2.y) TTA2z.Text = Str(At2.z) 'calcul de la distance et affichage D = Distance(At1, At2) Tdistance = Str(D)End SubCode à placer dans un module :Public Type XYZ x As Double y As Double z As DoubleEnd TypePublic Type Maille_type a As Double b As Double c As Double alpha As Double beta As Double gamma As DoubleEnd TypePublic A1 As XYZ, A2 As XYZPublic At1 As XYZ, At2 As XYZPublic D As DoublePublic M As Maille_typePublic Const Pi = 3.14159265358979Public Function MTransform(M As Maille_type, Atom As XYZ) As XYZ Dim V As Double V = M.a * M.b * M.c * _ Sqr(1 - Cos(M.alpha) ^ 2 - Cos(M.beta) ^ 2 - Cos(M.gamma) ^ 2 + 2 * Cos(M.alpha) * Cos(M.beta) * Cos(M.gamma)) MTransform.x = M.a * Atom.x + _ M.b * Cos(M.gamma) * Atom.y + _ M.c * Cos(M.beta) * Atom.z MTransform.y = M.b * Sin(M.gamma) * Atom.y + _ M.c * (Cos(M.alpha) - Cos(M.beta) * Cos(M.gamma)) * Atom.z / Sin(M.gamma) MTransform.z = V * Atom.z / (M.a * M.b * Sin(M.gamma))End FunctionPublic Function Distance(A1 As XYZ, A2 As XYZ) As Double Distance = Sqr((A1.x - A2.x) ^ 2 + (A1.y - A2.y) ^ 2 + (A1.z - A2.z) ^ 2)End FunctionPublic Function degrad(D As Double) As Double 'Convertion degrés >>> radians degrad = D * Pi / 180#End Function

Exercice VB: Examen Fin de Formation TSDI 2008 variante 5

La société Télé-Commerce souhaite mettre en place un système de vente sur Internet, vous étés maintenant chargé de développer cette application en respectant le modèle relationnel suivant :

CLIENTS (NumClient, Nom, Prenom, Ville, Tele).

COMMANDES (NumCommande, DateCommande, NumProduit,, Quantité).

 ETAT _COMMANDE(NumCommand, NumClient ,  EtatCommande).

 PRODUITS (N°Produit, Libellé, PrixUnitaire, TVA). 

Une fois le client fait le règlement de la commande, les produits commandés seront livrés dans un délais ne dépassant pas 48h.

EtatCommande : décrit l‘état de la commande (En cours, valider, annuler)

TVA : 20%

Travail à faire :

  1. Créer la base de données sous SQL SERVER (2 Pts)
  2. Faire quelques enregistrements pour le test
  3. Créer une interface de mise à jour des Client (4 Pts)
    1. Ajout (le contrôle de saisie est obligatoire et confirmation d’ajout)
    2. Modification
    3. Suppression
    4. Boutons de navigation
  4. Créer une interface de mise à jour des Produit (2 Pts)
  5. Créer une interface de mise à jour des Commande et Etat_Commande (4 Pts)
  6. Créer une feuille de recherche :
    1. Commandes passés par un client (1 Pt)
    2. Recherche les commandes validées entre deux dates (1 Pt)
  7. Sachant qu’une remise de 3% sur tous les produits est accordée aux clients ayant passé plus de 5 commandes. Faire les modification nécessaires sur l’interface Commande  (2 Pts)
  8. Créer un état pour afficher les commandes passées entre deux dates et l’état de chaque commande (3 Pts)
  9. Créer un état permettant de lister les commandes passée durant le mois en cours et le montant total des commandes (3Pts)
  10. Créer une page web permettant d’afficher la liste des produits (2 Pt)
  11. Créer une page permettant de mettre à jour la table Produits (2 Pts)
  12. Créer une page permettant aux clients de passer des commandes via Internet en choisissant des produit , l’état de chaque commande passée depuis le site web doit être en cours de traitement. L’affichage du montant total de la commande est obligatoire (3 Pts)
  13. Créer une page permettant d’afficher la liste des commandes en cours de traitement avec leurs montants (3 Pts)
  14. Créer une interface pour mettre à jour la table Produits (JAVA/JDBC) :
    1. Ajout (2 Pts)
    2. Modification (2 Pts)
    3. Suppression (2 Pts)
    4. Recherche (2 Pts)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648Imports System.Data.SqlClientPublic Class Client Private Sub Client_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim f As String = "select * from client" adp = New SqlDataAdapter(f, con) adp.Fill(dset, "client") tabcl = dset.Tables("client") tabcl.PrimaryKey = New DataColumn() {tabcl.Columns.Item(0)} DataGridView1.DataSource = tabcl End Sub Private Sub affichage(ByVal pos As Integer) With tabcl.Rows(pos) Numclient.Text = .Item(0) nomcl.Text = .Item(1) prenomcl.Text = .Item(2) villecl.Text = .Item(3) telephonecl.Text = .Item(4) End With End Sub Private Sub mise() Dim sqcmbui As New SqlCommandBuilder(adp) adp.Update(tabcl) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Numclient.Clear() nomcl.Clear() prenomcl.Clear() villecl.Clear() telephonecl.Clear() Numclient.Focus() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try Dim r As DataRow r = tabcl.NewRow() With r .Item(0) = Numclient.Text .Item(1) = nomcl.Text .Item(2) = prenomcl.Text .Item(3) = villecl.Text .Item(4) = telephonecl.Text End With tabcl.Rows.Add(r) mise() MsgBox("ajout avec succ") Button1_Click(sender, e) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Try Dim r As DataRow r = tabcl.Rows.Find(Numclient.Text) r.Delete() mise() MsgBox("supprimer aver succé") Button1_Click(sender, e) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Try Dim r As DataRow r = tabcl.Rows.Find(Numclient.Text) With r .Item(0) = Numclient.Text .Item(1) = nomcl.Text .Item(2) = prenomcl.Text .Item(3) = villecl.Text .Item(4) = telephonecl.Text End With mise() MsgBox("modification avec succé") Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click pos = 0 affichage(pos) End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Try If pos > 0 Then pos -= 1 affichage(pos) Else MsgBox("c'est le premier") End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Try If pos Then pos += 1 affichage(pos) Else MsgBox("c'est le dérnier") End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click pos = tabcl.Rows.Count - 1 affichage(pos) End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click Me.Hide() f1.Show() End SubEnd Class---------------------------------------------------------------------------Imports System.Data.SqlClientPublic Class Commande Private Sub Commande_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO : cette ligne de code charge les données dans la table 'Gestion_commandeDataSet.Produits'. Vous pouvez la déplacer ou la supprimer selon vos besoins. Me.ProduitsTableAdapter.Fill(Me.Gestion_commandeDataSet.Produits) Dim f As String = "select * from commandes" adpCm = New SqlDataAdapter(f, con) adpCm.Fill(dset, "commandes") tabcom = dset.Tables("commandes") tabcom.PrimaryKey = New DataColumn() {tabcom.Columns.Item(0)} DataGridView1.DataSource = tabcom End Sub Private Sub affichage(ByVal pos As Integer) With tabcom.Rows(pos) Numcom.Text = .Item(0) DateCom.Text = .Item(1) NumPr.Text = .Item(2) Qunt.Text = .Item(3) End With End Sub Private Sub mise() Dim sqcmbui As New SqlCommandBuilder(adpCm) adpCm.Update(tabcom) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Numcom.Clear() DateCom.Clear() 'NumPr.Clear() Qunt.Clear() Numcom.Focus() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try Dim r As DataRow r = tabcom.NewRow() With r .Item(0) = Numcom.Text .Item(1) = DateCom.Text .Item(2) = NumPr.Text .Item(3) = Qunt.Text End With tabcom.Rows.Add(r) mise() MsgBox("ajout avec succ") Button1_Click(sender, e) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Try Dim r As DataRow r = tabcom.Rows.Find(Numcom.Text) r.Delete() mise() MsgBox("supprimer aver succé") Button1_Click(sender, e) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Try Dim r As DataRow r = tabcom.Rows.Find(Numcom.Text) With r .Item(0) = Numcom.Text .Item(1) = DateCom.Text .Item(2) = NumPr.Text .Item(3) = Qunt.Text End With mise() MsgBox("modification avec succé") Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click pos = 0 affichage(pos) End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Try If pos > 0 Then pos -= 1 affichage(pos) Else MsgBox("c'est le premier") End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Try If pos Then pos += 1 affichage(pos) Else MsgBox("c'est le dérnier") End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click pos = tabcom.Rows.Count - 1 affichage(pos) End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click Me.Hide() f1.Show() End SubEnd Class----------------------------------------------------------------------------Imports System.Data.SqlClientPublic Class commande_entre_2_dates Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim h As String Dim o, b As Date o = TextBox1.Text b = TextBox2.Text h = " select * from Commandes where DateCommande Between '" & o & "' and '" & b & "'" Dim command1 As New SqlCommand(h, con) Try con.Open() Dim k As SqlDataReader = command1.ExecuteReader Dim j As String Do While k.Read() j = Str(k.GetValue(0)) + " " + k.GetValue(1) + " " + Str(k.GetValue(2)) + " " + Str(k.GetValue(3)) L1.Items.Add(j) Loop k.Close() con.Close() Catch ex As SqlException MsgBox(ex.Message) End Try End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click TextBox1.Text = "" TextBox2.Text = "" TextBox1.Focus() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click f1.Show() Me.Hide() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click End End SubEnd Class------------------------------------------------------------------------------Imports System.Data.SqlClientPublic Class EtatCommande Private Sub EtatCommande_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO : cette ligne de code charge les données dans la table 'Gestion_commandeDataSet3.Client'. Vous pouvez la déplacer ou la supprimer selon vos besoins. Me.ClientTableAdapter.Fill(Me.Gestion_commandeDataSet3.Client) 'TODO : cette ligne de code charge les données dans la table 'Gestion_commandeDataSet3.Commandes'. Vous pouvez la déplacer ou la supprimer selon vos besoins. Me.CommandesTableAdapter.Fill(Me.Gestion_commandeDataSet3.Commandes) Dim f As String = "select * from Etatcommande" adpEcm = New SqlDataAdapter(f, con) adpEcm.Fill(dset, "Etatcommande") tabecom = dset.Tables("Etatcommande") tabecom.PrimaryKey = New DataColumn() {tabecom.Columns.Item(0)} DataGridView1.DataSource = tabecom End Sub Private Sub affichage(ByVal pos As Integer) With tabecom.Rows(pos) Numcom.Text = .Item(0) NumCl.Text = .Item(1) EtatCom.Text = .Item(2) End With End Sub Private Sub mise() Dim sqcmbui As New SqlCommandBuilder(adpEcm) adpEcm.Update(tabcom) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Me.Numcom.Clear() 'NumCl.Clear() 'EtatCom.Clear() Numcom.Focus() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try Dim r As DataRow r = tabecom.NewRow() With r .Item(0) = Numcom.Text .Item(1) = NumCl.Text .Item(2) = EtatCom.Text End With tabecom.Rows.Add(r) mise() MsgBox("ajout avec succ") Button1_Click(sender, e) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Try Dim r As DataRow r = tabecom.Rows.Find(Numcom.Text) r.Delete() mise() MsgBox("supprimer aver succé") Button1_Click(sender, e) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Try Dim r As DataRow r = tabecom.Rows.Find(Numcom.Text) With r .Item(0) = Numcom.Text .Item(1) = NumCl.Text .Item(2) = EtatCom.Text End With mise() MsgBox("modification avec succé") Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click pos = 0 affichage(pos) End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Try If pos > 0 Then pos -= 1 affichage(pos) Else MsgBox("c'est le premier") End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Try If pos Then pos += 1 affichage(pos) Else MsgBox("c'est le dérnier") End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click pos = tabecom.Rows.Count - 1 affichage(pos) End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click Me.Hide() f1.Show() End SubEnd Class--------------------------------------------------------------------------------Imports System.Data.SqlClientPublic Class Produit Private Sub Produit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim f As String = "select * from produits" adpPr = New SqlDataAdapter(f, con) 'pour inisialiser adpter Produit adpPr.Fill(dset, "produits") tabpr = dset.Tables("produits") tabpr.PrimaryKey = New DataColumn() {tabpr.Columns.Item(0)} DataGridView1.DataSource = tabpr End Sub Private Sub mise() Dim sqcom As New SqlCommandBuilder(adpPr) adpPr.Update(tabpr) End Sub Private Sub affichage(ByVal pos As Integer) With tabpr.Rows(pos) N_pr.Text = .Item(0) Libelli.Text = .Item(1) PrixU.Text = .Item(2) Tva.Text = .Item(3) End With End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click N_pr.Clear() Libelli.Clear() PrixU.Clear() Tva.Clear() N_pr.Focus() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try Dim r As DataRow r = tabpr.NewRow With r .Item(0) = N_pr.Text .Item(1) = Libelli.Text .Item(2) = PrixU.Text .Item(3) = Tva.Text End With tabpr.Rows.Add(r) mise() MsgBox("ajout avec succée") Button1_Click(sender, e) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Try Dim r As DataRow r = tabpr.Rows.Find(N_pr.Text) With r .Item(0) = N_pr.Text .Item(1) = Libelli.Text .Item(2) = PrixU.Text .Item(3) = Tva.Text End With mise() Button1_Click(sender, e) MsgBox("modifier avec succée") Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Try Dim r As DataRow r = tabpr.Rows.Find(N_pr.Text) r.Delete() mise() Button1_Click(sender, e) MsgBox("suppression avec succée") Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click 'If pos > 0 Then pos = 0 affichage(pos) 'End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click pos = tabpr.Rows.Count - 1 affichage(pos) End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Try If pos > 0 Then pos -= 1 affichage(pos) Else MsgBox("c'est le premier") End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Try If pos Then pos += 1 affichage(pos) Else MsgBox("c'est le dérnier") End If 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 Me.Hide() f1.Show() End SubEnd Class-----------------------------------------------------------------------------Imports System.Data.SqlClientPublic Class Recherche_Com_cli Private Sub Recherche_Com_cli_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO : cette ligne de code charge les données dans la table 'Gestion_commandeDataSet3.Client'. Vous pouvez la déplacer ou la supprimer selon vos besoins. Me.ClientTableAdapter.Fill(Me.Gestion_commandeDataSet3.Client) End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Me.Hide() f1.Show() End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click 'con.Close() Dim z As String Dim test As Integer test = 0 z = "select NumClient from Client where NumClient=" & Val(T1.Text) & "" Dim command As New SqlCommand(z, con) Try con.Open() Dim s As SqlDataReader = command.ExecuteReader Do While s.Read() Dim p As Integer p = Str(s.GetValue(0)) If T1.Text = p Then test = 1 End If Loop s.Close() con.Close() Catch ex As Exception MsgBox(ex.Message) End Try If test = 1 Then Dim l As String l = "select * from etatCommande where NumClient =" & Val(T1.Text) & "" Dim command1 As New SqlCommand(l, con) Try con.Open() Dim f As SqlDataReader = command1.ExecuteReader Do While f.Read() Dim p As String p = Str(f.GetValue(0)) + " " + f.GetValue(1) + " " + Str(f.GetValue(2)) L1.Items.Add(p) Loop f.Close() con.Close() Catch ex As Exception MsgBox(ex.Message) End Try Else MsgBox("le numéro de ce client n'existe pas") End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Hide() f1.Show() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click End End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click t1.Text = "" L1.Items.Clear() t1.Focus() End SubEnd Class----------------------------------------------------------------------------Imports System.Data.SqlClientModule tous Public con As New SqlConnection("server=(local);integrated security=SSPI;database=gestion commande") Public dset As New DataSet Public adp, adpPr, adpCm, adpEcm As New SqlDataAdapter Public tabcl, tabpr, tabcom, tabecom As New DataTable Public pos As Integer Public f1 As New Form1 Public f2 As New Client Public f3 As New Produit Public f4 As New Commande Public f5 As New EtatCommande Public f6 As New Recherche_Com_cli Public f7 As New commande_entre_2_datesEnd Module

Exercice VB: Les suites Mathématique addition

Objectif :

Travailler avec les Suites et Fonctions.

Travail à Faire :

1. Donnez un programme pour calculer :

    S = 1 – 1/2 + 1/3 – 1/4 + …… –1/2n + 1/2n + 1

2. Donnez un programme pour calculer :

    S = 1 + 1/2 + 2/3 + 3/4 + ………

3. Donnez un programme pour calculer :

    S = 1 – 1/3 + 1/4 – 1/6 + 1/7 + ……… 

4. Donnez un programme pour calculer :

    S = X1 + X3 /3 + X5 /5 + ……. + X2n+1/2n+1

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960611.Module Module1Dim N, i, S As DoubleSub Main()Console.Write("Entrez la valeur de N : ")N = Console.ReadLineS = 1For i = 1 To NS = S - (1 / (2 * i)) + (1 / (2 * i + 1))NextConsole.Write("S est : " & S)Console.ReadLine()End SubEnd Module2.Module Module1Dim N, i, S As DoubleSub Main()Console.Write("Entrez la valeur de N : ")N = Console.ReadLineS = 1For i = 1 To NS = S + (i / (i + 1))NextConsole.Write("S est : " & S)Console.ReadLine()End SubEnd Module3.Module Module1Dim N, i, S As DoubleSub Main()Console.Write("Entrez la valeur de N : ")N = Console.ReadLineS = 1For i = 1 To NS = S - (1 / (3 * i)) + (1 / (3 * i + 1))NextConsole.Write("S est : " & S)Console.ReadLine()End SubEnd Module4.Module Module1Dim P, i, S, X As DoubleSub Main()Console.Write("Entrez la valeur de X : ")X = Console.ReadLineConsole.Write("Entrez la puissance : ")P = Console.ReadLineS = 0For i = 0 To PS = S + (X ^ (2 * i + 1)) / (2 * i + 1)NextConsole.Write("S est : " & S)Console.ReadLine()End SubEnd Module
Article publié le 01 Janvier 2012 Mise à jour le Vendredi, 16 Décembre 2022 21:56 par Babachekhe Mohamed