Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Leading zeros in IP address?

If I have a string containing a given IP address - it could be any IP
address, like:

1.222.33.004

What would be the smartest/shortest code, to make sure that all subnets have
leading seros, like:

001.222.033.004



TIA,


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Leading zeros in IP address?

Sub test()
IP = "1.222.33.004"
IParray = Split(IP, ".")

For i = 0 To 3
If i = 0 Then
IP = Format(Val(IParray(i)), "#000")
Else
IP = IP & "." & Format(Val(IParray(i)), "#000")
End If
Next i

End Sub


"Charlotte E." wrote:

If I have a string containing a given IP address - it could be any IP
address, like:

1.222.33.004

What would be the smartest/shortest code, to make sure that all subnets have
leading seros, like:

001.222.033.004



TIA,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Leading zeros in IP address?

IP = "1.222.33.004"
IParrray = split(IP,".")

for i = 0 to 3
if i = 0 then
IP = format(val(IPArray(i)),"#000")
else
IP = IP & "." &format(val(IPArray(i)),"#000")
end if
next i

"Charlotte E." wrote:

If I have a string containing a given IP address - it could be any IP
address, like:

1.222.33.004

What would be the smartest/shortest code, to make sure that all subnets have
leading seros, like:

001.222.033.004



TIA,



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Leading zeros in IP address?

Almost work :-)

It work when I don't have 'Option Explicit' enabled!

But with 'Option Explicit' enabled I get an error in the line:

IParray = split(IP,".")

If I don't Dim the variable I obviously get an "Variable not defined', but
if I try to Dim the variable with

Dim IParray(3) as Variant

I get a 'Cannot assign to Array'.


How to get by this problem???


CE


Joel wrote:
IP = "1.222.33.004"
IParrray = split(IP,".")

for i = 0 to 3
if i = 0 then
IP = format(val(IPArray(i)),"#000")
else
IP = IP & "." &format(val(IPArray(i)),"#000")
end if
next i

"Charlotte E." wrote:

If I have a string containing a given IP address - it could be any IP
address, like:

1.222.33.004

What would be the smartest/shortest code, to make sure that all
subnets have leading seros, like:

001.222.033.004



TIA,



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Leading zeros in IP address?


charlotte:
because there is a typo, IParrray = split(IP,"."). notice there are 3 r's.

Sub test()
Dim IP As String
Dim IParray As Variant
Dim i As Long
IP = "1.222.33.004"
IParray = Split(IP, ".")

For i = 0 To 3
If i = 0 Then
IP = Format(Val(IParray(i)), "#000")
Else
IP = IP & "." & Format(Val(IParray(i)), "#000")
End If
Next i
Debug.Print IP
End Sub


--


Gary

"Charlotte E." <@ wrote in message ...
Almost work :-)

It work when I don't have 'Option Explicit' enabled!

But with 'Option Explicit' enabled I get an error in the line:

IParray = split(IP,".")

If I don't Dim the variable I obviously get an "Variable not defined', but if
I try to Dim the variable with

Dim IParray(3) as Variant

I get a 'Cannot assign to Array'.


How to get by this problem???


CE


Joel wrote:
IP = "1.222.33.004"
IParrray = split(IP,".")

for i = 0 to 3
if i = 0 then
IP = format(val(IPArray(i)),"#000")
else
IP = IP & "." &format(val(IPArray(i)),"#000")
end if
next i

"Charlotte E." wrote:

If I have a string containing a given IP address - it could be any IP
address, like:

1.222.33.004

What would be the smartest/shortest code, to make sure that all
subnets have leading seros, like:

001.222.033.004



TIA,







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Leading zeros in IP address?

From
Dim IParray(3) as Variant

to

Dim IParray as Variant

"Charlotte E." wrote:

Almost work :-)

It work when I don't have 'Option Explicit' enabled!

But with 'Option Explicit' enabled I get an error in the line:

IParray = split(IP,".")

If I don't Dim the variable I obviously get an "Variable not defined', but
if I try to Dim the variable with

Dim IParray(3) as Variant

I get a 'Cannot assign to Array'.


How to get by this problem???


CE


Joel wrote:
IP = "1.222.33.004"
IParrray = split(IP,".")

for i = 0 to 3
if i = 0 then
IP = format(val(IPArray(i)),"#000")
else
IP = IP & "." &format(val(IPArray(i)),"#000")
end if
next i

"Charlotte E." wrote:

If I have a string containing a given IP address - it could be any IP
address, like:

1.222.33.004

What would be the smartest/shortest code, to make sure that all
subnets have leading seros, like:

001.222.033.004



TIA,




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Leading zeros in IP address?

Working - thanks :-)



Joel wrote:
From
Dim IParray(3) as Variant

to

Dim IParray as Variant

"Charlotte E." wrote:

Almost work :-)

It work when I don't have 'Option Explicit' enabled!

But with 'Option Explicit' enabled I get an error in the line:

IParray = split(IP,".")

If I don't Dim the variable I obviously get an "Variable not
defined', but if I try to Dim the variable with

Dim IParray(3) as Variant

I get a 'Cannot assign to Array'.


How to get by this problem???


CE


Joel wrote:
IP = "1.222.33.004"
IParrray = split(IP,".")

for i = 0 to 3
if i = 0 then
IP = format(val(IPArray(i)),"#000")
else
IP = IP & "." &format(val(IPArray(i)),"#000")
end if
next i

"Charlotte E." wrote:

If I have a string containing a given IP address - it could be any
IP address, like:

1.222.33.004

What would be the smartest/shortest code, to make sure that all
subnets have leading seros, like:

001.222.033.004



TIA,



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Leading Zeros Erika Excel Discussion (Misc queries) 4 March 27th 09 04:55 PM
Fomat cells for IP address including leading Zeros Pete[_2_] Excel Worksheet Functions 6 June 13th 07 12:55 AM
Leading Zeros [email protected] Excel Discussion (Misc queries) 6 August 3rd 06 06:15 PM
leading zeros Fernando Duran[_4_] Excel Programming 2 June 24th 06 08:13 AM
save text field w/ leading zeros in .csv format & not lose zeros? Ques Excel Discussion (Misc queries) 1 May 4th 05 06:21 PM


All times are GMT +1. The time now is 06:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"