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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting IP Addresses

Status
Not open for further replies.

arabesque

MIS
Nov 11, 2003
1
US
I'm creating a crystal report and would like the IP Addresses to be in sequential order. This is how it's appearing:

*.10
*.11
*.12
*.9

I need .9 to be above .10.
 
This is a bit ugly, yet effective...

If all of the IP Addresses are in the same format (e.g. 192.168.40.xxx), then create a formula like this:

ToNumber (Right ({Table.IPField}, InStr (StrReverse ({Table.IPField}), ".") - 1))

Then, you can sort on this formula.

-dave
 
Try this formula then sort on it.
It will display the IP, no matter the number in the octet as a string with the format of XXX.XXX.XXX.XXX with each number in each section displaying as three digits. For example, 10.57.0.21 displays as 010.057.000.021

stringvar ip:= "10.57.0.21"; //replace with your field
stringvar oct1;
stringvar oct2;
stringvar oct3;
stringvar oct4;

numbervar o1;
numbervar o2;
numbervar o3;

oct1:= left(ip,instr(ip,".")-1);
o1:=len(oct1)+2;
oct2:= mid(ip,o1,instr(o1,ip,".")-o1);
o2:=len(oct2)+len(oct1)+3;
oct3:= mid(ip,o2,instr(o2,ip,".")-o2) ;
o3:=len(oct3)+len(oct2)+len(oct1)+4;
oct4:= right(ip,len(ip)-instrrev(ip,"."));

totext(val(oct1),"000") &"." & totext(val(oct2),"000") &"." & totext(val(oct3),"000") &"." & totext(val(oct4),"000")

Mike
 
If you have CR8 or higher you can use this formula to change the IP to the XXX.XXX.XXX.XXX format:

stringvar array ip:= split("10.57.0.21",".");
numbervar loop;
stringvar out;

for loop:=1 to 4 do(
if loop = 4 then
out:=out+totext(val(cf[loop]),"000") else
out:=out + totext(val(cf[loop]),"000") + ".");
out


Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top