Jump to content

Populate ComboBox from Text File (solved)


muncherw
 Share

Recommended Posts

I have a text file with a list of nearly 1000 computer names ie.

adm-psaltyds

adm-airwolf

adm-geosoft etc.

I'd like to populate a combo box with these names. The letters in front of the hyphen are broken up so I'll have multiple boxes with different sets of computers. Anyway, I'm not sure where to start. I don't have any code yet and I'm not asking for anyone to write anything for me, all I'd like is an idea of how to get started. So far I'm thinking maybe I can read in lines from the file to create a variable that it uses but I'm not sure if that makes sense.

I should also state that the reason I don't want to just write the names into the code is that the computer names change frequently (when people quit, get hired, change last name, move to different job) so it's much easier to just generate a new list of PC names. In fact, the way I get the names is with AutoIt so maybe instead of writing them to a text file I can some how throw them into the combo box.

I was looking at many of the _GUICtrlComboBox functions but none of them hit me as something that made sense for what I wanted.

Thanks in advance.

Edited by muncherw
Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Link to comment
Share on other sites

@muncherw

Look at GuiCtrlCreateCheckBox or GuiCtrlCreateCombo and GuiCtrlSetData

Example :

#include <GuiConstants.au3>
Opt("GuiOnEventMode", 1)

GUICreate("GUI", 300, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$ck_1 = GUICtrlCreateCheckbox("Checkbox 1", 5, 5)
$ck_2 = GUICtrlCreateCheckbox("Checkbox 2", 5, 25)
GUICtrlCreateButton("Check !", 5, 50, 50, 20)
GUICtrlSetOnEvent(-1, "_Check")

$cbo = GUICtrlCreateCombo("Combo !",150,5,80,20)
GUICtrlSetData(-1, "Exit|Nothing","Combo !")
GUISetState()

While 1
    Sleep(250)
    If GUICtrlRead($cbo) = 'Exit' Then
        _Exit()
    EndIf
WEnd

Func _Check()
    If GUICtrlRead($ck_1) = $GUI_CHECKED Then
        MsgBox(64, 'ck_1', '$ck_1 checked !')
    EndIf
    If GUICtrlRead($ck_2) = $GUI_CHECKED Then
        MsgBox(64, 'ck_2', '$ck_2 checked !')
    EndIf
EndFunc   ;==>_Check

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Cheers, FireFox

Edited by FireFox
Link to comment
Share on other sites

Thanks, Firefox.

I've already got some scripts using combo boxes so I'm somewhat familiar. I guess I do need to use GuiCtrlSetData but it's really getting it to pull from the text file instead of having so specifically write it in the script that I'm confused about.

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Link to comment
Share on other sites

In my gui I have this, which works fine.

$ChampDropdown = GUICtrlCreateCombo("NONE", 30, 33, 220, 25)
GUICtrlSetData(-1, "adm-psaltyds|adm-airwolf|adm-geosoft")
GUICtrlSetFont(-1, 8, 400, 0, "Arial")

This is from the helpfile. I've just added a variable ($lineComplete) to store all the lines. This also works.

$file = FileOpen("list.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$lineComplete = ""
; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $lineComplete = $lineComplete & $line
Wend

FileClose($file)

But if I take that bit of code and try to paste it into the same script as the first one then I always get the error that it can't open my text file. I haven't even bothered to change any of the gui yet to try to use the variable, I just put that code at the begining of the script when I get the error.

----------------------------------

Woah. Total bonehead manuever on my part- I copied both scripts to the same directory but when I was working with them I still had the second script open from the old ocation and was doing my testing on it instead of the one in the same folder. Woopsie daisies!

Edited by muncherw
Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
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...