Jump to content

adding array top combo box


anwarbham
 Share

Recommended Posts

hi is there any way of adding an array to a combo box my code reads the lines from a file converts them to an array and is supposed to add that array to a combo box but it does not work any ideas any one

#include <GuiConstants.au3>

#include <file.au3>

Dim $aRecords

opt("GUIOnEventMode", 1)

;create gui

$box = GUICreate("asset tool", 400, 400)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

GUISetIcon(@SystemDir & "\mspaint.exe", 0)

$file = FileOpen("D:\Profiles\BHAMA\Desktop\phone\myfile.ini", 0) ; will have to change this

FileClose($file)

; asset inputbox

GUICtrlCreateLabel("Asset Number", 300, 65, 95, 40)

$input1 = GUICtrlCreateInput("", 40, 60, 250, 20); asset read command

_FileReadToArray("D:\Profiles\BHAMA\Desktop\phone\myfile.ini",$aRecords); this reads the lines from a file and makes them in to an array

For $x = 18 to $aRecords[0];starts from line 18 and reads till end of document

$look = GUICtrlRead($aRecords[$x]);suposed to read all of the arrays

Next

GUICtrlCreateCombo ($look,40,150,250) ; creates a combo box and adds the array value

GUISetState()

While 1

Sleep(100)

WEnd

Func _Exit()

Exit

EndFunc ;==>_Exit

Link to comment
Share on other sites

CODE

For $x = 18 To $aRecords[0];starts from line 18 and reads till end of document

$look = $look & $aRecords[$x] & "|"

Next

$look = StringTrimRight($look, 1)

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

yeah thats the way i tried it too but it comes up with an error

D:\Profiles\BHAMA\My Documents\_FileReadToArray.au3(25,16) : WARNING: $look: possibly used before declaration.

$look = $look &

#include <GuiConstants.au3>

#include <file.au3>

Dim $aRecords

opt("GUIOnEventMode", 1)

;create gui

$box = GUICreate("asset tool", 400, 400)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

GUISetIcon(@SystemDir & "\mspaint.exe", 0)

$file = FileOpen("D:\Profiles\BHAMA\Desktop\phone\myfile.ini", 0) ; will have to change this

FileClose($file)

; asset inputbox

GUICtrlCreateLabel("Asset Number", 300, 65, 95, 40)

$input1 = GUICtrlCreateInput("", 40, 60, 250, 20); asset read command

_FileReadToArray("D:\Profiles\BHAMA\Desktop\phone\myfile.ini",$aRecords); this reads the lines from a file and makes them in to an array

For $x = 18 To $aRecords[0];starts from line 18 and reads till end of document

$look = $look & $aRecords[$x] & "|"

Next

$look = StringTrimRight($look, 1)

GUICtrlCreateCombo ($look,40,150,250) ; creates a combo box and adds the array value

GUISetState()

While 1

Sleep(100)

WEnd

Func _Exit()

Exit

EndFunc ;==>_Exit

Link to comment
Share on other sites

that's just a warning from the au3check, you choose to ignore it and it should work or, just add $look at the top of the script:

CODE

#include <GuiConstants.au3>

#include <file.au3>

Dim $aRecords, $look = ""

opt("GUIOnEventMode", 1)

;create gui

$box = GUICreate("asset tool", 400, 400)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

GUISetIcon(@SystemDir & "\mspaint.exe", 0)

$file = FileOpen("D:\Profiles\BHAMA\Desktop\phone\myfile.ini", 0) ; will have to change this

FileClose($file)

; asset inputbox

GUICtrlCreateLabel("Asset Number", 300, 65, 95, 40)

$input1 = GUICtrlCreateInput("", 40, 60, 250, 20); asset read command

_FileReadToArray("D:\Profiles\BHAMA\Desktop\phone\myfile.ini", $aRecords); this reads the lines from a file and makes them in to an array

For $x = 18 To $aRecords[0];starts from line 18 and reads till end of document

$look = $look & $aRecords[$x] & "|"

Next

$look = StringTrimRight($look, 1)

GUICtrlCreateCombo($look, 40, 150, 250) ; creates a combo box and adds the array value

GUISetState()

While 1

Sleep(100)

WEnd

Func _Exit()

Exit

EndFunc ;==>_Exit

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

sorry to be a pain but its not working this is what i have

the field is now blank is there a way to split each record in to a diffrent combo box record

#include <GuiConstants.au3>

#include <file.au3>

Dim $aRecords, $look = ""

opt("GUIOnEventMode", 1)

;create gui

$box = GUICreate("asset tool", 400, 400)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

GUISetIcon(@SystemDir & "\mspaint.exe", 0)

$file = FileOpen("D:\Profiles\BHAMA\Desktop\phone\myfile.ini", 0) ; will have to change this

FileClose($file)

; asset inputbox

GUICtrlCreateLabel("Asset Number", 300, 65, 95, 40)

$input1 = GUICtrlCreateInput("", 40, 60, 250, 20); asset read command

_FileReadToArray("D:\Profiles\BHAMA\Desktop\phone\myfile.ini", $aRecords); this reads the lines from a file and makes them in to an array

For $x = 18 To $aRecords[0];starts from line 18 and reads till end of document

$look = $look & $aRecords[$x]&'|'

Next

$look = StringTrimRight($look, 3)

GUICtrlCreateCombo("", 40, 150, 250) ; creates a combo box

GUICtrlSetData(-1,$look) ;adds the array value to combo box

GUISetState()

While 1

Sleep(100)

WEnd

Func _Exit()

Exit

EndFunc ;==>_Exit

Link to comment
Share on other sites

GUICtrlCreateCombo("", 40, 150, 250) ; creates a combo box

GUICtrlSetData(-1,$look) ;adds the array value to combo box

I'm trying to load a list or combo box directly from an array. Didn't see this in the helpfile but I tried your sample above. However it doesn't work. Am I missing something ?

Thanks for any hints;

Attached my sample:

#include <GuiConstants.au3>

#Include <File.au3>

#Include <Array.au3>

; GUI

GuiCreate("testing", 1024, 768)

WinSetState("testing", "", @SW_MAXIMIZE)

; Select and Read a directory

$myfoldervar = FileSelectFolder("Choose a folder.", "")

$FileList=_FileListToArray($myfoldervar)

; Show it in a Combo

GUICtrlCreateCombo("", 40, 150, 250) ; create combo

GUICtrlSetData(-1,$FileList) ;adds the array value to combo box ???

; GUI MESSAGE LOOP

GuiSetState()

While GuiGetMsg() <> $GUI_EVENT_CLOSE

WEnd

Link to comment
Share on other sites

@anwarbham i checked my code with an ini i had and it worked fine, noticed you changed the trim from 1 to 3 only need to trim 1

@Bodi

CODE

#include <GuiConstants.au3>

#Include <File.au3>

#Include <Array.au3>

; GUI

GUICreate("testing", 1024, 768)

WinSetState("testing", "", @SW_MAXIMIZE)

; Select and Read a directory

$myfoldervar = FileSelectFolder("Choose a folder.", "")

$FileList = _FileListToArray ($myfoldervar)

$s_text = ""

For $x = 1 To $FileList[0]

$s_text = $s_text & $FileList[$x] & "|"

Next

$s_text = StringTrimRight($s_text, 1)

; Show it in a Combo

GUICtrlCreateCombo("", 40, 150, 250) ; create combo

GUICtrlSetData(-1, $s_text) ;adds the array value to combo box ???

; GUI MESSAGE LOOP

GUISetState()

While GUIGetMsg() <> $GUI_EVENT_CLOSE

WEnd

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

GUICtrlCreateCombo("", 40, 150, 250) ; creates a combo box

GUICtrlSetData(-1,$look) ;adds the array value to combo box

I'm having a similar problem...

The code is:

$NamesBox = GUICtrlCreateCombo("", 112, 8, 145, 21)

GUICtrlSetData($NamesBox, $sNameList)

MsgBox(0,"$sNameList",$sNameList,5)

The MsgBox shows "Gene|Kent|Charlotte|Sharon|Dwayne|Scott", but the ComboBox is not populated.

I tried first with:

$NamesBox = GUICtrlCreateCombo("", 112, 8, 145, 21)

GUICtrlSetData(-1, $sNameList)

MsgBox(0,"$sNameList",$sNameList,5)

The MsgBox showed "Gene|Kent|Charlotte|Sharon|Dwayne|Scott", but that didn't work either.

From my understanding of the Help file, either one of those should work. I'm using the .81 beta.

Any suggestions?

Edited by Gene

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

This works for me

#include <GUIConstants.au3>

$sNameList = "Gene|Kent|Charlotte|Sharon|Dwayne|Scott"
GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered

$NamesBox = GUICtrlCreateCombo("", 112, 8, 145, 21)
GUICtrlSetData($NamesBox, $sNameList)


GUISetState ()

; Run the GUI until the dialog is closed
While 1
 $msg = GUIGetMsg()
 
 If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

This works for me

#include <GUIConstants.au3>

$sNameList = "Gene|Kent|Charlotte|Sharon|Dwayne|Scott"
GUICreate("My GUI combo"); will create a dialog box that when displayed is centered

$NamesBox = GUICtrlCreateCombo("", 112, 8, 145, 21)
GUICtrlSetData($NamesBox, $sNameList)
GUISetState ()

; Run the GUI until the dialog is closed
While 1
 $msg = GUIGetMsg()
 
 If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Thanks for the reply. This is a weird situation, what you sent doesn't work and neither does the help file sample for _GUICtrlComboAddString(). Oh, and between my previous note and this, I'm now running the .83 beta. I'm running Win2K with sp4 & 256 MB RAM.

I modified what you sent to make sure of what beta level was running it.

#include <GUIConstants.au3>

$sNameList = "Gene|Kent|Charlotte|Sharon|Dwayne|Scott"
GUICreate("My GUI combo"); will create a dialog box that when displayed is centered

$NamesBox = GUICtrlCreateCombo("", 112, 8, 145, 21)
GUICtrlSetData($NamesBox, $sNameList)

MsgBox(0,"@AutoItVersion",@AutoItVersion)

GUISetState ()

; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

And the Help file sample code.

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

Opt('MustDeclareVars',1)

Dim $Label,$Input,$Btn_Add,$Combo,$Btn_Exit,$msg

GuiCreate("ComboBox Add String", 392, 254)

$Label = GuiCtrlCreateLabel("Enter String to Add", 20, 20, 120, 20)
$Input = GuiCtrlCreateInput("", 160, 20, 180, 20)
$Btn_Add = GuiCtrlCreateButton("Add String", 210, 50, 90, 30)
$Combo = GuiCtrlCreateCombo("A", 70, 100, 270, 21)
GUICtrlSetData($Combo,"B|C|D|E|F")
$Btn_Exit = GuiCtrlCreateButton("Exit", 150, 180, 90, 30)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
            ExitLoop
        Case $msg = $Btn_Add
            If(StringLen(GUICtrlRead($Input)) > 0) Then
                _GUICtrlComboAddString($Combo,GUICtrlRead($Input))
            EndIf
    EndSelect
WEnd
Exit

Of the Help file sample code, all that appears in the ComboBox is the "A".

EDIT = I have tried all attempts as interpreted and as compiled.

Edited by Gene

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

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