Jump to content

GUICtrlCreateList with 50+ items


ZenKensei
 Share

Recommended Posts

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

  • Developers

Here's an example with 100 entries...hope it gives you a start.. :idiot:

#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

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,

ZK

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 :idiot:

Link to comment
Share on other sites

  • Developers

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 :D

<{POST_SNAPBACK}>

We are 6 hours ahead of EST... :lol:

Below is a way to do it with a flatfile....

Gelukkig Kerstfeest.... :idiot:

RL003ASRET01

RL004ASRET01

RL005ASRET01

RL006ASRET01

RL007ASRET01

RL008ASRET01

RL009ASRET01

#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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...