Bonjour!
Ce n'est pas un masque de saisie mais c'est tout comme.
C'est surtout pour aider les personnes pour qui c'est d'actualité en ce moment:
ip_Change() est une macro qui faut rattacher au textbox concerné.
Private Sub ip_Change()
Dim element As Integer
Dim cpt As Integer
element = UBound(Split(ip, "."))
If Not IsNumeric(Right(ip, 1)) And Right(ip, 1) <> "." And Right(ip, 1) <> "" Then
MsgBox "Le caractere saisi doit être un chiffre", vbExclamation
ip = Left(ip, Len(ip) - 1)
Exit Sub
End If
If Right(ip, 1) "." And InStr(ip, ".") 1 Then
MsgBox "Format incorrecte", vbExclamation
ip = Left(ip, Len(ip) - 1)
ElseIf Right(ip, 1) = "." And InStr(ip, ".") <> 1 Then
For cpt = 0 To element - 1
If Not IsNumeric(Split(ip, ".")(cpt)) Then
MsgBox "Format incorecte", vbExclamation
ip = Left(ip, Len(ip) - (Len(Split(ip, ".")(cpt)) + 1))
Exit Sub
ElseIf CInt(Split(ip, ".")(cpt)) > 255 Then
MsgBox "Format incorecte", vbExclamation
ip = Left(ip, Len(ip) - (Len(Split(ip, ".")(cpt)) + 1))
Exit Sub
End If
Next cpt
If nbOccurences(".", ip.Value) > 3 Then
MsgBox "Format incorecte", vbExclamation
ip = Left(ip, Len(ip) - 1)
Exit Sub
End If
End If
If nbOccurences(".", ip.Value) = 3 And ip.Value <> "" Then
If Split(ip, ".")(element) <> "" Then
If (CInt(Split(ip, ".")(element)) > 255) Then
MsgBox "Format incorecte", vbExclamation
ip = Left(ip, Len(ip) - 1)
Exit Sub
End If
End If
End If
End Sub
Public Function nbOccurences(car As String, chaine As String) As Integer
Dim i As Integer, res As Integer
res = 0
For i = 1 To Len(chaine)
If Mid(chaine, i, 1) = car Then
res = res + 1
End If
Next
nbOccurences = res
End Function