Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2007
    Location
    Sydney, Australia
    Posts
    1,546

    Need some help with a ListBox problem?

    I have a ListBox that's tied in with a Dialog.FileBrowse action. Basically, the Dialog.FileBrowse action just adds strings to the ListBox, each time that a file-selection is made:
    eg.
    C:\example1.txt
    C:\example2.txt
    C:\example3.txt


    I need to get a value returned, to determine if the same string gets added twice. I can get a value returned okay, if the same string is added twice in a row, or sequentially ...
    eg.
    C:\example1.txt
    C:\example1.txt


    but how do I get a value returned if the string not added sequentially?
    eg.
    C:\example1.txt
    C:\example2.txt
    C:\example1.txt


    In other words, how would I get a value returned on the fact that C:\example1.txt has been added a second time, but a little later in the game?

  2. #2
    Join Date
    Jun 2007
    Location
    Delphi II
    Posts
    1,534
    I would use a for loop to check the contents of the listbox against the potential file. If an item from the listbox is equivalent to the one being selected by the user then do not add it an break out of the loop otherwise add it to the listbox.
    Action Plugins
    AllOn | Box | Class | Code | Cursor | DXML | Error | Frames | GlobalPaths | Group | INIPlus |KeyBind | KeyLock | MathEx | Menu | Name | Project | Resize | StatusBar
    Download

  3. #3
    Join Date
    May 2007
    Location
    Sydney, Australia
    Posts
    1,546
    Oh okay ... so like a 'do-while' loop, yeh?

    Something like,

    Code:
    a = 1;
    while a < 10 do
        a = a + 1;
    end
    Just not sure how to apply it in this instance, though?

  4. #4
    Join Date
    May 2006
    Posts
    1,443
    Global Functions:
    Code:
    function IsItemExist(strListBox,strItem)
    
    local bRet = false;
    
    nLBCount = ListBox.GetCount(strListBox); 
    
    local nCurrent = -1; 
    
    while (nCurrent < nLBCount) do 
    
        local nFound =  ListBox.FindItem(strListBox, nCurrent , LB_BYTEXT, "*"..strItem.."*");  
         
        if (nFound ~= LB_ERROR ) then 
         
            bRet = true;
            nCurrent = nFound;
            
        else
         
              nCurrent = nCurrent + 1; 
        end 
        
      return bRet,nCurrent;   
          
    end
    
    end
    AnyButton OnClick :

    Code:
    tblFiles = Dialog.FileBrowse(true, "Locate File", _DesktopFolder, "All Files (*.*)|*.*|", "", "txt", false, true); 
    
    if ( tblFiles ~= nil) then
    
     bRet,nCurrent =  IsItemExist("ListBox1",tblFiles[1]);
       if (bRet) then
    
          Dialog.Message("Notice", "Already Exist..!");
          ListBox.SelectItem("ListBox1", nCurrent);
       
       else
    
          ListBox.AddItem("ListBox1", tblFiles[1], "");
    
       end
       
    end
    Good Luck

  5. #5
    Join Date
    May 2007
    Location
    Sydney, Australia
    Posts
    1,546
    Far out reteset ... it's gonna take me a while to digest that. Many thanks, I'll investigate it and see if it's what I need.

    Having said that, while at work last night, I was comtemplating Centauri's suggestion of a loop ... but couldn't get it to work in my head. Then when I got home, after exhausting loop-ideas, substituted the ListBox with a ComboBox ... and then had a bit of an epiphany, and came up with this:

    Code:
    sValue = Dialog.FileBrowse(true, "Locate File", _DesktopFolder, "All Files (*.*)|*.*|", "", "dat", false, false);
    nValue = ComboBox.FindItem("ComboBox1", -1, LB_BYTEXTDATA, sValue[1]);
    
    	if (nValue == -1) then
    	 ComboBox.AddItem("ComboBox1", sValue[1], "");
    	 ComboBox.SetText("ComboBox1", sValue[1]);
    	end
    	
    	if nValue >0 then
         chkList = Dialog.Message("Oops!", "Entry already in list. Do you still wish to add entry?", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);
       
    		if chkList == 6 then
         	 ComboBox.AddItem("ComboBox1", sValue[1], "");
    	 	 ComboBox.SetText("ComboBox1", sValue[1]);	
    		end
    	end
    Now,it seems to work pretty good. But can I ask you 2 guys, for comments on this so-called ephiphany of mine? I know the code works, but in terms of logicality/practicality, and in terms of sticking to good-sense coding, what are your opinions on my solution? (You 2 guys are lightyears ahead of me in this department, so I'd value your opinions, yeh? Same goes for any others out there who'd like to offer up comments ... they'd be much appreciated)
    PS.
    I've attached an example, if that helps any?
    Last edited by mystica; 08-02-2009 at 01:58 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts