- Visual Basic / VB.NET : Controle de saisie simple d'un nombre décimal pour eviter les erreurs
- Algo. *** parfait et infaillible *** pour la saisie d'un nombre décimal et/ou négatif
- Delphi / Pascal : Arrondir un nombre décimal (formatfloat) - saisie valide de ce nombre - Cod
- Saisir un nombre décimal dans un textox
- Saisie d'un nombre décimal
31 mars 2006 à 11:27
Finalement le code de PCPunch devient presque aussi long, surtout quand il y a plusieurs textbox.
26 avril 2004 à 16:21
Allez comme ça on va stopper la discution, une petite fonction qui permet de definir le nombre de décimal aprés la virgule :
Private Sub Text1_KeyPress(KeyAscii As Integer)
If InStr(Text1, ",") <> 0 And KeyAscii 46 Then KeyAscii 0: Exit Sub
If NbDeci(Text1, 2) <> True And KeyAscii <> 8 Then KeyAscii = 0: Exit Sub
If KeyAscii 46 Then KeyAscii 44
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 And KeyAscii <> 44 Then KeyAscii = 0
End Sub
Public Function NbDeci(Src As TextBox, nb As Integer) As Boolean
'Src le textbox Nb le nombre de décimal autorisé
Dim Pos As Integer
Dim Decim As String
Pos = InStr(Src, ",")
If Pos <> 0 Then
Decim = Mid(Src, Pos + 1, Len(Src) - Pos + 1)
If Len(Decim) nb Then NbDeci False Else NbDeci = True
Else
NbDeci = True
End If
End Function
Voila , je pense qu'il n'y a plus rien a ajouter maintenant ????
26 avril 2004 à 16:12
26 avril 2004 à 16:07
Private Sub Text1_KeyPress(KeyAscii As Integer)
If InStr(Text1, ",") <> 0 And KeyAscii 46 Then KeyAscii 0: Exit Sub
If KeyAscii 46 Then KeyAscii 44
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 And KeyAscii <> 44 Then KeyAscii = 0
End Sub
26 avril 2004 à 15:47
Faut vraiment tout te faire letrust :
Dim Virgule As Boolean
Private Sub Form_Load()
Virgule = False
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii 46 And Not Virgule Then KeyAscii 44: Virgule = True
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 And KeyAscii <> 44 Then KeyAscii = 0
End Sub
++