0/5 (20 avis)
Snippet vu 32 326 fois - Téléchargée 29 fois
'Cette fonction supprime n'importe quel caractère du string strA passé en premier argument ' exemple : ' toto="azè-e(r(tè-y" ' toto=Strip(toto,"(","è","-") ' donne "azerty" Function Strip(strA As String, ParamArray varZoek()) Dim intTel As Integer Dim strNew As String Dim varteken As Variant Dim strTekst As String strTekst = strA For Each varteken In varZoek() strNew = "" For intTel = 1 To Len(strTekst) If Mid(strTekst, intTel, 1) <> varteken Then strNew = strNew & Mid(strTekst, intTel, 1) End If Next strTekst = strNew Next Strip = strNew End Function
8 juin 2006 à 11:57
une solution possible :
Private Const ES_UPPERCASE As Long = &H8&
Private Const GWL_STYLE As Long = -16
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Sub Form_Load()
SetWindowLong Text1.hwnd, GWL_STYLE, ES_UPPERCASE Or (GetWindowLong(Text1.hwnd, GWL_STYLE))
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If InStrB("1234567890ABCDEFabcdef" & Chr$(8) & Chr$(24) & Chr$(22) & Chr$(3), Chr$(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub
attention, tu peux ici coller des valeurs interdites...
8 juin 2006 à 11:55
il faut traiter la valeur ascii dans la fonction keypress .... il faut, je crois, mettre ascii = 0 pour les caracteres qui ne sont pas permis !
8 juin 2006 à 11:53
8 juin 2006 à 11:42
je débute et je voudrais savoir comment faire pour écrire seulement "1234567890ABCDEF" et que les autres caractères ne s'écrivent pas m^me si on appuie dessus...
merci
23 févr. 2006 à 23:47
Function Strip(ByVal strA As String, ByVal ParamArray varZoek() As String)
' Merci Jean Elens
Dim intTel As Integer
Dim strNew As String
Dim varteken As Object
Dim strTekst As String
strTekst = strA
For Each varteken In varZoek
strNew = ""
'For intTel = 1 To Len(strTekst)
' If Mid(strTekst, intTel, 1) <> varteken Then
' strNew = strNew & Mid(strTekst, intTel, 1)
' End If
'Next
strNew = Replace(strTekst, varteken, "")
strTekst = strNew
MessageBox.Show(strNew, "Strip", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Next
Strip = strNew
End Function
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.