Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Splitting an IP address

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark - 19 Nov 2004 11:57 GMT
I am using Word 97.

I have used some code which one of the MVP's provided which picks up the IP
address of a computer.

I want now to split the address say from:

010.016.065.002

so that it only picks up the third section

.065.

if its 2 digits adds a leading zero

.65. to .065.

then so that it strips out the dots at either side.

Can anyone assist, please.

Signature

Mark

Adrian - 19 Nov 2004 12:23 GMT
'18 Nov 2004
Private Sub TestSomething()

   Dim arrIP As Variant
   Dim s3rdSection As String

   arrIP = Split("010.016.65.002", ".")    'Creates zero-based array split
at period

   s3rdSection = Format(arrIP(2), "000")   'Formats 3rd element (starting
zero) to have leading zeros
   

End Sub

> I am using Word 97.
>
[quoted text clipped - 16 lines]
>
> Can anyone assist, please.
Mark - 19 Nov 2004 12:31 GMT
Brilliant.

Many thanks

> '18 Nov 2004
> Private Sub TestSomething()
[quoted text clipped - 31 lines]
> >
> > Can anyone assist, please.
Mark - 19 Nov 2004 12:37 GMT
Adrain,

It doesn't like the split command!

It debugs saying sub or function not defined.

Any solutions?

Mark

> '18 Nov 2004
> Private Sub TestSomething()
[quoted text clipped - 31 lines]
> >
> > Can anyone assist, please.
Jonathan West - 19 Nov 2004 12:41 GMT
> Adrain,
>
[quoted text clipped - 3 lines]
>
> Any solutions?

Are you using Word 97?

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Adrian - 19 Nov 2004 13:03 GMT
So sorry, Mark! You did say you are using Word 97, which does not have the
Split() function.

> Adrain,
>
[quoted text clipped - 41 lines]
> > >
> > > Can anyone assist, please.
Helmut Weber - 19 Nov 2004 13:25 GMT
Hi everybody,
Hi Mark
you must be a very polite person,
as Jonathan's example is using split, too.
---
Sub test666()
Dim s As String
Dim p As Integer ' a position
s = "010.016.065.002"
p = InStr(s, ".")
s = Right(s, Len(s) - p)
p = InStr(s, ".")
s = Right(s, Len(s) - p)
p = InStr(s, ".")
s = Left(s, p - 1)
s = Format(s, "000")
MsgBox s
End Sub
Of course, this could be converted into a function.
You could even model your own split function with Word 97.
But if it is only an IP-adress...
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Adrian - 19 Nov 2004 13:17 GMT
OK, Mark... step through this code!

 '18 Nov 2004
Private Sub TestSomething()

   Dim sStrToSplit As String, sChr As String
   Dim sReqdSection As String
   Dim i As Integer, nDotCount As Integer

   sStrToSplit = "010.016.65.002"
   nDotCount = 1

   For i = 1 To Len(sStrToSplit)
       sChr = Mid$(sStrToSplit, i, 1)
       If sChr = "." Then nDotCount = nDotCount + 1

       'Set nDotCout to return required section
       If nDotCount = 4 Then sReqdSection = sReqdSection & sChr
   Next

   If Left$(sReqdSection, 1) = "." Then sReqdSection = Mid$(sReqdSection, 2)

   sReqdSection = Format(sReqdSection, "000")

End Sub

> Adrain,
>
[quoted text clipped - 5 lines]
>
> Mark
Jonathan West - 19 Nov 2004 12:26 GMT
Hi Mark

This should do the trick

Function ThirdOctet(strIP As String) As String
Dim vSplit As Variant
vSplit = Split(strIP, ".")
ThirdOctet = Format(vSplit(2), "000")
End Function

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

>I am using Word 97.
>
[quoted text clipped - 17 lines]
>
> Can anyone assist, please.
Mark - 19 Nov 2004 12:43 GMT
Many thanks Jonathan

Mark

> Hi Mark
>
[quoted text clipped - 27 lines]
> >
> > Can anyone assist, please.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.