Page 1 of 2
Identifying occurences of specified text in one substack and report to another substack
Posted: Tue Apr 02, 2019 3:34 pm
by kresten
I am working to transform a process where results were delivered to an external file to a format were results now instead shall come to another substack
Briefly: 2 substacks:
a) "Phenomenalog", accumulating daycards, with textfield, for users diary notes
b) "Parsings" with two fields :
i) "searching" & ii) "occurrences"
The handler "phenoparse" is placed in the script of stack "Phenomenalog".
It permits user to specify a search-term and shall then scan the texts of all daycards identifying lines where the specified word(s) /name/number appears and report them
as ocurrences on a new card in the "Parsings" stack.
I attach the script of the handler in the hope that someone can suggest how to repair it.
< on phenoparse
global phenodate,cue,start,hitcard
ask "Which word shall be searched?"
if it is empty then
exit phenoparse
else
put it into cue
end if
ask "How many lines before ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into avant
ask "How many lines after ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into apres
open stack "Parsings"
new card
open field "searchings"
put "Parsed for" && cue && phenodate after field "searchings"of stack "Parsings"
close stack "Parsings"
go first card of stack "Phenomenalog"
find string cue in field "TextField"
if the result is "not found" then
answer "Cannot find this word"
exit phenoparse
else
put short name of this card && the foundchunk into start
put short name of this card into hitcard
put "<p>" & start & hitcard &"</p>" into field “occurrences” of last card of stack "Parsings"
put "<p>" & short name of this card & "</p>" into field “occurrences” of last card of stack "Parsings"
-- put the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" after field “occurrences” of stack pParsings
end if
repeat
set cursor to busy
find string cue in field "TextField"
if short name of this card && the foundchunk is start then
exit repeat
end if
if short name of this card is not hitcard then
put short name of this card into hitcard
put "<p> ----------------------</p>" after field “occurrences” of stack “Parsings”
put "<p>" & short name of this card & "</p>" after field “occurrences” of stack “Parsings”
end if
put the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" after field “occurrences” of stack “Parsings”
end repeat
go last card
put return & phenodate && the time && "Parsed:" && cue after field "TextField"
show stack "Parsings"
end phenoparse />
Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Tue Apr 02, 2019 4:45 pm
by dunbarx
Hi again.
This is the same as your post in the "Experienced Developers" pane, no?
I wrote there, though you never commented if I was anywhere near the problem:
Hi,
Please, please frame code offerings within the code tags (</>). It makes it much easier to see what is going on.
I glanced at your handler. Is this correct?
Code: Select all
if short name of this card && the foundchunk is start then
See the line properly "tagged"? And does this make sense?
Craig
Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Thu Apr 04, 2019 7:26 pm
by kresten
I tried to give a more precise title to the topic and a clearer description of the setup. Also the version of the script was slightly modified. I am too ignorant to find help in Your question about a single line in the handler .
I hope you or other visitors could suggest ways to elaborate the script to avoid error(s?)
Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Thu Apr 04, 2019 8:04 pm
by dunbarx
Kresten,
The line I mentioned is about 75% down the handler. I only glanced at your code, and wanted to make sure this line, which seems just a little odd, was what you meant.
Was an error thrown, or did the handler just not work?
In any case, in the future, do place code in code brackets.
Craig
Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Thu Apr 04, 2019 8:59 pm
by bogs
Hi again kresten
In case you aren't sure what Craig means by putting your above code into a code block, look at the top of your post with the code in it for this pencil (right hand side)

- Edit the post pencil...
- Selection_001.png (7.59 KiB) Viewed 9789 times
After you click on that, highlight all your code in the post, and click on the button that looks like [</>] -

- It is all in the code...
...and you'll wind up with something like this once you click on "submit"
Code: Select all
< on phenoparse
global phenodate,cue,start,hitcard
ask "Which word shall be searched?"
if it is empty then
exit phenoparse
else
put it into cue
end if
ask "How many lines before ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into avant
ask "How many lines after ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into apres
open stack "Parsings"
new card
open field "searchings"
put "Parsed for" && cue && phenodate after field "searchings"of stack "Parsings"
close stack "Parsings"
go first card of stack "Phenomenalog"
find string cue in field "TextField"
if the result is "not found" then
answer "Cannot find this word"
exit phenoparse
else
put short name of this card && the foundchunk into start
put short name of this card into hitcard
put "<p>" & start & hitcard &"</p>" into field “occurrences” of last card of stack "Parsings"
put "<p>" & short name of this card & "</p>" into field “occurrences” of last card of stack "Parsings"
-- put the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" after field “occurrences” of stack pParsings
end if
repeat
set cursor to busy
find string cue in field "TextField"
if short name of this card && the foundchunk is start then
exit repeat
end if
if short name of this card is not hitcard then
put short name of this card into hitcard
put "<p> ----------------------</p>" after field “occurrences” of stack “Parsings”
put "<p>" & short name of this card & "</p>" after field “occurrences” of stack “Parsings”
end if
put the htmltext of line (word 2 of the foundline) - avant to (word 2 of the foundline) + apres of field "Textfield" after field “occurrences” of stack “Parsings”
end repeat
go last card
put return & phenodate && the time && "Parsed:" && cue after field "TextField"
show stack "Parsings"
end phenoparse />
It will make your posts with long runs of code in them easier for everyone else to read.
As far as the code you posted goes, I'm not sure why you have this arrow in the first line -
< on phenoparse
or this in the last line
end phenoparse />
Since they are outside the actual handler, though, I'm not sure they affect it either, just was puzzling to look at.
Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Thu Apr 04, 2019 11:20 pm
by dunbarx
Bogs.
My code block icon looks like this: </>
Is this a Mac thing?
Craig
Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Fri Apr 05, 2019 3:11 am
by bogs
dunbarx wrote: ↑Thu Apr 04, 2019 11:20 pm
My code block icon looks like this: </>
Is this a Mac thing?
It is an ascii art thing, I wanted to include the button like surrounding, but now I realize that to get the (somewhat) fuller effect, I needed to include the bottom [
</>]

Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Fri Apr 12, 2019 6:19 pm
by kresten
Hi Dunbarx and bogs
I have been away for some days, now trying to understand your advices.
the line "if short name of this card && the foundchunk is start then" was meant to put an end to the scanning when the first occurrence is re-met
Code: Select all
on phenoparse
global phenodate,cue,start,hitcard
ask "Which word shall be searched?"
if it is empty then
exit phenoparse
else
put it into cue
end if
ask "How many lines before ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into avant
ask "How many lines after ?" with "0"
if it is cancel then
exit phenoparse
end if
put it into apres
open stack "Parsings"
new card
open field "searchings"
put "Parsed for" && cue && phenodate after field "searchings"
lock screen
set lockmessages to true
go first card of stack "Phenomenalog"
find string cue in field "TextField"
if the result is "not found" then
answer "Cannot find this word"
exit phenoparse
else
put short name of this card && the foundchunk into start
put short name of this card into hitcard
close stack "Parsings"
put "<p>" & start & hitcard "</p>" after field “occasions” of stack “Parsings”
put "<p>" & short name of this card & "</p>" after field “occasions”of stack Parsings
end if
repeat
set cursor to busy
find string cue in field "TextField"
if short name of this card && the foundchunk is start then
exit repeat
end if
if short name of this card is not hitcard then
put short name of this card into hitcard
put "<p> ----------------------</p>" after field “occasions” of stack “Parsings”
put "<p>" & short name of this card & "</p>" after field “occasions” of stack “Parsings”
end if
end repeat
go last card
put return & phenodate && the time && "Parsed:" && cue after field "TextField"
show stack "Parsings"
end phenoparse
Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Fri Apr 12, 2019 7:49 pm
by dunbarx
Hi.
"if short name of this card && the foundchunk is start then
It is just an odd construction, and I wanted to make sure it was what you intended. The line of code is in and of itself sound.
It would concatenate two strings. So if the short name of the card is "myData", and the foundChunk is
"char 37 to 43 of field 10" then you would be saying:
Code: Select all
if "myData char 37 to 43 of field 10" = start then...
Do you see? This string looks odd to me, though no error would be thrown.
Using the foundChunk is itself an issue; it is fragile. You must always save it the instant you have it, because it will be discarded by LC if you do almost anything else subsequently. That is for later, though.
But is that what you had in mind? I bet not.
Craig
Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Sat Apr 13, 2019 9:19 am
by [-hh]
Please note that "start" is a reserved word.
Using it as variable name may create problems in some situations.
Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Sat Apr 13, 2019 1:38 pm
by dunbarx
Hermann is correct.
You can use a reserved word like "start":
Code: Select all
on mouseUp
put "XYZ" into start
if start = "XYZ" then answer char 2 of start
end mouseUp
But just don't. And you do not want to have to look up each word when you are writing your code to make sure it is not reserved, so get into the habit of using variable names like "tStart" or "inTheBeginning".
But we still have issues with your code, no?
Craig
Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Sat Apr 13, 2019 2:29 pm
by Klaus
Well, you just need to look at your script (hit TAB from time to time if neccessary)!
All reserved words are somehow colorized, aren't they?

Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Sat Apr 13, 2019 2:31 pm
by bogs
dunbarx wrote: ↑Sat Apr 13, 2019 1:38 pm
And you do not want to have to look up each word when you are writing your code to make sure it is not reserved, so get into the habit of using variable names like "tStart" or "inTheBeginning".
While I absolutely agree with starting variables with anything that indicates their scope, you can certainly find out if a word is reserved or not far easier than looking it up manually.
Note the picture below -
![StepOsTesters [Running] - Oracle VM VirtualBox_001.png (50.12 KiB) Viewed 9552 times StepOsTesters [Running] - Oracle VM VirtualBox_001.png](./download/file.php?id=11093&t=1)
- reserved words....
Words that are reserved such as commands, functions, keywords, etc will usually tip you they are reserved by either their color or/and font style (bold, italic, etc), so right off the bat you know it is reserved.
Messages are not colored or styled, but if you click on the 'Documentation' tab at the bottom of the editor, you will see if it is a message as soon as you finish typing.
But Craig is dead on with his suggestion, until you get to tExt for a variable

Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Sun Apr 14, 2019 8:58 pm
by dunbarx
Bogs.
I have NEVER ever written this before. I hope you are gratified and impressed. You wrote:
until you get to tExt for a variable
OK, ready?
LOL
Craig
Re: Identifying occurences of specified text in one substack and report to another substack
Posted: Sun Apr 14, 2019 9:27 pm
by bogs
dunbarx wrote: ↑Sun Apr 14, 2019 8:58 pm
Bogs.
I have NEVER ever written this before. I hope you are gratified and impressed. You wrote:
until you get to tExt for a variable
OK, ready?
LOL
Craig
I am impressed, even though it isn't mine
I got it reading the archive mailing lists, either from Jacque, or someone else responding to her. It was funny enough to stick with me for the last year +