glarson Posted November 9, 2007 Share Posted November 9, 2007 (edited) Hi all, I am trying to make a combo list that will show the user all the .ini files in a specific folder. These files are different profiles created by the user that contain all the data populating the GUI so the user doesn't need to re-type it all each time they open the GUI. I found a function written by MSCreatoR that will populate the combo with the path to the folder containing the files, but not the files themselves. Here is the script that I found. What do I need to change to populate the files instead of the file paths. Thanksexpandcollapse popup#include <File.au3> #include <GuiConstants.au3> $Path = "D:\database\old_data" GUICreate("Get Dirs Combo", 200, 100) $Combo = GUICtrlCreateCombo("", 20, 70, 160, -1, $CBS_DROPDOWNLIST) $DirsList = _GetDirList($Path) GUICtrlSetData($Combo, $DirsList, $Path) $Button1 = GUICtrlCreateButton("Show selected", 60, 30, 80, 20) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $Button1 If $Path = GUICtrlRead($Combo) Then MsgBox(0, "", GUICtrlRead($Combo)) Else MsgBox(0, "", $Path & GUICtrlRead($Combo)) EndIf Case -3 Exit EndSwitch WEnd Func _GetDirList($sPath) Local $DirsArr = _FileListToArray($sPath, "*", 2), $RetString = $sPath & "|", $i If Not IsArray($DirsArr) Then Return $sPath For $i = 1 To $DirsArr[0] $RetString &= $DirsArr[$i] & "|" Next Return $RetString EndFunc Edited May 14, 2015 by Jon Broken code box Link to comment Share on other sites More sharing options...
Monamo Posted November 9, 2007 Share Posted November 9, 2007 Hi all, I am trying to make a combo list that will show the user all the .ini files in a specific folder. These files are different profiles created by the user that contain all the data populating the GUI so the user doesn't need to re-type it all each time they open the GUI. I found a function written by MSCreatoR that will populate the combo with the path to the folder containing the files, but not the files themselves. Here is the script that I found. What do I need to change to populate the files instead of the file paths. Thanks CODE#include <File.au3> #include <GuiConstants.au3> $Path = "D:\database\old_data" GUICreate("Get Dirs Combo", 200, 100) $Combo = GUICtrlCreateCombo("", 20, 70, 160, -1, $CBS_DROPDOWNLIST) $DirsList = _GetDirList($Path) GUICtrlSetData($Combo, $DirsList, $Path) $Button1 = GUICtrlCreateButton("Show selected", 60, 30, 80, 20) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $Button1 If $Path = GUICtrlRead($Combo) Then MsgBox(0, "", GUICtrlRead($Combo)) Else MsgBox(0, "", $Path & GUICtrlRead($Combo)) EndIf Case -3 Exit EndSwitch WEnd Func _GetDirList($sPath) Local $DirsArr = _FileListToArray($sPath, "*", 2), $RetString = $sPath & "|", $i If Not IsArray($DirsArr) Then Return $sPath For $i = 1 To $DirsArr[0] $RetString &= $DirsArr[$i] & "|" Next Return $RetString EndFunc Here's an edit of the example you gave that will populate the combobox with the names of the .INI files within a folder: CODE #include <File.au3> #include <GuiConstants.au3> $Path = FileSelectFolder("Select the folder to search", "") ; or hardcoded path below ; $Path = "" ; path to queried directory If @error Then MsgBox(48, "Error:", "No folder selected, selection cancelled.") Exit EndIf GUICreate("Get Ini Files Combo", 200, 100) $Combo = GUICtrlCreateCombo("", 20, 70, 160, -1, $CBS_DROPDOWNLIST) $fileList = _GetIniFiles($Path) GUICtrlSetData($Combo, $fileList) $Button1 = GUICtrlCreateButton("Show selected", 60, 30, 80, 20) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $Button1 If $Path = GUICtrlRead($Combo) Then MsgBox(0, "", GUICtrlRead($Combo)) Else MsgBox(0, "", $Path & "\" & GUICtrlRead($Combo)) EndIf Case - 3 Exit EndSwitch WEnd Func _GetIniFiles($sPath) Local $FilesArr = _FileListToArray($sPath, "*.ini", 1), $RetString = "", $i If Not IsArray($FilesArr) Then $RetString = "No INI files found in selected folder." MsgBox(48,"Error:",$RetString) Else For $i = 1 To $FilesArr[0] $RetString &= $FilesArr[$i] & "|" Next If StringRight($RetString,1) = "|" Then $RetString = StringTrimRight($RetString,1) EndIf EndIf Return $RetString EndFunc ;==>_GetIniFiles - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup] Link to comment Share on other sites More sharing options...
glarson Posted November 9, 2007 Author Share Posted November 9, 2007 (edited) Thanks that works but now I can't figure out how to load the data from the seleted file in the combo using a 'load' button??? Edited November 9, 2007 by glarson Link to comment Share on other sites More sharing options...
Monamo Posted November 9, 2007 Share Posted November 9, 2007 Thanks that works but now I can't figure out how to load the data from the seleted file in the combo using a 'load' button???You'd wanna add another button ("Load") and add a Case for the Load button that performs an IniRead(), etc., based upon a GUICtrlRead($Combo) - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup] Link to comment Share on other sites More sharing options...
glarson Posted November 10, 2007 Author Share Posted November 10, 2007 You'd wanna add another button ("Load") and add a Case for the Load button that performs an IniRead(), etc., based upon a GUICtrlRead($Combo)I can't get it to work. I am using 'on event mode'. Here are the bits of my script i'm working on. What am I missing??CODEOpt("GUIOnEventMode", 1)Opt("GUIDataSeparatorChar")Global $GUITitle = "AutoMining EVE Online"$EveGUI = GUICreate($GUITitle, 620,300);,853,644)GUISetOnEvent($GUI_EVENT_CLOSE, "CheckGUI")GUISetState()GUICtrlCreateTab(210,0,405,260);,0x0008)GUICtrlCreateTabItem("Main")$EveGUI_ProfileLable=GUICtrlCreateLabel("Profile",220,30,40,18)$EveGUI_ProfileInput=GuiCtrlCreatecombo("",265,30,120,100,$CBS_DROPDOWNLIST)$fileList = _GetIniFiles($Path)GUICtrlSetData($EveGUI_ProfileInput,$fileList);$EveGUI_LoadButton = GUICtrlCreateButton("Load",390,30,47,20)GUICtrlSetOnEvent($EveGUI_LoadButton, "OpenProfile1")$EveGUI_SaveButton = GUICtrlCreateButton("Save",440,30,47,20)GUICtrlSetOnEvent($EveGUI_SaveButton, "SaveProfile")$EveGUI_EVEPathLable=GUICtrlCreateLabel("EVE Path",220,67,75,18)$EveGUI_EVEPath=GUICtrlCreateInput("",230,87,340,20);needs to be filled by $EVEfolder result for file open dialog$EveGUI_EVEPathButton = GUICtrlCreateButton("...",575,87,30,20);button = $EVEPath file open dialogGUICtrlSetOnEvent($EveGUI_EVEPathButton, "SelectFileFolderEVE")$EveGUI_ProfilePathLable=GUICtrlCreateLabel("Save Profile Path",220,117,110,18)$EveGUI_ProfileSavePath=GUICtrlCreateInput("",230,137,340,20)$EveGUI_ProfileSavePathButton = GUICtrlCreateButton("...",575,137,30,20);button = $ProfilePath file open dialogGUICtrlSetOnEvent($EveGUI_ProfileSavePathButton, "SelectFileFolderSave");$EveGUI_MouseLable=GUICtrlCreateLabel("Mouse Speed",220,167,80,18); Mouse To use$EveGUI_MouseSpeed=GUICtrlCreateInput("15",230,187,50,20)GUICtrlSetLimit(GuiCtrlCreateUpDown($EveGUI_MouseSpeed),100,10)GUICtrlSetOnEvent($EveGUI_MouseSpeed, "CheckGUI")Func OpenProfile1() Select Case @GUI_CtrlId=$EveGUI_LoadButton $file=GUICtrlRead($EveGUI_ProfileInput) GUICtrlSetData($EveGUI_MouseSpeed,IniRead($file,"Main","Mouse","")) GUICtrlSetData($EveGUI_ProfileSavePath,IniRead($file,"Main","Save","")) GUICtrlSetData($EveGUI_EVEPath,IniRead($file,"Main","EVE","")) EndSelectEndFuncFunc SaveProfile() $title = "Save" $initialdir = $ProfileFolder $filter = "ini (*.ini)" $iOption = 1 + 2 +16; verifies file existance, popup messagebox if filename entered doesn't exist $userdat ="Default.ini"; default initial filename (or none) for dialog input $parentgui = 0 ; or Hwnd returned from GuiCreate $file=FileSaveDialog($title, $initialdir, $filter, $iOption, $userdat) If StringRight($file, 4) <> ".ini" Then $file &= ".ini" IniWrite($file,"Main","Mouse",$MouseSpeed);need to add all of the gUI variables to .ini file except login info IniWrite($file,"Main","Save",$ProfileFolder) IniWrite($file,"Main","EVE",$EVEFolder)EndFuncFunc OpenProfile() $title1 = "Open" $initialdir1 = $ProfileFolder $filter1 = "ini (*.ini)" $iOption1 = 1 + 2 + 16; verifies file existance, popup messagebox if filename entered doesn't exist $userdat1 = "Default.ini" ; default initial filename (or none) for dialog input $parentgui1 = 0 ; or Hwnd returned from GuiCreate $file=FileOpenDialog($title1, $initialdir1, $filter1, $iOption1, $userdat1);, "", $parentgui1) GUICtrlSetData($EveGUI_MouseSpeed,IniRead($file,"Main","Mouse","")) GUICtrlSetData($EveGUI_ProfileSavePath,IniRead($file,"Main","Save","")) GUICtrlSetData($EveGUI_EVEPath,IniRead($file,"Main","EVE",""))EndFuncWhen I use the "opendProfile" function everything works fine, all of the fields get populated, but I can't get it to work if I try and load from the combo menu. Link to comment Share on other sites More sharing options...
GaryFrost Posted November 11, 2007 Share Posted November 11, 2007 Just to show how to populate the combobox with the beta function _GUICtrlComboBox_AddDir, simple one liner. expandcollapse popup#include <GUIComboBox.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) $Debug_CB = False ; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work Global $hCombo, $Path Global $GUITitle = "AutoMining EVE Online" Global $EveGUI, $EveGUI_ProfileLable, $EveGUI_ProfileInput Global $EveGUI_LoadButton, $EveGUI_SaveButton, $EveGUI_EVEPathLable Global $EveGUI_EVEPath, $EveGUI_EVEPathButton, $EveGUI_ProfilePathLable Global $EveGUI_ProfileSavePath, $EveGUI_ProfileSavePathButton Global $EveGUI_MouseLable, $EveGUI_MouseSpeed Global $ProfileFolder Global $MouseSpeed Global $EVEFolder _Main() Func _Main() $Path = FileSelectFolder("Select the folder to search", "") ; or hardcoded path below ; $Path = "" ; path to queried directory If @error Then MsgBox(48, "Error:", "No folder selected, selection cancelled.") Exit EndIf $EveGUI = GUICreate($GUITitle, 620, 300);,853,644) GUISetOnEvent($GUI_EVENT_CLOSE, "CheckGUI") GUISetState() GUICtrlCreateTabItem("Main") $EveGUI_ProfileLable = GUICtrlCreateLabel("Profile", 220, 30, 40, 18) $EveGUI_ProfileInput = GUICtrlCreateCombo("", 265, 30, 120, 100, $CBS_DROPDOWNLIST) ;============================================================== ; Add files - no need for creating find file function _GUICtrlComboBox_AddDir($EveGUI_ProfileInput, $Path & "\*.ini") ;============================================================== $EveGUI_LoadButton = GUICtrlCreateButton("Load", 390, 30, 47, 20) GUICtrlSetOnEvent($EveGUI_LoadButton, "OpenProfile1") $EveGUI_SaveButton = GUICtrlCreateButton("Save", 440, 30, 47, 20) GUICtrlSetOnEvent($EveGUI_SaveButton, "SaveProfile") $EveGUI_EVEPathLable = GUICtrlCreateLabel("EVE Path", 220, 67, 75, 18) $EveGUI_EVEPath = GUICtrlCreateInput("", 230, 87, 340, 20);needs to be filled by $EVEfolder result for file open dialog $EveGUI_EVEPathButton = GUICtrlCreateButton("...", 575, 87, 30, 20);button = $EVEPath file open dialog GUICtrlSetOnEvent($EveGUI_EVEPathButton, "SelectFileFolderEVE") $EveGUI_ProfilePathLable = GUICtrlCreateLabel("Save Profile Path", 220, 117, 110, 18) $EveGUI_ProfileSavePath = GUICtrlCreateInput("", 230, 137, 340, 20) $EveGUI_ProfileSavePathButton = GUICtrlCreateButton("...", 575, 137, 30, 20);button = $ProfilePath file open dialog GUICtrlSetOnEvent($EveGUI_ProfileSavePathButton, "SelectFileFolderSave") ; $EveGUI_MouseLable = GUICtrlCreateLabel("Mouse Speed", 220, 167, 80, 18); Mouse To use $EveGUI_MouseSpeed = GUICtrlCreateInput("15", 230, 187, 50, 20) GUICtrlSetLimit(GUICtrlCreateUpdown($EveGUI_MouseSpeed), 100, 10) GUICtrlSetOnEvent($EveGUI_MouseSpeed, "CheckGUI") ; Loop until user exits While 1 Sleep(10) WEnd GUIDelete() EndFunc ;==>_Main Func CheckGUI() Exit EndFunc ;==>CheckGUI Func OpenProfile1() Local $file Select Case @GUI_CtrlId = $EveGUI_LoadButton $file = $Path & "\" & GUICtrlRead($EveGUI_ProfileInput) GUICtrlSetData($EveGUI_MouseSpeed, IniRead($file, "Main", "Mouse", "")) GUICtrlSetData($EveGUI_ProfileSavePath, IniRead($file, "Main", "Save", "")) GUICtrlSetData($EveGUI_EVEPath, IniRead($file, "Main", "EVE", "")) EndSelect EndFunc ;==>OpenProfile1 Func SaveProfile() Local $title, $initialdir, $filter, $iOption, $userdat, $parentgui, $file $title = "Save" $initialdir = $ProfileFolder $filter = "ini (*.ini)" $iOption = 1 + 2 + 16; verifies file existance, popup messagebox if filename entered doesn't exist $userdat = "Default.ini"; default initial filename (or none) for dialog input $parentgui = 0 ; or Hwnd returned from GuiCreate $file = FileSaveDialog($title, $initialdir, $filter, $iOption, $userdat) If StringRight($file, 4) <> ".ini" Then $file &= ".ini" IniWrite($file, "Main", "Mouse", $MouseSpeed);need to add all of the gUI variables to .ini file except login info IniWrite($file, "Main", "Save", $ProfileFolder) IniWrite($file, "Main", "EVE", $EVEFolder) EndFunc ;==>SaveProfile Func OpenProfile() Local $title, $initialdir, $filter, $iOption, $userdat, $parentgui, $file $title = "Open" $initialdir = $ProfileFolder $filter = "ini (*.ini)" $iOption = 1 + 2 + 16; verifies file existance, popup messagebox if filename entered doesn't exist $userdat = "Default.ini" ; default initial filename (or none) for dialog input $parentgui = 0 ; or Hwnd returned from GuiCreate $file = FileOpenDialog($title, $initialdir, $filter, $iOption, $userdat);, "", $parentgui1) GUICtrlSetData($EveGUI_MouseSpeed, IniRead($file, "Main", "Mouse", "")) GUICtrlSetData($EveGUI_ProfileSavePath, IniRead($file, "Main", "Save", "")) GUICtrlSetData($EveGUI_EVEPath, IniRead($file, "Main", "EVE", "")) EndFunc ;==>OpenProfile Func SelectFileFolderEVE() EndFunc ;==>SelectFileFolderEVE Func SelectFileFolderSave() EndFunc ;==>SelectFileFolderSave 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...
glarson Posted November 11, 2007 Author Share Posted November 11, 2007 thanks, but I still can't get the script to load the value in the combobox. Help Link to comment Share on other sites More sharing options...
GaryFrost Posted November 11, 2007 Share Posted November 11, 2007 thanks, but I still can't get the script to load the value in the combobox.Help I made corrections to your OpenProfile1 function, so if you have the right section and value names it should work.If your on Win2K make the height of the ComboBox 120 or higher. 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...
glarson Posted November 11, 2007 Author Share Posted November 11, 2007 I made corrections to your OpenProfile1 function, so if you have the right section and value names it should work.If your on Win2K make the height of the ComboBox 120 or higher.Thank, that solved it!!! 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