Link to home
Start Free TrialLog in
Avatar of jay_waugh
jay_waughFlag for United Kingdom of Great Britain and Northern Ireland

asked on

extract 1st threee octets from IP address

Hi can someone help please?

I have an Access database which contains a table of IP addresses.

I want to add a further column to the table which only contains the 1st three octets of the IP address.

e.g

IP Address            Octet
1.1.1.1                   1.1.1
172.0.1.27             172.0.1
192.168.3.1.2        192.168.3

How can this be done?

Many Thanks

Jay
Avatar of Rgonzo1971
Rgonzo1971

HI,

pls try
Function fIP3Octets(txt As String) As String
Dim aTxt As Variant
aTxt = Split(txt, ".")
ReDim Preserve aTxt(2)
fIP3Octets = Join(aTxt, ".")
End Function

Open in new window

Regards
SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In one line:

IpAddress = "192.168.3.12"
Octet3 = StrReverse(Split(StrReverse(IpAddress), ".", 2)(1))

Octet3 -> "192.168.3"

Open in new window

/gustav