bouv
Messages postés1411Date d'inscriptionmercredi 6 août 2003StatutMembreDernière intervention 3 mars 20191 22 sept. 2005 à 18:03
On peut aussi faire
Private Sub Form_KeyPress(KeyAscii As Integer)
Const AutorizedChars = "0123456789" & Chr$(25)
If Instr(AutorizedChars, Chr$(KeyAscii)) 0 then KeyAscii 0
End Sub
ou
Private Sub Form_KeyPress(KeyAscii As Integer)
Const RestrictedChars = "LJBDVLKUH" & Chr$(13) & Chr$(8)
If Not Instr(RestrictedChars, Chr$(KeyAscii)) 0 then KeyAscii 0
End Sub
Totoroyamada
Messages postés31Date d'inscriptionjeudi 26 mai 2005StatutMembreDernière intervention17 novembre 2005 22 sept. 2005 à 16:39
Ok, c'est juste que moi quand dans Visual Studio j'écris
Private Sub toto(tutu As Integer)
...
End Sub
il me corrige ça tout seul en
Private Sub toto(ByVal tutu As Integer)
...
End Sub
et j'ai beau vouloir enlever le "ByVal", il me le remet automatiquement... d'où la nécessité de préciser moi-même ByRef...
'fin bon disons qu'on avait tous les deux à moitié raison ;-)
cs_DARKSIDIOUS
Messages postés15814Date d'inscriptionjeudi 8 août 2002StatutMembreDernière intervention 4 mars 2013130 22 sept. 2005 à 16:32
Et non TOTOROYAMADA, le ByRef, si on ne le mais pas dans la déclaration d'un sub, il est pris par défaut, par contre, c'est vrai qu'il faut enlever le As Integer, donc ca donne :
Private Sub Bad_Char(KeyAscii As Integer)
Select Case KeyAscii
Case 49, 50, 51, 52, 53, 54, 55, 56, 57, 58: KeyAscii = 0
End Select
End Sub
Private Sub Text1_Change()
Bad_Char (KeyAscii)
End Sub
Totoroyamada
Messages postés31Date d'inscriptionjeudi 26 mai 2005StatutMembreDernière intervention17 novembre 2005 22 sept. 2005 à 15:19
Je peux me tromper (parce que là tout de suite je peux pas tester), mais ton truc ne doit pas marcher DS...
Il faut soit faire
KeyAscii = Bad_Char(KeyAscii)
soit déclarer ta sub comme ça:
Sub Bad_Char(ByRef KeyAscii As Integer)
...
End Sub
cs_DARKSIDIOUS
Messages postés15814Date d'inscriptionjeudi 8 août 2002StatutMembreDernière intervention 4 mars 2013130 22 sept. 2005 à 14:51
Tu peux également utiliser une Sub, avec une utilisation encore plus simple :
1. Private Sub Form_KeyPress(KeyAscii As Integer)
2. Bad_Char(KeyAscii)
3. End Sub
4.
5. Sub Bad_Char(KeyAscii As Integer) As Integer
6. Select Case KeyAscii
7. Case 62, 60, 34, 63, 42, 58, 92, 46, 47, 124: KeyAscii = 0
8. End Select
9. End Sub
22 sept. 2005 à 18:03
Private Sub Form_KeyPress(KeyAscii As Integer)
Const AutorizedChars = "0123456789" & Chr$(25)
If Instr(AutorizedChars, Chr$(KeyAscii)) 0 then KeyAscii 0
End Sub
ou
Private Sub Form_KeyPress(KeyAscii As Integer)
Const RestrictedChars = "LJBDVLKUH" & Chr$(13) & Chr$(8)
If Not Instr(RestrictedChars, Chr$(KeyAscii)) 0 then KeyAscii 0
End Sub
22 sept. 2005 à 16:39
Private Sub toto(tutu As Integer)
...
End Sub
il me corrige ça tout seul en
Private Sub toto(ByVal tutu As Integer)
...
End Sub
et j'ai beau vouloir enlever le "ByVal", il me le remet automatiquement... d'où la nécessité de préciser moi-même ByRef...
'fin bon disons qu'on avait tous les deux à moitié raison ;-)
22 sept. 2005 à 16:32
Private Sub Bad_Char(KeyAscii As Integer)
Select Case KeyAscii
Case 49, 50, 51, 52, 53, 54, 55, 56, 57, 58: KeyAscii = 0
End Select
End Sub
Private Sub Text1_Change()
Bad_Char (KeyAscii)
End Sub
22 sept. 2005 à 15:19
Il faut soit faire
KeyAscii = Bad_Char(KeyAscii)
soit déclarer ta sub comme ça:
Sub Bad_Char(ByRef KeyAscii As Integer)
...
End Sub
22 sept. 2005 à 14:51
1. Private Sub Form_KeyPress(KeyAscii As Integer)
2. Bad_Char(KeyAscii)
3. End Sub
4.
5. Sub Bad_Char(KeyAscii As Integer) As Integer
6. Select Case KeyAscii
7. Case 62, 60, 34, 63, 42, 58, 92, 46, 47, 124: KeyAscii = 0
8. End Select
9. End Sub