CALCULATRICE EN VB

Signaler
Messages postés
22
Date d'inscription
vendredi 11 novembre 2005
Statut
Membre
Dernière intervention
23 septembre 2014
-
Messages postés
22
Date d'inscription
vendredi 11 novembre 2005
Statut
Membre
Dernière intervention
23 septembre 2014
-
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/52757-calculatrice-en-vb

Messages postés
22
Date d'inscription
vendredi 11 novembre 2005
Statut
Membre
Dernière intervention
23 septembre 2014

Un premier commentaire rapide sur ton code, tu peux l'optimiser :

# Private Sub one_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles one.Click
# chaine = chaine + "1"
# result.Text = chaine
#
# End Sub
#
# Private Sub two_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles two.Click
# chaine = chaine + "2"
# result.Text = chaine
# End Sub
#
# Private Sub three_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles three.Click
# chaine = chaine + "3"
# result.Text = chaine
# End Sub
#
# Private Sub four_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles four.Click
# chaine = chaine + "4"
# result.Text = chaine
# End Sub
# Private Sub five_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles five.Click
# chaine = chaine + "5"
# result.Text = chaine
# End Sub
#
# Private Sub six_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles six.Click
# chaine = chaine + "6"
# result.Text = chaine
# End Sub
#
# Private Sub seven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles seven.Click
# chaine = chaine + "7"
# result.Text = chaine
# End Sub
#
# Private Sub eight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eight.Click
# chaine = chaine + "8"
# result.Text = chaine
# End Sub
#
# Private Sub nine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nine.Click
# chaine = chaine + "9"
# result.Text = chaine
# End Sub

Tu peux le transformer en

Private Sub number_Click(ByVal sender As System.Object, ByVale e As System.EventArgs) Handles one.Click, two.Click, three.Click, four.Click, five.Click, six.Click, seven.Click, eight.Click, nine.Click
chaine += CType(sender, Button).Text
result.Text = chaine
End Sub