Jump to content

Populate a list box


Recommended Posts

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

Link to comment
Share on other sites

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

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...?

:)

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
Link to comment
Share on other sites

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.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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
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...