rather simple if-then-else not working

When I run the script below in my application … I cannot complete the first “if” statement. The text field value gets set to 0. If I remove the “else if”, the script places the proper answer in the text field. It’s almost like my “if then else” statement is broken … any clues?

set restartCompletedCycles to SearchFileWithString(somePOSIXFile, "cycling")
set sleepCompletedCycles to SearchFileWithString(somePOSIXFile, "sleep cycle")

if restartCompletedCycles > 0 then
	set contents of text field "numOfCompCycle" of window "mainWindow" to restartCompletedCycles
	set testType to "restart"
else if sleepCompletedCycles > 0 then
	set contents of text field "numOfCompCycle" of window "mainWindow" to sleepCompletedCycles
	set testType to "sleep"
end if

on SearchFileWithString(fileAsPOSIX, theString)
	return (do shell script "/usr/bin/grep -w -c" & space & quoted form of theString & space & quoted form of fileAsPOSIX & space & "; echo")
end SearchFileWithString

I’m not sure but you might try coercing the results to a number before you run the if statement. “0” as text is greater than 0 as a number so I don’t think your if statement is doing as intended. Replace these 2 lines like so and see if that helps.

set restartCompletedCycles to SearchFileWithString(somePOSIXFile, “cycling”) as number
set sleepCompletedCycles to SearchFileWithString(somePOSIXFile, “sleep cycle”) as number