anwarbham Posted October 3, 2005 Share Posted October 3, 2005 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 More sharing options...
GaryFrost Posted October 3, 2005 Share Posted October 3, 2005 (edited) $look = $look & $aRecords[$x] & "|" after the loop $look = stringtrimright($look,1) see if that helps Edited October 3, 2005 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 More sharing options...
anwarbham Posted October 4, 2005 Author Share Posted October 4, 2005 sorry dude not working ive put it after the loop before the loop doesnt pick up the array is there another way to read the lines of a file and display it in to a combo box Link to comment Share on other sites More sharing options...
GaryFrost Posted October 4, 2005 Share Posted October 4, 2005 (edited) 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 October 4, 2005 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 More sharing options...
anwarbham Posted October 4, 2005 Author Share Posted October 4, 2005 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 More sharing options...
GaryFrost Posted October 4, 2005 Share Posted October 4, 2005 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 More sharing options...
anwarbham Posted October 5, 2005 Author Share Posted October 5, 2005 yay it works but with a hitch all the records have merged now and apear in one continus line in the combo box in stead of each one on a new box that i can scroll down to any ideas how i can seperate them Link to comment Share on other sites More sharing options...
GaryFrost Posted October 5, 2005 Share Posted October 5, 2005 GUICtrlCreateCombo("", 40, 150, 250) ; creates a combo box GUICtrlSetData(-1,$look) ;adds the array value to combo box 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 More sharing options...
anwarbham Posted October 6, 2005 Author Share Posted October 6, 2005 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 More sharing options...
Bodi Posted October 6, 2005 Share Posted October 6, 2005 GUICtrlCreateCombo("", 40, 150, 250) ; creates a combo boxGUICtrlSetData(-1,$look) ;adds the array value to combo boxI'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>; GUIGuiCreate("testing", 1024, 768)WinSetState("testing", "", @SW_MAXIMIZE); Select and Read a directory$myfoldervar = FileSelectFolder("Choose a folder.", "")$FileList=_FileListToArray($myfoldervar); Show it in a ComboGUICtrlCreateCombo("", 40, 150, 250) ; create comboGUICtrlSetData(-1,$FileList) ;adds the array value to combo box ???; GUI MESSAGE LOOPGuiSetState()While GuiGetMsg() <> $GUI_EVENT_CLOSEWEnd Link to comment Share on other sites More sharing options...
GaryFrost Posted October 6, 2005 Share Posted October 6, 2005 @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@BodiCODE#include <GuiConstants.au3>#Include <File.au3>#Include <Array.au3>; GUIGUICreate("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 ComboGUICtrlCreateCombo("", 40, 150, 250) ; create comboGUICtrlSetData(-1, $s_text) ;adds the array value to combo box ???; GUI MESSAGE LOOPGUISetState()While GUIGetMsg() <> $GUI_EVENT_CLOSEWEnd 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 More sharing options...
Gene Posted October 13, 2005 Share Posted October 13, 2005 (edited) GUICtrlCreateCombo("", 40, 150, 250) ; creates a combo boxGUICtrlSetData(-1,$look) ;adds the array value to combo boxI'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 October 13, 2005 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 More sharing options...
GaryFrost Posted October 13, 2005 Share Posted October 13, 2005 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 More sharing options...
Gene Posted October 13, 2005 Share Posted October 13, 2005 (edited) 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 WendThanks 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 WendAnd 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 ExitOf 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 October 13, 2005 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 More sharing options...
GaryFrost Posted October 13, 2005 Share Posted October 13, 2005 ah, win2k, just change the height of the combobox to 100 or more, should fix your problem 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now