1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
Public Class Form1 <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">Integer.TryParse<span class="br0">(</span><span class="br0">)</span></span> avec plus d'info <a href="https://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx" target="_blank">ici</a>
Cela te protégera des cas ou l'utilisateur envoi deux String dans les textbox.
si textbox1.text = "a" alors Textbox1.text * Textbox2.Text te lèvera une exception.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim resultat As Integer = calcul(TextBox1.Text,TextBox2.Text)
afficher(resultat)
End Sub
Private Function calcul(x As Integer, y As Integer) As Integer
Return x * y
End Function
Private Sub afficher(resultat As Integer)
MessageBox.Show(calcul(TextBox1.Text,TextBox2.Text)
End Sub
End Class |
Partager