Sign in to follow this  
Followers 0
tAKTelapis

Populate combo box

8 posts in this topic

#1 ·  Posted (edited)

hey guys,

im trying to populate a combo box from a text file (ini or whatever, doesnt really matter)

i want to have a series of codes in a text file:

F1

F2

F3

F4

etc... (no, not relating to the keys on a kb)

and have the program list those in a Combo box.

these codes change often, so updating a text file is quick and easy for the people required to do that. (or ill make a maintenance screen which can easily edit this)

i have had a look around the forum, but couldnt find anything that stood out (nearest i can was getting it to list the files in a directory)

Cheers

/tAK

Edited by tAKTelapis

Share this post


Link to post
Share on other sites



hey guys,

im trying to populate a combo box from a text file (ini or whatever, doesnt really matter)

i want to have a series of codes in a text file:

F1

F2

F3

F4

etc... (no, not relating to the keys on a kb)

and have the program list those in a Combo box.

these codes change often, so updating a text file is quick and easy for the people required to do that. (or ill make a maintenance screen which can easily edit this)

i have had a look around the forum, but couldnt find anything that stood out (nearest i can was getting it to list the files in a directory)

Cheers

/tAK

http://www.autoitscript.com/forum/index.ph...=_PopulateCombo

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

well, thanks for the link to the search.. which i sure did perform, and i had read that entire thread.

i have finally had a clear headed day since then, and i have come up with the following code to perform the required function:

Create the file test.txt in the same directory as you have the script sitting, and file it in with information on each line, then close the listing file with EndOfFile, eg:

test1
test2
test3
EndOfFile

Running the script will produce a GUI, containing a combobox, which lists each line of the text file as a separate option.

it sounds like a slow process, however i have used it to parse a text file of at least 600 lines, roughly 10 characters a piece, word takes longer to open then this program.

#include <GuiConstants.au3>
#include <GuiCombo.au3>

GuiCreate("ComboBox From Text File", 392, 254)


$Combo = GuiCtrlCreateCombo("", 70, 100, 270, 120)
$Btn_Exit = GuiCtrlCreateButton("Exit", 150, 180, 90, 30)


$File = FileOpen("test.txt", 0)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf

$LineNumber = 1
$EndOfFile = ("EndOfFile")
While 1
    $Line = FileReadLine($File, $LineNumber)
    if $line == $EndOfFile then
        ExitLoop
    Else
        _GUICtrlComboAddString($Combo, $line)
        $LineNumber = $lineNumber + 1
    EndIf
WEnd
FileClose($file)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
            ExitLoop
    EndSelect
WEnd
Exit

/tAK

Share this post


Link to post
Share on other sites

Tip:

Checking your @error status after the FileReadLine() will tell you if end of file has occurred. That is if you want that effect.

:whistle:

Share this post


Link to post
Share on other sites

Ha a function I didn't notice... There's always the old fashioned way:

#include <file.au3>
Local $FileToPopulate = @DesktopDir & '\test.txt'

$Main = GUICreate('Some GUI', 200, 100)
$Combo = GUICtrlCreateCombo('', 10, 10, 180, 100)
$Button = GUICtrlCreateButton('Populate', 65, 40, 60, 30)

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = - 3
            Exit
        Case $Msg = $Button
            Local $aFileArray
            _FileReadToArray($FileToPopulate, $aFileArray)
            _PopulateCombo($Combo, $aFileArray)
    EndSelect
    Sleep(10)
WEnd

Func _PopulateCombo($hwndCTRLID, $vInfo)
    Local $sStoreForCombo = ''
    For $iCount = 1 To UBound($vInfo) - 1
        If $vInfo[$iCount] <> '' Then $sStoreForCombo &= $vInfo[$iCount] & '|'
    Next
    GUICtrlSetData($hwndCTRLID, $sStoreForCombo)
EndFunc


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

sweet, thanks SmOke_N

.. there we go, a lot easier then it all looks in the end

though, its proof that even simple ways will work.

and yes MHz, the end of the file is what i was trying to achieve.. havent really paid attention regarding the error codes short of If Exists statements. something that i should probably do a lot more.

i also havent had a look at function calls. ive just been thinking of small things that could be handy to know really.. and attempting to create them using auto IT.

Share this post


Link to post
Share on other sites

Error handling sure is important.... (also very important to look at the function calls... so you at least know what's going on step by step).

Glad it worked out for you.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

yeah, i got the combo box working as requested, and the project got scrapped, the app i was producing is apparently no longer required.

essentially, all i got out of it was the knowledge of creating such a combo box if needed in the future...

oh well, onto whatever it is that i am to do next.

Share this post


Link to post
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
Sign in to follow this  
Followers 0