Jump to content

Formula Problem


Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...