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
|
Imports System.Globalization
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim duree, cout, profit as Integer
Dim montant, renta as Decimal
// test si ta textBox n'est pas vide
If String.IsNullOrEmpty(tTextBoxDurée.Text)
duree = TextBoxDurée.Text
cout = duree * 150
TextBoxCoût.Text = cout
End If
If String.IsNullOrEmpty(TextBoxMontant.Text)
montant = TextBoxMontant.Text
profit = montant - cout
TextBoxProfit.Text = profit
renta = (profit / montant) * 100
// appel à ta fonction 'formater' avec le paramètre renta
TextBoxRenta.Text = formater(renta)
End If
End Sub
// fonction qui transforme un décimal au format xx,xx
Private Function formater(ByVal renta As Decimal) As String
Dim formatNombre As NumberFormatInfo = New CultureInfo("fr-FR", False).NumberFormat
Dim rentaString As String
Dim rentaFinal As String
rentaString = renta.ToString("C", formatNombre)
rentaFinal = rentaString .Substring(0, rentaString.ToString.Length - 1)
Return valFinal
End Function
End Class |
Partager