vickerps Posted April 20, 2004 Posted April 20, 2004 Hi Guys I am writing a prog to configure IP address There 1024 Site to configureSite1 = 10.10.0.0Site2 = 10.10.0.16This will multiplying by 16 until 240 is reach then site 17 = 10.10.1.0Site 18 = 10.10.1.16 and so onI 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 - $NIF $IP4 >240 Then$IP4 = $IP4 - 240$siteno = $siteno - $N$IP4 = $siteno * $N - $NEndIF$IP= $IP1 & "." & $IP2 & "." & $IP3a & "." & $IP4Msgbox (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
Triton Posted April 20, 2004 Posted April 20, 2004 (edited) Is there any reason that you can only have 15 address per 3rd octet? Edited April 20, 2004 by Triton Triton
dmbech Posted April 20, 2004 Posted April 20, 2004 (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 April 20, 2004 by dmbech
vickerps Posted April 20, 2004 Author Posted April 20, 2004 (edited) thanks guysBefore 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 & "." & $IP4Msgbox (16," ",$IP) Edited April 20, 2004 by vickerps
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now