Public Class Form1
Dim Sep As Char
Dim Nombre As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Nombre = CDbl(TextBox1.Text)
Label1.Text = Nombre
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Détecter le séparateur décimale de l'application.
Sep = Application.CurrentCulture.NumberFormat.NumberDecimalSeparator
TextBox1.Focus()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not (Char.IsNumber(e.KeyChar) Or e.KeyChar.Equals(Sep) Or Char.IsControl(e.KeyChar)) Then e.Handled = True
End Sub
End Class
Public Class Form2
Dim Sep As Char
Dim Nombre As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Applique()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Détecter le séparateur décimale de l'application.
Sep = Application.CurrentCulture.NumberFormat.NumberDecimalSeparator
End Sub
Private Sub Data_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Data.KeyDown
If e.KeyCode = 13 Then
Applique()
End If
End Sub
Private Sub Data_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Data.TextChanged
If Data.Text = Sep Then
'si le séparateur décimal est taper directement
Data.Text = "0" & Sep
Data.SelectionStart = Len(Data.Text)
ElseIf Not IsNumeric(Trim(Data.Text)) Then
Beep()
If Len(Data.Text) < 1 Then
Data.Text = ""
Else
Data.Text = Microsoft.VisualBasic.Left(Data.Text, Len(Data.Text) - 1)
Data.SelectionStart = Len(Data.Text)
End If
End If
End Sub
Sub Applique()
Dim DT As String
'Pour adapter à la configuration du PC hôte.
DT = Replace(Data.Text, ".", Sep)
DT = Replace(DT, ",", Sep)
Label1.Text = CDbl(DT)
On Error Resume Next
Data.SelectionStart = 0
Data.SelectionLength = Len(Data.Text)
Data.Focus()
End Sub
End Class
| VBA.VB6 - Fonction d'arrondi Supp/Inférieur à n décimales | Programmation - Comment débuter, quel langage? |
Combien cela coûte-t-il au total ? Quelles aides apportent l'état et les acteurs du marché pour alléger cette charge non choisie ? Tous les détails sur Commentçamarche.net.