Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

TextBox format pourcentage

2 réponses
Avatar
pierref
bonjour,

je voudrais v=E9rifier que la saisie d'une textbox soit sous=20
la forme d'un pourcentage cad 0,5 ou 0,05 ou 50,05 ou 100=20
ou 05,005 etc..

j'ai ecris le code suivant :

Private Sub Tb_pourc_Change()

If Format(Tb_pourc.Text) <> "000,000" Then
MsgBox "Format du pourcentage incorrect", vbOKOnly
Tb_pourc.Text =3D "00,00"
End If

End Sub

Ca ne marche pas !!

merci de m'aider=20

pierref

ps : j'insiste sur le fait qu'il me faut une virgule et=20
non un point dans le format.

2 réponses

Avatar
pierref
lol en fait jai trouvé la solution tout seul comme un
grand :

Dim test As Double

On Error GoTo erreur
test = CDbl(Tb_pourc.Text)

Exit Sub

erreur:
MsgBox "Format du pourcentage incorrect", vbOKOnly
Tb_pourc.Text = "00,00"


si qq'un a mieux, quil n'hésite pas !
d'ailleurs j'utilise la fonction textbox_Change
est ce que un truc comme lostfocus marche ??

a +

-----Message d'origine-----
bonjour,

je voudrais vérifier que la saisie d'une textbox soit
sous

la forme d'un pourcentage cad 0,5 ou 0,05 ou 50,05 ou 100
ou 05,005 etc..

j'ai ecris le code suivant :

Private Sub Tb_pourc_Change()

If Format(Tb_pourc.Text) <> "000,000" Then
MsgBox "Format du pourcentage incorrect", vbOKOnly
Tb_pourc.Text = "00,00"
End If

End Sub

Ca ne marche pas !!

merci de m'aider

pierref

ps : j'insiste sur le fait qu'il me faut une virgule et
non un point dans le format.


.



Avatar
Ellimac
Bonjour,

Tu peux traiter l'évènement sur sortie avec un :
ContrôleSuivant.SetFocus

Et sur Entrée du ContrôleSuivant :
On Error GoTo erreur
test = CDbl(Tb_pourc)
If Tb_pourc< 0 Or Tb_pourc> 100 Then GoTo erreur
Exit Sub

erreur:
MsgBox "Format du pourcentage incorrect", vbOKOnly
Tb_pourc.SetFocus
Tb_pourc= "00,00"

Camille

-----Message d'origine-----
bonjour,

je voudrais vérifier que la saisie d'une textbox soit
sous

la forme d'un pourcentage cad 0,5 ou 0,05 ou 50,05 ou 100
ou 05,005 etc..

j'ai ecris le code suivant :

Private Sub Tb_pourc_Change()

If Format(Tb_pourc.Text) <> "000,000" Then
MsgBox "Format du pourcentage incorrect", vbOKOnly
Tb_pourc.Text = "00,00"
End If

End Sub

Ca ne marche pas !!

merci de m'aider

pierref

ps : j'insiste sur le fait qu'il me faut une virgule et
non un point dans le format.


.