GuiXT
Title "Occurrence Counter"
// Clear the screen
del (0,0) (100,100)

// Box for the text comparison 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="count_words.txt" size=(1,15)
  Using text = "&Text[Text1]"
  Using search = "&V[search]"

count_words.txt

GuiXT
Parameter text
Parameter search

// Start with offset 0
Set V[offset] 0

// Number of hits
Set V[n] 0

// Set text to be checked
Set Text[t] "&U[text]"

label searchnext
SearchText "t" string="&U[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 '&U[search]' appears &V[n] times in the text." _
    -statusline

Return