Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arranging IP numbers 1

Status
Not open for further replies.

007700

Programmer
Jan 24, 2005
20
NL
Hi there,

I am looking for a way to arrange ip numbers on a form.
I have got a form containing txt boxes with IP numbers.
Each text box contains 1 ip number.

When I try to arrange them now, this is the result I get:

10.208.148.129
10.208.149.129
10.208.15.129
10.208.150.129
10.208.151.129

What I want is to get something like this;

10.208.15.129
10.208.148.129
10.208.149.129
10.208.150.129
10.208.151.129

I know I can get it down by putting every number in a different txt box. This would mean that I get 4 txt boxes for eacht IP number, and that I have to split all my ip numbers into 4 numbers :-((.

If anyone can thing of a smart way to get this to work, I would be most greatfull..

Regards 007700

 
There might be a better way to do it, but this works. Open a new module and copy and paste the following code.
Code:
Function IPAddress(strIP As String) As Integer

    Dim varAddress As Variant
    
    varAddress = Split(strIP, ".")
    IPAddress = CInt(varAddress(2))
    
End Function

Then create a new query with the following SQL statement. Basically, the query calls the function which returns a number. And that number is what the query sorts on.
Code:
SELECT Table1.strIP, IPAddress([strIP]) AS IP
FROM Table1
ORDER BY IPAddress([strIP]);
 
Brilliant !!!!!!

There are no other words to describe this ...!!!!

Thanks
 
No need of UserDefinedFunction:
SELECT strIP
FROM Table1
ORDER BY Val(Mid([strIP],1+InStr(1+InStr([strIP],"."),[strIP],".")));

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
How are ya 007700 . . . . .

Backing up [blue]FancyPrairie's[/blue] method, the following sorts across the full address, so you can [purple]sort addresses no matter what[/purple].

The Function:
Code:
[blue]Function RtnIP(IP As String, idx As Integer) As Integer
   Dim Hld
    
   Hld = Split(IP, ".")
   RtnIP = CInt(Hld(idx))
End Function[/blue]
The SQL:
Code:
[blue]SELECT [purple][b]PrimaryKeyName[/b][/purple], [purple][b]IP_AddressFieldName[/b][/purple]
FROM [purple][b]TableName[/b][/purple]
ORDER BY RtnIP([Addr],0), RtnIP([Addr],1), RtnIP([Addr],2), RtnIP([Addr],3);[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top