滚动字段为空但它显示一些字符串为什么?
Scorlling filed is empty but it display some string why?
我有两个滚动字段,一个包含一些文本,另一个包含一些单词。例如。 (s1:s2) 冒号分隔 my objective 是为了查找第一个Scrolling 字段中出现了第二个Scrolling 中的单词数。 (例如:如果 s1 出现在第一个滚动字段中,则它显示 s1,1 表示 s1 出现一次)。在执行我的代码时它可以工作但是如果我的第一个滚动字段是空的它有时也会显示一些文本它在第一个字段中需要一些单词。 (eg:\documentclass)这个词不在第 2 个字段中。
我正在使用以下代码。
global ar
global sam
on mouseUp
--set the caseSensitive to true
put 0 into tmp
put empty into sam
put the field SRText into myArrayT
split myArrayT by CR
put the number of lines of (the keys of myArrayT) into myArrayl
repeat for each key j in myArrayT
put myArrayT[j] into k
split k by colon
put k[1] into searchStr1
put the field "MytextField" into sss
repeat for each word ass in sss
if ass contains searchStr1 then
add 1 to tmp
put ass & CR & CR after sam
put sam into ar
end if
end repeat
end repeat
answer sam
answer tmp
--answer sa
end mouseUP
on mouseDown
answer ar
put ar into ss
get ss
repeat for each word tWord in it
add 1 to wordCount[tword]
end repeat
combine wordCount by return and comma
answer wordCount
--put empty into sam
end mouseDown
您确实应该在字段名称周围使用引号。我保证有一天你会意识到,你一直在搬起石头砸自己的脚。
不要在对象引用前使用the
,
field "Field Name"
button "Field name"
但一定要在 属性 引用前使用 the
:
the number of lines of fld "Field Name"
the text of fld "Field Name"
the name of this stack
你对数组的痴迷真的没有理由。不需要时停止使用数组!它只会让事情变得过于复杂和缓慢。
我已经修改了您的 mouseUp 处理程序。我没有看你的 mouseDown 处理程序。我相信您的 mouseUp 处理程序应该如下所示:
on mouseUp
--set the caseSensitive to true
put 0 into tmp
put empty into sam
repeat for each line k in fld "SRText"
set the itemDel to colon
put item 1 of k into searchStr1
repeat for each word ass in field "MytextField"
if ass contains searchStr1 then
add 1 to tmp
put ass & colon & tmp & cr after sam
end if
end repeat
put 0 into tmp
end repeat
put sam
end mouseUp
上面的脚本是基于你的方法,我真的不明白你为什么要这样做以及你将如何处理结果。下面的脚本可能效率更高,对我来说似乎更有用。
on mouseUp
// I assume fld SRText contains a list similar to
// "abc:1" & cr & "bcd:2" & cr & "cde:1" & cr & "def:4"
put fld "SRText" into myData
split myData by cr and colon
put the keys of myData into myData
// myData is not an array!
repeat for each word myWord in fld "MytextField"
if myWord is among the lines of myData then
// use an array to store data, not to loop through
if myCounts[myWord] is empty then
put 1 into myCounts[myWord]
else
add 1 to myCounts[myWord]
end if
end if
end repeat
combine myCounts by cr and colon
put myCounts
end mouseUp
我有两个滚动字段,一个包含一些文本,另一个包含一些单词。例如。 (s1:s2) 冒号分隔 my objective 是为了查找第一个Scrolling 字段中出现了第二个Scrolling 中的单词数。 (例如:如果 s1 出现在第一个滚动字段中,则它显示 s1,1 表示 s1 出现一次)。在执行我的代码时它可以工作但是如果我的第一个滚动字段是空的它有时也会显示一些文本它在第一个字段中需要一些单词。 (eg:\documentclass)这个词不在第 2 个字段中。
我正在使用以下代码。
global ar
global sam
on mouseUp
--set the caseSensitive to true
put 0 into tmp
put empty into sam
put the field SRText into myArrayT
split myArrayT by CR
put the number of lines of (the keys of myArrayT) into myArrayl
repeat for each key j in myArrayT
put myArrayT[j] into k
split k by colon
put k[1] into searchStr1
put the field "MytextField" into sss
repeat for each word ass in sss
if ass contains searchStr1 then
add 1 to tmp
put ass & CR & CR after sam
put sam into ar
end if
end repeat
end repeat
answer sam
answer tmp
--answer sa
end mouseUP
on mouseDown
answer ar
put ar into ss
get ss
repeat for each word tWord in it
add 1 to wordCount[tword]
end repeat
combine wordCount by return and comma
answer wordCount
--put empty into sam
end mouseDown
您确实应该在字段名称周围使用引号。我保证有一天你会意识到,你一直在搬起石头砸自己的脚。
不要在对象引用前使用the
,
field "Field Name"
button "Field name"
但一定要在 属性 引用前使用 the
:
the number of lines of fld "Field Name"
the text of fld "Field Name"
the name of this stack
你对数组的痴迷真的没有理由。不需要时停止使用数组!它只会让事情变得过于复杂和缓慢。
我已经修改了您的 mouseUp 处理程序。我没有看你的 mouseDown 处理程序。我相信您的 mouseUp 处理程序应该如下所示:
on mouseUp
--set the caseSensitive to true
put 0 into tmp
put empty into sam
repeat for each line k in fld "SRText"
set the itemDel to colon
put item 1 of k into searchStr1
repeat for each word ass in field "MytextField"
if ass contains searchStr1 then
add 1 to tmp
put ass & colon & tmp & cr after sam
end if
end repeat
put 0 into tmp
end repeat
put sam
end mouseUp
上面的脚本是基于你的方法,我真的不明白你为什么要这样做以及你将如何处理结果。下面的脚本可能效率更高,对我来说似乎更有用。
on mouseUp
// I assume fld SRText contains a list similar to
// "abc:1" & cr & "bcd:2" & cr & "cde:1" & cr & "def:4"
put fld "SRText" into myData
split myData by cr and colon
put the keys of myData into myData
// myData is not an array!
repeat for each word myWord in fld "MytextField"
if myWord is among the lines of myData then
// use an array to store data, not to loop through
if myCounts[myWord] is empty then
put 1 into myCounts[myWord]
else
add 1 to myCounts[myWord]
end if
end if
end repeat
combine myCounts by cr and colon
put myCounts
end mouseUp