Basic syntax error. Expected: Then

On running the macro code below, execution stops with str in line “If str[i] …” highlighted and the above error is displayed. Can anyone see what’s wrong?
System is Windows 10, LO version 6.1.1.2 (x64)

REM ***** BASIC *****

function CountChars(str, char)
dim count
count=0
for i=1 to len(str) 
 If str[i] = "|" Then
 	count++
 endif
next
return count

End

Basic is not C; array access is not done using square brackets, and strings are not arrays; there’s no increment operator, and returning from functions is not done using “return”… please read about Basic language first.

@mikekaganski,

TY - I was too quick with an answer (now deleted) looking only at the “if” line. Your remarks are absolutely correct.

https://help.libreoffice.org/6.3/en-US/text/sbasic/shared/main0601.html