Title "Occurrence Counter"
// Clear the screen
del (0,0) (100,100)
// Box for the text searching tool
Box (1,1) (11,70) "Occurrence counter"
// TextBox and InputField for input
TextBox (2,2) (6,68) name="Text1" textFont="Arial" textHeight=18 maxLines=4
InputField (7,2) "Search" (7,17) name="search" size=20
// Button to compare the texts
PushButton (9,2) "@16@Count" process="search_text.txt" size=(1,15)
search_text.txt
GuiXT
// Start with offset 0
Set V[offset] 0
// Number of hits
Set V[n] 0
label searchnext
SearchText "Text1" string="&V[search]" _
fromOffset="&V[offset]" _
returnOffset="offset"
if Q[ok]
// Increase hit count
Set V[n] &V[n] + 1
// Increase search offset
Set V[offset] &V[offset] + 1
// continue searching
goto searchnext
endif
Message "The string '&V[search]' appears &V[n] times in the text." _
-statusline
Return