Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,098 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,838 people online right now. Registration is fast and FREE... Join Now!




Data Formatting

 
Reply to this topicStart new topic

Data Formatting, Formatting an IP Address

MarcE
22 Apr, 2008 - 05:48 PM
Post #1

New D.I.C Head
*

Joined: 22 Apr, 2008
Posts: 0

I'm still new to VB.NET I am a VFP programmer and I was task to convert the application that I have written to .NET.

I have a bit of dilemma I want to convert the IP Address that is inputted as '10.0.2.1' to '010.000.002.001' as you well know '10.0.2.1' would not sort properly.

In VFP my program will have this snippet:


PADL would pad the address with 'O' if the length of the data between each '.' is less than 3
if the data entered is '10.0.2.1'
in the example
IP1 = '10' and will be converted to '010'
IP2 = '0' and will be converted to '000'
IP3 = '2' and will be converted to '002'
IP4 = '1' and will be converted to '001'
ipaddress = ip1+'.'+ip2+'.'+ip3+'.'+ip4 (010.000.002.001)

Program Snippet:

ip1 = PADL(subSTR(IP_Address,1,AT('.',IP_Address,1)-1),3,'0')

ip2 = PADL(subSTR(IP_Address,AT('.',IP_Address,1)+1,AT('.',IP_Address,2)-4),3,'0')

ip3 = PADL(subSTR(IP_Address,AT('.',IP_Address,2)+1,AT('.',IP_Address,3)-6),3,'0')

ip4 = PADL(alltrim(substr(ip_address,RAT('.',IP_Address,1)+1)),3,'0')

ipaddress = ip1+'.'+ip2+'.'+ip3+'.'+ip4
replace ip_Address WITH ipAddress

Can somebody please show me how I can do it in VB.NET.

How do I also validate that the user has inputted a valid IP address.

This routine will be used in different pages as well as some pages will contain the textbox for IP Address.

My backend is SQL2005 does anybody know how to do it in SQL as an input mask.

I would appreciate it if somebody will be able to show by example how I can do this and where can I put it in?

Can I put it in a stored procedure or make it a function...bearing in mind that I should be able to call this from any page and how do I call it?

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:24AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month