JohnV Posted February 26, 2011 Share Posted February 26, 2011 Hello Fellow AutoIT programmers, I have a question that has been stumping me. What I want to do is create a little app that would ping computers and if its successfull, it would create a static icon with a button below it. If the ping fails, then it would call a different icon. What I'm having a hard time is, is to add an ico or jpg swap based on success/fail using the ping command in a function. I have several static computer in a gui and would like to keep their positions on the app. I can write an if then statement for each static pc but that would not be the best method to write it, expecially if i'm going to ping more than 100 static computer names. Please look at my code and if possible give me some pointers. I am still a noob at scripting and not a programmer. Thank you for all your suggestions and help. John expandcollapse popup#AutoIt3Wrapper_icon=monitor.ico #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> Global $lblCompletePing Global $KIT[2][4] ; Write an Array to capture computer info $KIT[0][0] = "pc1" $KIT[0][2] = GUICtrlCreateIcon("monitor_add.ico", 488, 296, 32, 32 ) $KIT[0][3] = GUICtrlCreateIcon("monitor_delete.ico", 488, 296, 32, 32 ) $KIT[1][0] = "pc2" $KIT[1][2] = GUICtrlCreateIcon("monitor_add.ico", -1, 488, 352, 32, 32) $KIT[1][3] = GUICtrlCreateIcon("monitor_delete.ico", -1, 488, 352, 32, 32) Main() Func Main() ;Primary GUI #Region ### START Koda GUI section ### Form=e:\documents\sapien\scripts\deltakiosks\initialform1.kxf $mainTools = GUICreate("Ping Tool", 1009, 569, 192, 125) $DTabs = GUICtrlCreateTab(8, 8, 993, 553) $tbComputers = GUICtrlCreateTabItem("Computers") $FirstClass = GUICtrlCreateGroup(" First Class ", 473, 280, 257, 129) $KIT[0][1] = GUICtrlCreateButton("PC1", 481, 328, 45, 20) GUICtrlSetState(-1, $GUI_DISABLE) $KIT[1][1] = GUICtrlCreateButton("PC2", 481, 384, 45, 20) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) $command = GUICtrlCreateGroup("Command Tools", 592, 480, 241, 49) $strPing = GUICtrlCreateButton("Test Availibility", 597, 494, 81, 25) $btnExitMain = GUICtrlCreateButton("Exit", 758, 494, 65, 25) GUICtrlCreateGroup("", -99, -99, 1, 1) $lblCompletePing = GUICtrlCreateLabel("Test Completed", 856, 536, 133, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetState(-1, $GUI_HIDE) $Legend = GUICtrlCreateGroup("Legend", 840, 440, 153, 89) $icoLegend1 = GUICtrlCreatePic("monitor_add.jpg", -1, 848, 456, 32, 32) $icoLegend2 = GUICtrlCreatePic("monitor_delete.jpg", -1, 848, 488, 32, 32) $lblLegend1 = GUICtrlCreateLabel("= System Online", 880, 464, 80, 17) $lblLegend2 = GUICtrlCreateLabel("= System Unavailable", 880, 496, 106, 17) GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $strPing ; Pings the Computers KioskPCping() Case $KIT[0][1] Case $KIT[1][1] Case $btnExitMain ;Runs the Exit Button and Exits the Application Exit EndSwitch WEnd EndFunc Func KioskPCping() ;Pings the computers's to see if they are online using 2 Dimensional Arrays. Local $pcPing, $i For $i = 0 To UBound($KIT) - 1 $pcPing = Ping($KIT[$i][0], 1000) If $pcPing Then GUICtrlSetBkColor($KIT[$i][1], 0x00FF00) GUICtrlSetState($KIT[$i][1], $GUI_ENABLE) Else GUICtrlSetBkColor($KIT[$i][1], 0xFF0000) EndIf Next GUICtrlSetState($lblCompletePing, $GUI_SHOW) EndFunc 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