VB.Net Changer le "." (point) par une "," (virgule)

Résolu
cs_JeffC1977 Messages postés 928 Date d'inscription vendredi 10 novembre 2000 Statut Membre Dernière intervention 23 septembre 2023 - 4 sept. 2007 à 13:18
cs_JeffC1977 Messages postés 928 Date d'inscription vendredi 10 novembre 2000 Statut Membre Dernière intervention 23 septembre 2023 - 5 sept. 2007 à 15:37
Salut...

Je suis à la recherche de comment faire pour que si l'utilisatuer utilise un point, dans mon textbox il y aura une virgule.

J'ai trouvé ce code sur vbfrance mais ca marche pas, j'ai une erreur... Si quelqu'un peut me donner un coup de main 

merci d'avance

P.S. Erreur en Gras et Souligné plus bas. 1.Handles clauses requires a WithEvents variable defined in the containing type or one of its bases types
2. Property 'KeyChar' is 'ReadOnly'

Private
Sub decimaltxt_KeyPress(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.KeyPressEventArgs)
Handles decimaltxt.KeyPress

'on accepte chiffres et virgule, ainsi que la touche back. On remplace un eventuel point par une virgule, et on refuse la saisie d'une virgule en tant que premier caractere
'remplacement du point par une virgule

If Asc(e.KeyChar) = 46
Then e.KeyChar =
","
'si c'est une virgule et qu'il y en a déja une dans le textbox, ou qu'elle est tappé en premier caractère, on annule la saisie
If Asc(e.KeyChar) = 44
And (
CType(sender, TextBox).Text.IndexOf(
",") > 0
Or
CType(sender, TextBox).Text =
"")
Then e.Handled =
True

End
Sub

3 réponses

cs_JeffC1977 Messages postés 928 Date d'inscription vendredi 10 novembre 2000 Statut Membre Dernière intervention 23 septembre 2023 4
5 sept. 2007 à 15:37
Voilà la solution...

Public
Sub TextBox_KeyPress(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.KeyPressEventArgs)
Handles txtNewPoint.KeyPress, txtPcode_.KeyPress, txtPoint1.KeyPress, txtPoint2.KeyPress, txtPoint3.KeyPress, txtPoint4.KeyPress, txtStation.KeyPress, txtBack.KeyPress, txtPointTA.KeyPress, txtPointSaisi.KeyPress, txtPcode.KeyPress, txtAzimutSaisi.KeyPress, txtDistanceSaisi.KeyPress, txtPoint1TA.KeyPress, txtPoint2TA.KeyPress, txtDirRefTA.KeyPress, txtPoint3TA.KeyPress, txtAzimutTA.KeyPress, txtDistanceTA.KeyPress, txtPcodeTA.KeyPress



' Remplace le point par une virgule

If
e.KeyChar = "."c

Then

CType
(sender, TextBox).SelectedText = ","c
e.Handled =

True

End



If

End



Sub
3
cs_JeffC1977 Messages postés 928 Date d'inscription vendredi 10 novembre 2000 Statut Membre Dernière intervention 23 septembre 2023 4
4 sept. 2007 à 18:43
Re...
J'ai résolu un erreur mais ma je n'arrive pas à résoudre la première condition car c'est du .NET Framework et je suis en compact Framework...

Si quelqu'un peut me donner un coup de main...

merci.

Private
Sub Decimaltxt_KeyPress(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.KeyPressEventArgs)
Handles
Me.KeyPress

If Asc(e.KeyChar) = 46
Then
",",
"." ) 'The targeted version of the .Net Compact Framework does not support latebinding

If Asc(e.KeyChar) = 44
And (
CType(sender, TextBox).Text.IndexOf(
",") > 0
Or
CType(sender, TextBox).Text =
"")
Then e.Handled =
True

End
Sub
0
cs_JeffC1977 Messages postés 928 Date d'inscription vendredi 10 novembre 2000 Statut Membre Dernière intervention 23 septembre 2023 4
4 sept. 2007 à 20:38
Bon le code a encore changer. Mon seul problème est que ca devrait marcher mais ca marche pas...

Sub TextBox_KeyPress(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.KeyPressEventArgs)

If e.KeyChar = "."c
Thene.KeyChar = ","c

If Asc(e.KeyChar) = 44
And (
CType(sender, TextBox).Text.IndexOf(
",") > 0
Or
CType(sender, TextBox).Text =
"")
Then e.Handled =
True
End
Sub

Erreur disant : Property 'KeyChar' is 'ReadOnly'

Pourquoi je suis en lecture seul   Je ne comprends rien... ???

merci de votre aide
0
Rejoignez-nous