ZenKensei Posted December 24, 2004 Share Posted December 24, 2004 Group, Ok, I thought I would use my time off during the holidays to try and learn the GUI side of AutoIT. I have a couple of ideas for applications to run against the servers I manage at work (over 100 servers). Obviously GUICtrlCreateList is going to figure in most of them, however I have yet to see an example of how to use GUICtrlCreateList with that many items (most show only 1 or 2 items, nothing where you might need to scroll). Can someone post a quick example, doesn't have to be truely functional, say a listing of 15 - 20 servers (server1, server2, etc.) where you select it and then perform a command against it (i.e. something like an RClient or FTP). Since I'm dealing with a large data set I want to make sure that I'm coding the most efficient way possible to keep the code clean and manageable. Thanks in advance, ZenKensei Link to comment Share on other sites More sharing options...
Developers Jos Posted December 24, 2004 Developers Share Posted December 24, 2004 Here's an example with 100 entries...hope it gives you a start.. #include <GUIConstants.au3> GUICreate("My GUI list"); will create a dialog box that when displayed is centered ; create serverlist $ServerList = "" For $x = 1 To 100 $serverlist = $serverlist & "|Server" & StringFormat("%02i",$x) Next ; create gui $add = GUICtrlCreateButton("Add", 64, 32, 75, 25) $clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25) $mylist = GUICtrlCreateList("", 176, 32, 121, 97) GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling GUICtrlSetData(-1, $ServerList) $close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25) ; GUISetState() ; $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $mylist _RunFunc(GUICtrlRead($mylist)) Case $msg = $add GUICtrlSetData($mylist, "You clicked button No1|") Case $msg = $clear GUICtrlSetData($mylist, "") Case $msg = $close MsgBox(0, "", "the closing button has been clicked", 2) Exit EndSelect Wend ; Func _RunFunc($ServerName) MsgBox(4096, 'debug:', '$ServerName:' & $ServerName) EndFunc ;==>_RunFunc SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ZenKensei Posted December 24, 2004 Author Share Posted December 24, 2004 JdeB, As always, thanks for your quick response and for the code sample. Now I understand the relationship between the actual 'selection' of the data in the list box and how you perform an action against the selected item. If I could press you a bit further on a technique aspect of it, specifically the server names (the data in the list box). The server names are not as neat as I mentioned earlier in the form of Server1, Server2, etc. nor are the named consecutively (i.e. ServerA, ServerB, ServerC, etc. They may be ServerA, ServerD, ServerG, etc.). So, with that in mind, if I had to manually specify each server name, would it be best to enter it in a series of GUICtrlSetData(-1, "|RL003ASRET01|RL004ASRET01|RL005ASRET01|RL006ASRET01|RL007ASRET01|RL008ASRET01|RL009ASRET01", "RL004ASRET01")lines or is there a way maybe to read the names from a text file or .ini file which can be included within the compiled script?Let me know your thoughts,Thanks,ZKP.S. Happy Holidays as well my friend, I noticed your in the Netherlands so excuse my ignorance for not knowing if your ahead of U.S. time or behind it Link to comment Share on other sites More sharing options...
this-is-me Posted December 25, 2004 Share Posted December 25, 2004 It depends on whether or not you think you will ever update your script. If you will never make any changes, then do it as you have above. If not, then read from an inifile to make things easier for yourself in the future. Who else would I be? Link to comment Share on other sites More sharing options...
Developers Jos Posted December 25, 2004 Developers Share Posted December 25, 2004 lines or is there a way maybe to read the names from a text file or .ini file which can be included within the compiled script?P.S. Happy Holidays as well my friend, I noticed your in the Netherlands so excuse my ignorance for not knowing if your ahead of U.S. time or behind it <{POST_SNAPBACK}>We are 6 hours ahead of EST... Below is a way to do it with a flatfile....Gelukkig Kerstfeest.... RL003ASRET01RL004ASRET01RL005ASRET01RL006ASRET01RL007ASRET01RL008ASRET01RL009ASRET01expandcollapse popup#include <GUIConstants.au3> GUICreate("My GUI list"); will create a dialog box that when displayed is centered ; create serverlist $ServerList = "" $file = FileOpen("servers.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $serverlist = $serverlist & "|" & $line Wend FileClose($file) ; create gui $add = GUICtrlCreateButton("Add", 64, 32, 75, 25) $clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25) $mylist = GUICtrlCreateList("", 176, 32, 121, 97) GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling GUICtrlSetData(-1, $ServerList) $close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25) ; GUISetState() ; $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $mylist _RunFunc(GUICtrlRead($mylist)) Case $msg = $add GUICtrlSetData($mylist, "You clicked button No1|") Case $msg = $clear GUICtrlSetData($mylist, "") Case $msg = $close MsgBox(0, "", "the closing button has been clicked", 2) Exit EndSelect Wend ; Func _RunFunc($ServerName) MsgBox(4096, 'debug:', '$ServerName:' & $ServerName) EndFunc ;==>_RunFunc SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. 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