Re: strings, again and again
Re: strings, again and again
- Subject: Re: strings, again and again
- From: "Gary (Lists)" <email@hidden>
- Date: Mon, 04 Feb 2008 18:05:01 -0500
- Thread-topic: strings, again and again
"Justin Laden" wrote:
> Thanks for the responses everyone, and your suggestions did help clear
> some things up, but not--and I want to add emphasis here--with Excel.
I didn't know there was anything to do with Excel (or I blanked that part of
it.) I don't use Excel so I can't help with that bit.
> Let me provide an example--I wrote this test script, which works,
> outside of my main code:
>
>
> set testList to {{"Q1718_00_"}, {"D1198 BAI"}, {"A3000"}}
Now you've got lists of lists. I don't understand the need for that.
Why is the data that way?
Where does the data come from?
Now you're going to need more code, along the lines:
item 1 of item 1 of...
That's no good.
> set twoList to {{}, {}, {}}
Why are you making a list of 3 empty lists?
What's so special about 3...because there were 3 things in 'testList'?
> set item 2 of twoList to find text "^[a-zA-Z][0-9]{4}" in item 2 of
> testList with regexp
Why do that? That's not what I described before.
'twoList' is -- as you defined above -- a list of 3 empty lists.
Now, you're setting item 2 of that list to some value. Why not item 1?
Item 1 should still be an empty list? Tell us why, or what you're doing.
> item 2 of twoList --> {D1198}
Doubtful.
You probably received --> {"D1198"}
There's a deal-breaking difference.
> That's real data in there, and it works
No, it's not. And I don't think so. ;)
> You all helped me see that I can't populate an empty list the way I
> thought I could. Now, I add a new empty list on every run through the
> loop--see below.
This is why you get the weird result that you describe below.
Don't ADD empty lists, just start from an empty list and add to it (you'll
be adding matched strings, not lists of a single string.)
> So first, I add a list with an empty string to the end of a my target
> range, THEN, I test the other range for the number combo, and then I
> do it again. But, with e
No. Start with an empty list and THEN add to it as you loop through.
Look:
You say you start with a list of strings. (We don't know from where.)
You then make an empty list (to hold the matches), then you loop through
your first list, looking for matches, and then add the matches (when found)
to the end of your originally empty list, building a full list of matches.
> repeat with i from 2 to (z)
Why 2, now?
> copy {""} to end of jobNumRange
No. That's making one of your problems. Why add an list of an empty string
to the end of an undefined variable? (That'll error. You don't show it, but
I can't see where this variable 'jobNumRange' gets defined.
And...don't put this INSIDE the loop. Put the empty list declaration BEFORE
the repeat.
set jobNumRange to {} -- define variable to hold matches
repeat with i from 1 to (count someListOfValuesThatYouStartWith)
-- ... with our 'firstPull' finding routine
end repeat
> set firstPull to (find text "^[a-zA-Z][0-9]{4}" in item i of
> descriptionRange with regexp)
>
> set list i of jobNumRange to matchResult of firstPull
NO! This can not work. No way.
Use:
copy matchResult of firstPull to end of jobNumRange
-- NOTE the above. JobNumRange starts off empty, then you
add to the 'end of' that list by copying.
> on error
>
> set item i of jobNumRange to {""}
Nah. You're going to get even more lists of empty strings in your big list
of matches.
If you hit an error, you probably don't want to add something like this, do
you? Wouldn't you, minimally, just ignore it, so that your ending list of
matches is at least valid?
> end try
>
> end repeat
> copy the value of range ("I1:I" & z) to jobNumRange
That line could only exist inside a 'tell application "Excel"...' block.
I don't see how you are talking to Excel. I see that you are wanting to
copy your new list of found matches to some range in Excel, I guess.
I can't help that part, but I can say that you'll need to "tell app Excel"
in there.
> No matter what, it doesn't work in EXCEL--give it a shot!
No need. It won't, period.
> The problem seems to be that I can't get the new populated list to be
> copied into an Excel column.
I'm not sure that I'd settle on that as "the problem" ;)
> This could be because the list is NOT a
> list of lists, but a list of strings and lists...
It IS a list of lists and strings, because that's what you've done (for no
gain that I can see.)
> Not sure how to get
> the regular expressions to be returned as lists.
The 'find text' command returns a record of 3 items. The first 2 tell you
the numeric range of the start and end, the 3rd is a string of the actual
found result.
That record has labels, and one of those labels is 'matchResult'.
So, when 'find text' returns its result, you ask for the 'matchResult' of
that result and you have the string.
THIS is what you should be adding to your list, named 'jobNumRange'.
The thing is, you DO know how to get the results of the 'find text' command,
but you're doing other things which mess up your final list.
Every where -- in the results below -- that you have "D1198", etc. you have
done the right thing. Everywhere you see {""} is because of your
intentional (but erroneous) adding of that empty-string list.
> Also, it seems to add lists in between the results, like so:
>
> "D1198", {""}, "D1243", {""}, "D1251", {""}, "D1285", {""}, "D1352",
> {""}, {""}, {""}
>
> Kurt, I'll fix the error handling later--thanks for the help. I want
> to get it into Excel first:)
Kurt's point was not one of cosmetics. It was suggestion that you will
start to see WHERE you have errors and WHAT those are, if you wrap your
scripts in a 'try...on error' block.
It's a suggestion to help you progress through the lines of your script,
eliminating errors in sequence.
You really should re-read his suggestion. It's nearly impossible to debug a
script without knowing where the errors are.
It doesn't look like your script is free of logical and syntactical errors
well before the form of the result that you publish above.
We don't know -- really -- what the incoming list looks like (the list that
you will search for matches), and so constructing the looping logic is just
a guessing game from what you've shown here.
Also, it appears (from my reading) that you've gone a step backward, not
forward, from the weekend's exchange.
Your script (as I returned it) seemed closer, to me, to your goal.
I'm sure we can continue to help, but you'll need to do some the basics:
show us your script (not just edited pieces), show us the input to your
script, and start using 'try/on error' to catch your errors earlier.
--
Gary
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden