Академический Документы
Профессиональный Документы
Культура Документы
QBADOU
VB.NET
Programmation Evnementielle
VB.NET
Cours
Applications
1
VB.NET
OBJECTIFS
Professeur M.QBADOU
VB.NET
SOMMAIRE
Professeur M.QBADOU
Chap. I
Elments du langage VB
Exemples dapplications consoles
Chap. II : interfaces graphiques avec VB.NET
Contrles standards
Professeur M.QBADOU
VB.NET
Chap. I
Elments du
langage
VB.NET
VB.NET
Professeur M.QBADOU
Sommaire
Notion de donnes et de types
Les Instructions Entre/Sortie
Lopration daffectation et oprateurs
Les structures de contrle
Conditionnelle, slective, rptitives
Structure dun module VB.NET
Fonctions et procdures
VB.NET
Professeur M.QBADOU
Type
VB
Type .NET
quivalent
Dclaration de variable/Constante
Taille
(en Octets)
Boolean
System.Boolean
Byte
System.Byte
Char
System.Char
Date
System.DateTime
Decimal System.Decimal
16
Double
System.Double
Integer
System.Int32
Long
System.Int64
Object
System.Object
Short
System.Int16
Single
System.Single
String
System.String
100000L
Double
134.789, -45E-18
Single
134.789F, -4.5E-18F
Decimal
100000D
Char
"A"c
String
"aujourd'hui"
Boolean
true, false
Date
VB.NET
objet.ToString
Integer.Parse(chaine) ou Int32.Parse(chaine)
Long.Parse(chaine) ou Int64.Parse
Double.Parse(chane)
Single.Parse(chane)
traitement de l'exception e
7
end try
VB.NET
Exemple
Option Strict On ' directive
Professeur M.QBADOU
Imports System.Console
Dim i1 As Integer
Try
i1 = Integer.Parse("10.67") 'chane-->int
afficher(i1.ToString)
Catch e As Exception
Public Sub afficher(ByVal S As String)
afficher("Erreur [10.67] : " + e.Message)
WriteLine("S=" + S)
End Try
End Sub
' chane --> double
Sub Main()' procdure principale
Dim d1 As Double
' donnes locales
Try
Dim l as long=100
d1 = Double.Parse(" 100.87 ")
Const i As Integer = 10
afficher("" & d1)
Const f As Single = 45.78F
Catch e As Exception
' nombre --> chane
afficher("Erreur [100.87] : " +e.Message)
afficher(CType(i, String))
End Try
afficher(CType(l, String))
End Sub
afficher(CType(f, String))
End Module
Module TestConversion
VB.NET
Professeur M.QBADOU
UC - Mmoire
Clavier
Ecran
4
5
1. lecture d'informations provenant du clavier
Disque
2. traitement d'informations(calculs)
3. criture d'informations l'cran
VB.NET
Professeur M.QBADOU
VB.NET
Professeur M.QBADOU
11
Catch e As FormatException
WriteLine(e.Message)
Sub Main()
End Try
Dim nom As String
WriteLine("Nom : " + nom)
Dim adresse As String
WriteLine("Adresse:"+ adresse)
Dim age As Byte
WriteLine("Age:"+age.ToString)
Write("nom : ") : nom = ReadLine()
ReadLine()
Write("Adresse: ") : adresse= ReadLine()
End Sub
Try
End Module
Write("Age : ")
age = Byte.Parse(ReadLine())
VB.NET
nomVar = expression
12
Oprateurs
Arithmtique
^, , *, /, \,
Mod , +
Affectation
Relationnelle
Concatnation
&,+
Logique/
binaire
Autres
AddressOf , GetType
Priorit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Oprateurs
()
^
Unaire : - , +
*, /
\
Mod
+, &
<<, >>
=, <>,<,>, <=, >=, Like, Is,TypeOf...Is
Not
And, AndAlso
Or, OrElse
Xor
VB.NET
Fonctions et constantes
Cos, Sin, Tan, Acos, Asin, Atan2,
Cosh, Sinh, tanh,
Sqrt, Pow, Exp, Log, Log10,
Abs, Floor, Ceiling Round,
Max, Min,
r2 = Math.Sqrt(Math.E^9)
r1 = Math.Cos(Math.PI/3)
Description
StrComp
InStrRev, StrReverse
Len
InStr, Left, LTrim, Mid, Right, RTrim, Trim Manipuler des chanes.
13
Replace
Filter
Split, Join
VB.NET
Professeur M.QBADOU
14
if condition then
actions_si_vrai
[else
actions_sinon]
end if
Condition
Action
VB.NET
Professeur M.QBADOU
Action
...
[blocAction]
Loop { While | Until } condition
Condition
Action
Action
...
Condition
...
VB.NET
Professeur M.QBADOU
Option Explicit On
Imports System.Console
Imports System.IO
Module Essai
Dim rep As DirectoryInfo
Sub Main()
WriteLine(Environment.GetEnvironmentVariable("windir"))
rep=New DirectoryInfo(Environment.CurrentDirectory())
WriteLine(rep.FullName)
ReadKey()
16
End Sub
End Module
Professeur M.QBADOU
VB.NET
17
End Module
VB.NET
Professeur M.QBADOU
VB.NET
Exemple
Professeur M.QBADOU
Option Strict On
19
Imports System.Console
Module testTableaux
Sub main()
' un premier tableau une dim
Dim tab0(5) As Integer,i as Integer, j as Integer
For i = 0 To UBound(tab0)
tab0(i) = i
Next
For i = 0 To UBound(tab0)
WriteLine("tab0(" + i.ToString + ")=" + tab0(i).tostring)
Next
' un second tableau 1 dim
Dim tab1() As Integer = New Integer(5) {}
For i 0 To tab1.Length - 1
tab1(i) = i * 10
Next
VB.NET
Exemple(suite)
For i = 0 To tab1.Length - 1
Professeur M.QBADOU
For j = 0 To tab2.GetLength(1) - 1
tab2(i, j) = i * 10 + j
Next
Next
For i = 0 To UBound(tab2)
For j = 0 To tab2.GetLength(1) - 1
WriteLine("tab2(" + i.ToString + "," + j.ToString + ")=" + tab2(i, j).tostring)
Next
Next
20
VB.NET
Professeur M.QBADOU
Exemple(suite)
21
VB.NET
Exemple(fin)
Dim noms()() As String = New String(3)() {} ' un tableau de tableaux de texte
Professeur M.QBADOU
For i = 0 To noms.Length- 1
End Module
22
VB.NET
Professeur M.QBADOU
23
try
Lobjet e de la classe Exception fournie :
Action exception
La proprit Message contenant le dtail l'erreur
catch e as Exception
traiter l'exception e
La mthode ToString qui rend un texte indiquant le
[finally
type de l'exception et la valeur de la proprit
Action excute toujours]
end try
Message.
VB.NET
Professeur M.QBADOU
8.1. Fonction
24
8.2. Procdure
Sub nomfonction( [{byVal|byRef}] arg as type[, ])
Actions
[if Exit Sub]
[Actions]
End Sub
VB.NET
Professeur M.QBADOU
C:\...\dossierApp>vbc nomapp.vb
Assurez vous que la variable environnement path rfrence bien le
compilateur VB.NET VBC.Exe. Pour cela tapez la command path
Professeur M.QBADOU
VB.NET
26
VB.NET
Exemples
dApplications
Consoles
VB.NET
Professeur M.QBADOU
Spcification
Ventes : -1, 1400,
Gestion
Ventes
27
VenteMin
VenteMoy
VenteMax
NbreVentes
VB.NET
Organigramme
Dbut
Vente 0
Professeur M.QBADOU
Som 0
Nbre 0
Saisir(Vente)
Min Vente
Min Vente
Max Vente
Nbre > 0
Max Vente
Som Som +Vente
Nbre Nbre + 1
28
Moy Som/Nbre
Afficher(Min, Moy,Max)
Afficher(Nbre)
Lire(Vente)
Fin
VB.NET
Professeur M.QBADOU
Code
29
VB.NET
Professeur M.QBADOU
L'affichage de la liste
30