Jump to content
Sign in to follow this  
notta

Most efficient way?

Recommended Posts

notta

I'm creating a script that will scan our network, but there's a part that I'm wondering if there is a more efficient way of doing. I'm scanning a list of computers for their IP and then parsing the subnet. After I have the subnet I want to output the building number depending upon the value. Example:

if $subnet = 111 Then FileWriteLine($output, "Building 4000 Floor 1")
         if $subnet = 112 Then FileWriteLine($output, "Building 4000 Floor 2") 
         if $subnet = 113 Then FileWriteLine($output, "Building 4000 Floor 3")

and so on. Is this the most efficient way of doing this? We have a large amount of buildings, so this could take some time to create :) Thanks guys.

Edited by notta

Share this post


Link to post
Share on other sites
weaponx

Maybe a Switch would work better.

Switch $subnet

Case 111

FileWriteLine($output, "Building 4000 Floor 1")

Case 112

FileWriteLine($output, "Building 4000 Floor 2")

Case 113

FileWriteLine($output, "Building 4000 Floor 3")

EndSwitch

Share this post


Link to post
Share on other sites
notta

Yea I was thinking about that. I would be able to break out instead of checking 100 more if statements. Thanks.

Share this post


Link to post
Share on other sites
Danny35d

The best way to do it is using weaponx example. Another way if you know the subnet are in order by floor 111, 112, 113...etc will be:

FileWriteLine($output, "Building 4000 Floor 1 " & StringRight($subnet, 1))

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites
notta

Yea I was thinking about that. I would be able to break out instead of checking 100 more if statements. Thanks.

After reading the switch docs I found a switch is automatically exited when a case is matched. I thought you had to break out.

Share this post


Link to post
Share on other sites
weaponx

After reading the switch docs I found a switch is automatically exited when a case is matched. I thought you had to break out.

Other languages (C++, PHP) support cascading Case statements and thusly require you to Break if you don't want to cascade through every case.

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  

×