Sign in to follow this  
Followers 0
PDowning

Help a newb make this more efficient

6 posts in this topic

I have made a script that pulls the PC IP address, compare the 2nd octect number and open a website based on that comparison. The problem is that it has to be compared to nealy 90 sites and it makes for one large If .. .EndIf. Here is a snippet of the code:

If Number ($Octet[2]) = 118 Then    
      run ("c:\Program Files\Internet Explorer\IEXPLORE.EXE http://website/common/welcome.jsp?site=101")
ElseIf Number ($Octet [2]) = 123 Then
     run ("c:\Program Files\Internet Explorer\IEXPLORE.EXE http://website/common/welcome.jsp?site=102")
ElseIf Number ($Octet [2]) = 195 Then
     run ("c:\Program Files\Internet Explorer\IEXPLORE.EXE http://website/common/welcome.jsp?site=105")

this continues till the final ElseIF comparison.

How can this be more efficient?

Share this post


Link to post
Share on other sites



PDowning,

Look at Switch in the Help file. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

According to my puny brain power here, I can't see how those help due to the IP's NOT being in a straight order(ex. 101,102,103,104). They, thanks to the brilliant engineering brain power around here, are all over the place. Also the number at the end of the IExplorer line are also not in order. Guess I'm just not wrapping a head around this yet.

Edited: Not knocking your suggestions, thank you very much for them. I just can't wrap my head around how it helps.

Edited by PDowning

Share this post


Link to post
Share on other sites

PDowning,

JohnOne's idea is better than mine - and here is how you might implement something like it:

#include <Array.au3>

; Creat an array to link the octet with the site ID
Global $aListing[3][2] = [[118, 101], [123, 102], [195, 105]]

; Simulate the octet
Global $Octet[3]
$Octet[2] = 118

; Look for the octet
$iIndex = _ArraySearch($aListing, Number($Octet[2]))
If $iIndex <> -1 Then
    ; Use the related site ID
    ConsoleWrite("c:\Program Files\Internet Explorer\IEXPLORE.EXE http://website/common/welcome.jsp?site=" & $aListing[$iIndex][1] & @CRLF)
    ;Run("c:\Program Files\Internet Explorer\IEXPLORE.EXE http://website/common/welcome.jsp?site=" & $aListing[$iIndex][1])
EndIf

All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Gotcha .... that makes sense now. I had thought of something similar when I was sitting to write the script, but couldn't visualize how to put it on paper, so to speak.

thanks much

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