A chunking mystery

Phil Davis revdev at pdslabs.net
Fri Mar 14 00:20:11 EDT 2008


Hi David,

I don't know if this is the total answer to your problem, but you're 
mixing "repeat" forms.

Using the "repeat for each" form, you would normally examine the 
contents of the line variable you named in the repeat. But your code 
always check line 1 of the 'parent' container instead.

Try this:
repeat for each line thisLine in tSource
    if item 2 of thisLine <> "0" then
      put tThisLine & cr after tCleanSource
    end if
end repeat
delete last char of tCleanSource -- the trailing CR


Or if you want to use the "repeat with" form, try this:
repeat with x = the number of lines in tSource down to 1
    if item 2 of line x of tSource = "0" then
      delete line x of tSource
    end if
end repeat

In the 2nd example, it's safest to go from end to beginning of the data 
since you're deleting lines by their line number. Going from start to 
end will cause the loop to skip a line whenever one is deleted.

Also, the first example will be faster. The larger your file, the more 
you'll see the difference in speed.

Take care -
Phil Davis



David Coker wrote:
> Hello folks,
> I have a handler built that does nothing more than checking for a zero
> in a specific item located in a scrolling text field and if found,
> deletes the entire line. It seemed to work flawlessly with all of the
> test files that I had chosen to work with while building the app. No
> problem, I thought.
>
> Then I started using an assortment of real data (all CSV format, with
> the target item in the same location), only to find that I was getting
> unreliable results. I have a fairly large data file where the app
> always works, yet another much smaller one that the target zeros are
> almost ignored. I can mix and match sample data from both files and
> get varied results. I've even tried sorting the field to get them up
> to the top of the file, but that doesn't seem to make a difference.
>
>   repeat for each line thisLine in tSource
>     if item 2 of line 1 of tSource = "0" then
>       delete line 1 of tSource
>     end if
>   end repeat
>
> The sample files I'm using came from different sources, but are
> otherwise identical in general composition, structure and delimited
> format. Any ideas as to what I need to be looking for? Still using the
> 2.51 studio version. (bummer!)
>
> I'd totally appreciate any boost in the right direction.
> David
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>   

-- 
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net




More information about the use-livecode mailing list