Sign in to follow this  
Followers 0
vickerps

Formula Problem

4 posts in this topic

Hi Guys I am writing a prog to configure IP address There 1024 Site to configure

Site1 = 10.10.0.0

Site2 = 10.10.0.16

This will multiplying by 16 until 240 is reach then

site 17 = 10.10.1.0

Site 18 = 10.10.1.16 and so on

I have written this to write the ip addresses based upon the site no

$N = 16

$IP1=10

$IP2=10

$IP3=0

$IP4=0

While 1

$siteno = InputBox ( " ", "Please enter the Site Number" )

If $siteno >1024 OR $siteno <1 Then

Msgbox (16," ","Incorrect Site Number")

EndIF

IF $siteno <=1024 AND $siteno >=1 Then ExitLoop

WEnd

$IP3 = $siteno / $N

$IP3a = Round ($IP3)

$IP4 = $siteno * $N - $N

IF $IP4 >240 Then

$IP4 = $IP4 - 240

$siteno = $siteno - $N

$IP4 = $siteno * $N - $N

EndIF

$IP= $IP1 & "." & $IP2 & "." & $IP3a & "." & $IP4

Msgbox (16," ",$IP)

basically my formula doesn't work because once site 33 is reach it will start writing 256 and upwards.

Can anyone help please

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Is there any reason that you can only have 15 address per 3rd octet?

:D

Edited by Triton

Triton

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Well, I think you have a couple of logic problems. First lets deal with $IP3. In your example it will increment when your siteno hits 8 and I don't think you want this. From what I can tell, $IP3 should not increment until siteno reaches multiples of 16 so all you need for $IP3 is:

$IP3 = Int(($siteno-1) / $N)

Now get rid of that useless variable $IP3a. $IP4 is a little harder but can be done with the following:

$IP4 = ($siteno - ($N*$IP3))*$N - $N

Now get rid of the useless If...Then and you are all set.

Edited by dmbech

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

thanks guys

Before I read your reply i had solved my problem. here is the code i have used can you find any problems with it. should redo it the way you have suggested

  $IP1=10

$IP2=10

$IP3=0

$IP4=0

; ----------------------------------------------------------------------------

; Script Start

; ----------------------------------------------------------------------------

While 1

$siteno = InputBox ( " ", "Please enter the Site Number" )

If $siteno >1024 OR $siteno <1 Then

Msgbox (16," ","Incorrect Site Number")

EndIF

IF $siteno <=1024 AND $siteno >=1 Then ExitLoop

WEnd

$Max = ($siteno -1) * 16

$IP3 = $Max / 256

$IP3 = INT ($IP3)

$N= 16 * $IP3

$IP4 = $siteno * 16 - 16

IF $IP4 >240 Then

$siteno = $siteno - $n

$IP4 = $siteno * 16 - 16

EndIF

$IP= $IP1 & "." & $IP2 & "." & $IP3 & "." & $IP4

Msgbox (16," ",$IP)

Edited by vickerps

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0