Jump to content

Array to combo Box


kpu
 Share

Recommended Posts

What I'm trying to do is read a txt file that has line by line of data and put it in the combo box. What I think I have to do is use the file array like this one:

#include <file.au3>
Dim $aRecords,$xFile
$xFile = "list.txt"
If Not _FileReadToArray($xFile,$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
    Msgbox(0,'Record:' & $x, $aRecords[$x])
Next

Then some how use the data it pulls from $aRecords[$x] to put in the combo box...??? Am I getting warm or WAY! off.

I understand how to put and read, the data when coding the Combo Box, but not how to fill it in from another source such as a file.

Any help would greatly be appreciated!

Link to comment
Share on other sites

#include <file.au3>
Dim $aRecords,$xFile
$xFile = "list.txt"
If Not _FileReadToArray($xFile,$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
    $ComboList=$comboList & $aRecords[$x] & "|"
Next
$ComboList=StringTrimRight($ComboList,1)

; build the rest of your GUI

$ComboBox1 = GUICtrlCreateCombo ("", 10,10)
GUICtrlSetData($ComboBox1,$ComboList)

Not tested, but I think that will work...

As a Side Note, you don't HAVE to put it into the array at all, you could just open the file, read it line by line and format the string for your combo box directly... and there are probably many more (and several of them will be more efficient) ways to do what your wanting to do.

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

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