Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2009
    Location
    Athens, Greece
    Posts
    31

    Huh? How to count the occurences of all text found in a richtext object?

    The following is my attempt that did not produce correct results.
    Can somebody help me on this?
    Thanks...


    Code:
    search_result = RichText.FindText("RichText1", "findthis", 1, -1, false, false);
    
    -- Create a table containing all possible matches.
    all_matches = {};
    
    min = search_result.Start+1;  -- The number to start at
    max = RichText.GetTextLength("RichText1");  -- The number to stop at
    step = 1;  -- The number to count by
    
    --try to find all matches
    for count_var = min, max, step do --beginning of for loop
    	   search_result=nil; --just to avoid confussion with previous references, just in case anyway
    	   search_result = RichText.FindText("RichText1", "findthis", count_var, -1, false, false);
    
    
           --check to see if it is a match
         if (search_result) then
           all_matches[(Table.Count(all_matches)+1)]=search_result;
         end
    
    
    end    ---end of for loop
    
    ------
    ------
    ------
    ------ IF ALL CORRECT UNTILL NOW, THE FOLLOWING SHOULD DISPLAY CORRECT RESULTS
    
    no_of_matches_found = Table.Count(all_matches);
    
    ---- BUT THE NUMBER DISPLAYED IS NOT AS EXPECTED! IT IS A REALLY HUGE ONE INSTEAD!

  2. #2
    Join Date
    Mar 2009
    Location
    Athens, Greece
    Posts
    31

    Oops

    I made the following amendments: (just added a check for duplicate values)
    Code:
           --check to see if it is a match and check for duplication of values
         if ((search_result~=nil)and (search_result~=previous_search_result)) then
           all_matches[(Table.Count(all_matches)+1)]=search_result;
    	   previous_search_result=search_result;
         end
    But still i get wrong results.

    I believe that it must be something about how the "Richtext.FindText" built in function has been implemented.
    I am really stuck with this one, i have no more ideas on top off my head.
    Last edited by hliobasilema; 04-03-2009 at 08:05 AM.

  3. #3
    Join Date
    Mar 2009
    Location
    Athens, Greece
    Posts
    31

    search_result~=previous_search_result
    SOLVED

    I just changed the above line with:

    search_result.Start~=search_result.End



    now works fine. Thank you everybody who have read my case

  4. #4
    Join Date
    Jul 2002
    Location
    Just South of Reality
    Posts
    778
    You solved it before I hade a chance to reply - I dug this out of some old code I had and adapted it to you...

    Code:
    all_matches = {};
    search_variable="findthis"
    bump=1
    beg=1
    x=1
    while x==1 do
    	search_result = RichText.FindText("RichText1", search_variable, beg, -1, false, false);
    	    if (search_result) then    
    			beg=search_result.End +1
    			all_matches[bump]=search_result
    			bump=bump+1
    		else
    			x=0;	
    		end	
    end
    Dialog.Message("matches:", ""..Table.Count(all_matches))

  5. #5
    Join Date
    Mar 2009
    Location
    Athens, Greece
    Posts
    31
    Never it is too late! Here you give me a chance to consider your code that is
    more elegant.
    So thank you!

    I like a lot the "beg=search_result.End +1" part!!!

    But isn't this code going to break the loop as soon
    as we don't have a match???

    Shouldn't the while loop be within another loop?

  6. #6
    Join Date
    Jul 2002
    Location
    Just South of Reality
    Posts
    778
    Try it. I haven't tested it completely, but it should check the entire RT for all occurances...and yeah, the code will break when you don't have a match...I thought that was the premise. It should check for each occurance and store them in the table (for additional reference if desired).

  7. #7
    Join Date
    Mar 2009
    Location
    Athens, Greece
    Posts
    31
    Quote Originally Posted by holtgrewe View Post
    Try it. I haven't tested it completely, but it should check the entire RT for all occurances...and yeah, the code will break when you don't have a match...I thought that was the premise. It should check for each occurance and store them in the table (for additional reference if desired).
    What happens is that this code will only capture the first match. As soon as it will start looking for the second will stop.

    But it should not stop and continue looking untill the end of document trying to find yet another match.

  8. #8
    Join Date
    Jul 2002
    Location
    Just South of Reality
    Posts
    778
    That's strange...I just tested it and it works fine here.
    Sorry it didn't work for you...just scrap my code and use your solution.

  9. #9
    Join Date
    Jul 2002
    Location
    Just South of Reality
    Posts
    778
    hliobasilema
    Here's a quick example of my test. Maybe we're not on the same page as to what you are wanting to do.
    Attached Files

Similar Threads

  1. rich text object example requested
    By sue in forum AutoPlay Media Studio 7.5
    Replies: 8
    Last Post: 09-07-2008, 09:34 PM
  2. Example: Loading Paragraph Text Using a Timer
    By Jonas DK in forum AutoPlay Media Studio 5.0 Examples
    Replies: 7
    Last Post: 11-25-2004, 05:10 PM
  3. Text Object Question???
    By tkistre in forum AutoPlay Media Studio 4.0
    Replies: 5
    Last Post: 01-21-2003, 08:41 PM
  4. INFO: Difference between the Media Player Object and the AVI Object
    By Support in forum AutoPlay Media Studio 4.0 Examples
    Replies: 0
    Last Post: 10-29-2002, 02:15 PM
  5. TUTORIAL: Showing and Hiding Objects in AutoPlay Menu Studio 3.0
    By Support in forum AutoPlay Menu Studio 3.0
    Replies: 0
    Last Post: 10-10-2002, 02:39 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