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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
Imports System.Globalization
Public Class frmQICalcul
'Declare au niveau classe pour accessibilite
'une variable CultureInfo vers l'affichage anglais
'des nombres
Dim ci As CultureInfo = New CultureInfo("en-US")
'declare au biveau classe nos variables pour accessibilite
Dim valA As Double
Dim valB As Double
Dim valC As Double
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
A.ForeColor = Color.Red
B.ForeColor = Color.Red
C.ForeColor = Color.Red
'specifie affichage à 2 decimales
ci.NumberFormat.NumberDecimalDigits = 2
End Sub
Private Sub A_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles A.GotFocus
A.Text = ""
A.Refresh()
A.BackColor = Color.Blue
End Sub
Private Sub A_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles A.LostFocus
A.BackColor = Color.LightSlateGray
End Sub
Private Sub B_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles B.GotFocus
B.Text = ""
B.Refresh()
B.BackColor = Color.Blue
End Sub
Private Sub B_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles B.LostFocus
B.BackColor = Color.LightSlateGray
End Sub
Private Sub Buttonclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonclose.Click
Me.Close()
End Sub
'serieusement raccourci le calculate
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
valC = 0.0
If (valA <= 36 Or valA >= 40) Then
MessageBox.Show("Erreur : ValA n'est pas compris entre 36 et 40!!!")
Exit Sub
End If
If (valB <= 36 Or valB >= 40) Then
MessageBox.Show("Erreur : ValB n'est pas compris entre 36 et 40!!!")
Exit Sub
End If
Dim resultToDisplay = (-4 * (1 - ((valB) / (valA) ^ 2)))
'Affiche en "english"
C.Text = resultToDisplay.ToString(ci)
End Sub
'La fonction Double.TryParse ,comme toString est une fonction "shared"
'ou "partagee" qu'on peut appeler de partout.
'Redoutable .
'Lit en "english" , verifie si c'est un double
' renvoie le resultat dans valA
'Si valA =0 il y a erreur et 0.0 est affiche dans le controle A.text
Private Sub A_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles A.Validating
'Init valA
valA = 0.0
If Not Double.TryParse(A.Text, NumberStyles.AllowDecimalPoint, ci, valA) Then
MessageBox.Show("Erreur : " & TextBox1.Name.ToString & " n'est pas un Double!!!")
'Ecrit 0.0 dans A.text
A.Text = valA
Else
'simple label pourr le test
Me.LabelEcho.Text = valA.ToString(ci)
End If
End Sub
Private Sub B_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles B.Validating
valB = 0.0
If Not Double.TryParse(B.Text, NumberStyles.AllowDecimalPoint, ci, valB) Then
MessageBox.Show("Erreur : " & B.Name.ToString & " n'est pas un Double!!!")
B.Text = valB
Else
Me.LabelEcho.Text = valB.ToString(ci)
End If
End Sub
End Class |
Partager