>Well, today's project is learning how to read the classful boundry of
>an IP address.
[quoted text clipped - 18 lines]
>
>Thank you!!
Make a userform with a textbox named txtIP, a command button named
cmdClass, and a label named lblClass (plus any other controls you
like) and give the button this code:
Private Sub cmdClass_Click()
Dim IPaddr As Variant
If Len(txtIP.Text) > 0 Then
IPaddr = Split(txtIP.Text, ".")
If UBound(IPaddr) <> 3 Then
lblClass = "Not a valid IP address"
Exit Sub
End If
Select Case (CLng(IPaddr(0)))
Case 1 To 126
lblClass = "Class A"
Case 128 To 191
lblClass = "Class B"
Case 192 To 223
lblClass = "Class C"
Case Else
lblClass = "Not classified"
End Select
End If
End Sub
The Split function makes an array in the Variant, consisting of the
nodes of the address separated by periods (the periods aren't stored
in the Variant). The Select Case then figures out which range the
first node belongs to, and assigns the corresponding value to the
label.
The check for the upper bound of the variant makes sure there are four
nodes (numbering starts at 0). You could also throw in checks to make
sure all the nodes are numeric and that none of them have values
greater than 255; failing either test would also make the IP address
invalid.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
call_me_sol@yahoo.com - 07 Jul 2007 14:45 GMT
Hi -
Thanks for the reply. The part I'm specifically having a problem with
is taking the value that's input into the textbox and returning it in
its classful boundary.
So, if the user enters 64.192.29.2, I want the form to return 64.0.0.0
(because it's part of a class A block).
If the user enters 208.16.14.1, I want the form to return 208.16.14.0
(because it's parrt of a class C block).
I guess I don't know how to take inputted value, dissect it, and then
return it formatted as described above.
Thanks!!
Jay Freedman - 07 Jul 2007 19:40 GMT
>Hi -
>
[quoted text clipped - 11 lines]
>
>Thanks!!
The Split function has already separated the input into its separate
nodes. All you need now is to put the appropriate pieces (depending on
class) back together, followed by the necessary ".0" nodes:
Private Sub cmdClass_Click()
Dim IPaddr As Variant
If Len(txtIP.Text) > 0 Then
IPaddr = Split(txtIP.Text, ".")
If UBound(IPaddr) <> 3 Then
lblClass = "Not a valid IP address"
Exit Sub
End If
Select Case (CLng(IPaddr(0)))
Case 1 To 126
lblClass = "Class A: " & _
IPaddr(0) & ".0.0.0"
Case 128 To 191
lblClass = "Class B: " & _
IPaddr(0) & "." & IPaddr(1) & ".0.0"
Case 192 To 223
lblClass = "Class C: " & _
IPaddr(0) & "." & IPaddr(1) & "." & IPaddr(2) & ".0"
Case Else
lblClass = "Not classified"
End Select
End If
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
Call_me_sol,
Greg Maxey showed you last month how get your data and work with select case
with the macro below.
So what are you having a problem with now?
You can use the left() function to return the first three characters.
Private Sub CommandButton1_Click()
Dim myArray
Dim lngCount As Long
Dim i As Long
Dim pString As String
Dim pString2
myArray = Split(Me.TextBox1.Text, Chr(13))
lngCount = UBound(myArray) + 1
Select Case lngCount
Case Is < 10
pString2 = "ip prefix maximum 100"
Case Is > 11
Select Case lngCount
Case Is < 100
pString2 = "ip prefix list maximum 1000"
Case Is > 100
pString2 = "ip prefix list maximum 10000"
Case Else
End Select
Case Else
pString = "Whatever"
End Select
For i = 0 To UBound(myArray)
pString = myArray(i)
ActiveDocument.Range.InsertAfter "ip prefix list AS2345 permit ip "
& pString & vbCr
Next i
ActiveDocument.Range.InsertAfter pString2
Me.Hide
End Sub
> Well, today's project is learning how to read the classful boundry of
> an IP address.
[quoted text clipped - 18 lines]
>
> Thank you!!

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID