jon_in_vermont Posted May 3, 2007 Posted May 3, 2007 Hello, As a new and still infrequent user of AutoIt, I need direction / help in doing the following: 1. Populate a listbox from an existing text file 2. Use the listbox in a script so a user can select (in this case a student name) 3. Then use that student name later on in the script. Any thoughts on how to get started with that? This is for a simple script that controls drive mappings based on the selected student name. Thanks, Jon
PsaltyDS Posted May 3, 2007 Posted May 3, 2007 Hello,As a new and still infrequent user of AutoIt, I need direction / help in doing the following:1. Populate a listbox from an existing text file2. Use the listbox in a script so a user can select (in this case a student name)3. Then use that student name later on in the script.Any thoughts on how to get started with that?This is for a simple script that controls drive mappings based on the selected student name.Thanks, JonPost an example of the text file, with about three to five fake students in it. The format will determine the easiest way. Will it be .xml, .ini, .csv, etc...? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
jon_in_vermont Posted May 4, 2007 Author Posted May 4, 2007 Post an example of the text file, with about three to five fake students in it. The format will determine the easiest way. Will it be .xml, .ini, .csv, etc...? Here is an example of the text file:username1@email.school.eduusername2@email.school.eduI strip off everything past and including the @. I just need a solution to pop these names into a listbox or picklist of some sort. Thanks
PsaltyDS Posted May 4, 2007 Posted May 4, 2007 Here is an example of the text file: username1@email.school.edu username2@email.school.edu I strip off everything past and including the @. I just need a solution to pop these names into a listbox or picklist of some sort. Thanks Use _FileReadToArray() to read the file into an array, then walk through the array, testing each value for "@email.school.edu". When a match occurs, strip off the username and add it to your list. Code it as far as you can. If it doesn't work, post your code and you'll get lots of help. To provide enough data for a good test, I would create Test.txt like this: Irrelavent line of nonsense... username1@email.school.edu intentionally@malformed.com username2@email.school.edu broken.ref.without.ampersand username3@email.school.edu username4@email.school.edu username5@email.school.edu Cheers! Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Kip Posted May 4, 2007 Posted May 4, 2007 Something like this? #include <GUIConstants.au3> #include <GuiList.au3> #include <file.au3> $Form1 = GUICreate("?Usernames Example?", 468, 242, 193, 115) $List1 = GUICtrlCreateList("", 8, 24, 457, 188) $Label1 = GUICtrlCreateLabel("Usernames", 8, 8, 57, 17) $Button1 = GUICtrlCreateButton("Ok", 392, 216, 73, 25, 0) $Button2 = GUICtrlCreateButton("Cancel/Quit/Or whatever!", 240, 216, 145, 25, 0) GUISetState(@SW_SHOW) Dim $ReadedFile _FileReadToArray("Usernames.txt",$ReadedFile) For $i = $ReadedFile[0] to 1 step -1 $Splitted = StringSplit($ReadedFile[$i],"@") _GUICtrlListAddItem($List1,$Splitted[1]) Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 MsgBox(0,"Username",GUICtrlRead($List1)) Case $Button2 ExitLoop EndSwitch WEnd Change 'Usernames.txt' in your usernames file. MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
Valuater Posted May 4, 2007 Posted May 4, 2007 I dont think this is right_GUICtrlListAddItem($List1,$Splitted[1])8)
PsaltyDS Posted May 4, 2007 Posted May 4, 2007 I dont think this is right _GUICtrlListAddItem($List1,$Splitted[1]) 8) No, I think he got that right. The username is is the first field delimited by @. [0] is the count, [1] should be username, and [2] would be email.school.edu. But his loop does ASSume that every line is a correctly formatted email... Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Kip Posted May 4, 2007 Posted May 4, 2007 (edited) @ Valuater: If you think it isnt right, just test it. But you will see that it is right. @ PsaltyDS: I'm also just a newbie (maybe an advanced newbie) Edited May 4, 2007 by kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
jon_in_vermont Posted May 4, 2007 Author Posted May 4, 2007 @ Valuater: If you think it isnt right, just test it. But you will see that it is right.@ PsaltyDS: I'm also just a newbie (maybe an advanced newbie)Kip's code worked great! Many thanks again. Virtual beverages to you....Jon
Kip Posted May 4, 2007 Posted May 4, 2007 (edited) no thanx Edited May 5, 2007 by kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
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