Exercice Visual Basic : Recherche dans une Phrase

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

ExerciceVB-id2134


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Option Strict On
Option Explicit On 
Public Class Form1
    Inherits System.Windows.Forms.Form
    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
 
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim caractererecherche As Char
        Dim resultatrecherche As Int32
        resultatrecherche = 0
        If Me.Txtcible.Text.Length = 0 Then
            MessageBox.Show("vous n'avez pa entrez de caractère")
        Else
            caractererecherche = Txtcible.Text.Chars(0)
            If Me.CheckBox1.Checked Then
                resultatrecherche = recherchecaractere(Me.TextBox1.Text, caractererecherche)
            End If
            If Me.CheckBox2.Checked Then
                resultatrecherche = resultatrecherche + recherchecaractere(Me.TextBox2.Text, caractererecherche)
            End If
            If Me.CheckBox3.Checked Then
                resultatrecherche = resultatrecherche + recherchecaractere(Me.TextBox3.Text, caractererecherche)
            End If
        End If
        Me.txtnboccurence.Text = resultatrecherche.ToString
    End Sub
 
    Private Function recherchecaractere(ByVal zone As String, ByVal caractererecherche As Char) As Int32
        Dim longzone As Int32
        Dim i As Int32
        Dim caractereelementaire As Char
        Dim nboccurence As Int32
        nboccurence = 0
        longzone = zone.Length
        For i = 0 To longzone - 1
            caractereelementaire = zone.Chars(i)
            If caractereelementaire = caractererecherche Then
                nboccurence = nboccurence + 1
            End If
        Next
        recherchecaractere = nboccurence
    End Function
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
 
    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
        Dim i As Integer
        For i = 0 To 100
            Label1.Text = i.ToString : Label1.Refresh()
        Next i
    End Sub
 
 
End Class