notta Posted September 14, 2007 Share Posted September 14, 2007 (edited) 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 September 14, 2007 by notta Link to comment Share on other sites More sharing options...
weaponx Posted September 14, 2007 Share Posted September 14, 2007 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 Link to comment Share on other sites More sharing options...
notta Posted September 14, 2007 Author Share Posted September 14, 2007 Yea I was thinking about that. I would be able to break out instead of checking 100 more if statements. Thanks. Link to comment Share on other sites More sharing options...
Danny35d Posted September 14, 2007 Share Posted September 14, 2007 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 Link to comment Share on other sites More sharing options...
notta Posted September 14, 2007 Author Share Posted September 14, 2007 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. Link to comment Share on other sites More sharing options...
weaponx Posted September 14, 2007 Share Posted September 14, 2007 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. Link to comment Share on other sites More sharing options...
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