Bonjour,
je voudrais crér une fonction qui détermine si une chaine de charactères est bien une adresse IP et si oui, la converti en un Long, malheurreusement, j'ai des problèmes d'overflow pour une adresse du genre 193.191.242.1

Voici le code développé :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Function ValidIp(ByVal strIP As String, ByRef lgIP As Long) As Boolean
 
Dim reg As New VBScript_RegExp_55.RegExp
Dim regMatches As VBScript_RegExp_55.MatchCollection
Dim regMatch As VBScript_RegExp_55.Match
 
 
reg.Pattern = "^((25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(25[0-5]|2[0-4]\d|1?\d?\d)$"
If reg.Test(strIP) Then
    ValidIp = True
    reg.Global = True
    reg.Pattern = "((25[0-5]|2[0-4]\d|1?\d?\d))"
    Set regMatches = reg.Execute(strIP)
    i = 3
    lgIP = 0
    For Each regMatch In regMatches
 
        lgIP = lgIP + CLng((CLng(regMatch.Value) * CLng(CLng(256) ^ i)))
        i = i - 1
 
    Next
Else
    ValidIp = False
End If
 
 
 
Set reg = Nothing
 
End Function
QQn aurait-il une solution ?
Rem : il s'agit d une macro VBA pour Excel.