Inscris-toi pour écrire dans l'encyclopédie Wikimini!

Visual Basic

« Visual Basic » défini et expliqué aux enfants par les enfants.
Aller à : navigation, rechercher

Visual Basic est un langage de programmation dérivé du BASIC créé par Microsoft. Il est apparu pour la première fois en 1991. Il permet de créer des applications rapidement, facilement et avec une interface graphique.

Langages dérivés de Visual Basic

Exemple de codage

  • Navigateur (Programmation orienté objet) :


Public Class Navigateur
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, _
ByVal wParam As Integer, ByVal lParam As String) As Integer
Private Declare Sub ReleaseCapture Lib "user32" ()

Private Sub Barre_mousedown(sender As System.Object, e As System.EventArgs) Handles BARRE.MouseDown

Dim lHwnd As Int32
lHwnd = Me.Handle
If lHwnd = 0 Then Exit Sub
ReleaseCapture()
SendMessage(lHwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)


End Sub

Private Sub txt_copier_Click(sender As System.Object, e As System.EventArgs) Handles txt_copier.Click
WebBrowser1.GoBack()
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
WebBrowser1.GoForward()
End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
WebBrowser1.Refresh()
End Sub

Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
WebBrowser1.Stop()
End Sub

Private Sub Navigateur_Load(sender As Object, e As System.EventArgs) Handles Me.Load
WebBrowser1.Navigate("http://www.google.be")
End Sub


Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
WebBrowser1.ShowPrintPreviewDialog()
End Sub

Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
WebBrowser1.Navigate("http://www.google.be")
End Sub

Private Sub Button10_Click(sender As System.Object, e As System.EventArgs) Handles Button10.Click
My.Settings.NUMFAVORI = My.Settings.NUMFAVORI + 1
My.Settings.Save()
If My.Settings.NUMFAVORI = 4 Then
My.Settings.NUMFAVORI = 1
My.Settings.Save()
End If
If My.Settings.NUMFAVORI = 1 Then
My.Settings.fAVORI1 = WebBrowser1.Url.ToString
My.Settings.Save()
ElseIf My.Settings.NUMFAVORI = 2 Then
My.Settings.FAVORI2 = WebBrowser1.Url.ToString
My.Settings.Save()
ElseIf My.Settings.NUMFAVORI = 3 Then
My.Settings.FAVORI3 = WebBrowser1.Url.ToString
My.Settings.Save()
End If
End Sub

Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
WebBrowser1.Navigate(My.Settings.fAVORI1)
End Sub

Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
WebBrowser1.Navigate(My.Settings.FAVORI2)
End Sub

Private Sub Button9_Click(sender As System.Object, e As System.EventArgs) Handles Button9.Click
WebBrowser1.Navigate(My.Settings.FAVORI3)
End Sub

Private Sub Navigateur_FormClosed(sender As System.Object, e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed

End Sub

Private Sub Button11_Click(sender As System.Object, e As System.EventArgs) Handles Button11.Click
WebBrowser1.Navigate("https://www.google.be/search?q=" & TextBox1.Text)
End Sub
End Class



  • Calculatrice (sans interface graphique) :


Module Module1

Sub Main()
Dim Entree As String
Dim Nombre1 As Integer
Dim Nombre2 As Integer
Console.Beep(500, 100)
Console.WriteLine("Que veux tu faire ? M pour multiplication, D pour division, A pour addition et S pour soustraction")
Entree = Console.ReadLine
If Entree = "M" Then
Console.Beep(500, 100)
Console.WriteLine("Entre le nombre 1")
Nombre1 = Console.ReadLine
Console.Beep(500, 100)
Console.WriteLine("Entre le nombre 2")
Nombre2 = Console.ReadLine
Console.Beep(500, 100)
Console.WriteLine(Nombre1 & "x" & Nombre2 & "=" & Nombre1 * Nombre2)
ElseIf Entree = "D" Then
Console.Beep(500, 100)
Console.WriteLine("Entre le nombre 1")
Nombre1 = Console.ReadLine
Console.Beep(500, 100)
Console.WriteLine("Entre le nombre 2")
Nombre2 = Console.ReadLine
Console.Beep(500, 100)
Console.WriteLine(Nombre1 & "/" & Nombre2 & "=" & Nombre1 / Nombre2)
ElseIf Entree = "A" Then
Console.Beep(500, 100)
Console.WriteLine("Entre le nombre 1")
Nombre1 = Console.ReadLine
Console.Beep(500, 100)
Console.WriteLine("Entre le nombre 2")
Nombre2 = Console.ReadLine
Console.Beep(500, 100)
Console.WriteLine(Nombre1 & "+" & Nombre2 & "=" & Nombre1 + Nombre2)
Else
Console.Beep(500, 100)
Console.WriteLine("Entre le nombre 1")
Nombre1 = Console.ReadLine
Console.Beep(500, 100)
Console.WriteLine("Entre le nombre 2")
Nombre2 = Console.ReadLine
Console.Beep(500, 100)
Console.WriteLine(Nombre1 & "-" & Nombre2 & "=" & Nombre1 - Nombre2)
End If
Console.ReadKey()
Console.Beep(500, 100)
End Sub

End Module

Wikiboo Outils personnels