It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

validating text

Moderator: dafunkymunky

validating text

Postby krusty on Wed Mar 19, 2008 7:10 am

am currently working on an inventory system for the I.T department. The system is used to store information about all the computers in the company including the username, OS Version, IP Address e.t.c Now i want to validate a text box such that the user can only enter a valid IP address in the usual format *.*.*.* e.g 123.456.67.0. Does anyone have any sample code to do that?
krusty
 
Posts: 4
Joined: Wed Mar 19, 2008 6:50 am

Use Like Command

Postby sendtoanurag on Wed Mar 19, 2008 3:07 pm

Put this code for validation

If Text1 Like "###.###.##.#." Then
'Do ur work
Else
Text1.setFocus
Alert User
End If


'# for numbers
sendtoanurag
 
Posts: 29
Joined: Tue Mar 18, 2008 2:51 pm

Postby krusty on Wed Mar 19, 2008 3:19 pm

sendtoanurag wrote:Put this code for validation

If Text1 Like "###.###.##.#." Then
'Do ur work
Else
Text1.setFocus
Alert User
End If


'# for numbers
thanks alot mate the code somehow works but there is one hitch, i can only enter an IP address that has 3 values througout. eg 123.456.678.901
What if the IP address is something like 123.34.456.4.
the IP addresses vary but your code is only allows one way of entering them.
all in all thanks alot partner, atleast now i have a clue so modifing the code wont be very difficult
krusty
 
Posts: 4
Joined: Wed Mar 19, 2008 6:50 am

Postby krusty on Wed Mar 19, 2008 3:21 pm

whats wrong with my code?
Private Sub txtIP_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtIP.LostFocus
If txtIP.Text Like "###.###.###.###" Then
MsgBox(" IP Address is OK!!", MsgBoxStyle.Information)
Else
MsgBox("Invalid IP Address", MsgBoxStyle.Critical)
txtIP.Focus()
txtIP.Clear()
End If
End Sub
krusty
 
Posts: 4
Joined: Wed Mar 19, 2008 6:50 am

Postby sendtoanurag on Thu Mar 20, 2008 4:19 am

I've used it in my projetc
But be sure to add exception handler

Public Function ValidateIp(ByVal strIPAddress As String) As Boolean

Dim IPAddress
Dim lngNum As Long
Dim lngNumCount As Long

IPAddress = Split(strIPAddress, ".", , vbTextCompare)
If IsArray(IPAddress) Then
For lngNum = LBound(IPAddress) To UBound(IPAddress)
lngNumCount = lngNumCount + 1
IPAddress(lngNum) = CByte(IPAddress(lngNum))
Next
ValidateIp = (lngNumCount = 4)
End If
End Function
sendtoanurag
 
Posts: 29
Joined: Tue Mar 18, 2008 2:51 pm


Who is online

Users browsing this forum: No registered users and 2 guests