Announcement

Collapse
No announcement yet.

listbox with files + combobox with folder data: How to load correctly?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • listbox with files + combobox with folder data: How to load correctly?

    Hi all:

    After searching here in forum and reading the IR help file, Im blocked about one problem as title says. The explanation is as follow:

    - AMS 8 version:
    8.3.0.0. I know, there is out a new version (currently is 8.5.0.0), but I will not purchase it until Win 10 is released in summer.

    - Description of the project:
    I have a listbox with multiple select enabled, list mode and listbox's checkboxes enabled.

    In that listbox is filled all files found in a "file.find" action for each folder (3 folders with files). This action is perfomed by using one combobox. The combobox stores 1 folder per item that is used to search those files stored in. And finally a button where gets all items checked from listbox to copy to a "x" path or folder to copy all selected files.


    - Description of the problem:
    If you select a list from combobox I can see correctly all files found on listbox from a specified folder. You select a item from combobox from another items all is okay an so on. Once I picked a item up (or more than one item) by checking his checkbox associated to that item for then install later.
    I click the button copy or install by usin the "file.copy" action to a desired folder. All is okay, no problem.

    The problem is if you repeat this operation by selecting another item from combobox and then you do all operations I explained above, no error is thrown to screen. Only the combobox once selected one item to search files from a folder, the listbox does not load the found content.


    - Code I used to do this task:

    * Global functions:
    Code:
    [COLOR="blue"][B][FONT="Tahoma"]function ReloadCB()
    	ComboBox.ResetContent("ComboBox1");
    
    	CB_NamePack = {}
    	CB_NamePack[1] = "PLANE PACKS";
    	CB_NamePack[2] = "CAR PACKS";
    	CB_NamePack[3] = "TRUCK PACKS";
    	
    	for i, vItem in pairs (CB_NamePack) do
    	ComboBox.AddItem("ComboBox1", vItem, "");
    	end
    end[/FONT][/B][/COLOR]

    * On Show Event:
    Code:
    [COLOR="blue"][B][FONT="Tahoma"]ReloadCB()[/FONT][/B][/COLOR]
    *On Select from Combobox1 object:
    Code:
    [COLOR="blue"][B]
    [FONT="Tahoma"]
    nSelected = ComboBox.GetSelected("ComboBox1");
    if nSelected then
    
    	local sCategory = ComboBox.GetItemText("ComboBox1", nSelected);
    	ListBox.DeleteItem("ListBox1", -1);
    	
    	CB_DATA = {}
    	CB_DATA[1] = "PLANE PACKS";
    	CB_DATA[2] = "CAR PACKS";
    	CB_DATA[3] = "TRUCK PACKS";
    
    
    	if sCategory == CB_DATA[1] then
    		
    		ListBox.DeleteItem("ListBox1", -1);
    		Application.SetRedraw(true);
    		strDirData = ComboBox.GetItemText("ComboBox1", nSelected);
    
    		local tFiles = File.Find("Autoplay\\Docs\\"..strDirData, "*.*", false, false, nil);
    
    		if tFiles then
    
    			for i, sFilePath in pairs (tFiles) do
    			tFileParts = String.SplitPath(sFilePath); -- this breaks everypart of the filepath
    			sFileName = tFileParts.Filename; -- this one is the Filename only
    			sFileExtension = tFileParts.Extension; -- this one is File Extension only
    			sFullFileName = sFileName..sFileExtension;
    			ListBox.AddItem("ListBox1", sFullFileName, sFilePath); -- add to the ListBox
    			end
    		end
    		
    	
    	elseif sCategory == CB_DATA[2] then
    		ListBox.DeleteItem("ListBox1", -1);
    		Application.SetRedraw(true);
    		strDirData = ComboBox.GetItemText("ComboBox1", nSelected);
    
    		local tFiles = File.Find("Autoplay\\Docs\\"..strDirData, "*.*", false, false, nil);
    
    		if tFiles then
    
    			for i, sFilePath in pairs (tFiles) do
    			tFileParts = String.SplitPath(sFilePath); -- this breaks everypart of the filepath
    			sFileName = tFileParts.Filename; -- this one is the Filename only
    			sFileExtension = tFileParts.Extension; -- this one is File Extension only
    			sFullFileName = sFileName..sFileExtension;
    			ListBox.AddItem("ListBox1", sFullFileName, sFilePath); -- add to the ListBox
    			end
    		end
    		
    
    	elseif sCategory == CB_DATA[3] then
    		ListBox.DeleteItem("ListBox1", -1);
    		Application.SetRedraw(true);
    		strDirData = ComboBox.GetItemText("ComboBox1", nSelected);
    
    		local tFiles = File.Find("Autoplay\\Docs\\"..strDirData, "*.*", false, false, nil);
    
    		if tFiles then
    
    			for i, sFilePath in pairs (tFiles) do
    			tFileParts = String.SplitPath(sFilePath); -- this breaks everypart of the filepath
    			sFileName = tFileParts.Filename; -- this one is the Filename only
    			sFileExtension = tFileParts.Extension; -- this one is File Extension only
    			sFullFileName = sFileName..sFileExtension;
    			ListBox.AddItem("ListBox1", sFullFileName, sFilePath); -- add to the ListBox
    			end
    		end
    	end
    end[/FONT]
    
    [/B][/COLOR]
    *On Select from Button1 object (Here's I think it could be the problem):

    Code:
    [COLOR="blue"][B]
    [FONT="Tahoma"]count = ListBox.GetCheckedCount("ListBox1", BST_CHECKED);
    Folder.Create(_DesktopFolder.."\\My Folder");
    
    if count == nil then
    Dialog.TimedMessage("error...", "Pick up some item", 2000, MB_ICONINFORMATION);
    else
    
    	for index=1, count do
    		pathing = ListBox.GetItemData("ListBox1", index);
            File.Copy(pathing, _DesktopFolder.."\\My Folder", false, false, false, false, nil);
    	end
    
    end
    for n=1, (ListBox.GetCount("ListBox1")) do
    ListBox.SetItemCheck("ListBox1", n, BST_UNCHECKED);
    end
    
    --Reload the Combobox to reuse the combobox once the copy process is fullfilled, resetting the listbox but not the combobox
    ReloadCB()[/FONT][/B][/COLOR]
    Am I doing something wrong? where's the problem I did several ways of coding with not success I think I am missing something here?.

    Sorry for the long post I needed to be clear with the idea, my english is well, normal but not good. Thanks.

  • #2
    To begin debugging your project, check for errors after File.Find(), adding this code after every use:
    Code:
    error = Application.GetLastError();
    if (error ~= 0) then
        Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
    end
    If there is no file found (which would explain why the ListBox is no longer being updated) then this could mean that your current folder is no longer where you expect it to be. Perhaps you need to add _SourceFolder to avoid problems:
    Code:
    local tFiles = File.Find(_SourceFolder .. "\\Autoplay\\Docs\\"..strDirData, "*.*", false, false, nil);
    Ulrich

    Comment


    • #3
      Hi Ulrich, I have a question I don't get or don't understand why I can't use the hardcoded path like "Autoplay\\Docs\\"..strDirData" instead the other way you posted before if these path takes to the same place? Its rare to see your solutions works perfectly while my way of pathing a file doesn't not work.


      thanks for the help.

      Comment

      Working...
      X