Okay, James.
I've also added boundary limits, and negative index, so -i means index from the right.
macro instrab(mm,bb,bk,lk, bt,bm,lm)
=====================================
byte bt=bb
byte bm at @bk
int lm=lk
mm=0
while lm
lm--
if bm=bt then mm=1 : exit while
@bm++
wend
end macro
function instranyb(sys pb,pk, int ls,lk,i,di) as int
====================================================
if not ls then return 0
if i<0 then i+=ls+1
if i<0 then i=1
if i>ls then i=ls
if di=0 then di=1
if di>0 then
if i=0 then i=1
ls=ls-i+1
else
if i=0 then i=ls
ls=i
end if
int mm
byte *bb,*bk
@bb=pb+i-1
@bk=pk
while ls
ls--
instrab(mm,bb,bk,lk)
if mm then return @bb-pb+1
@bb+=di
wend
return 0
end function
function instrany(int i,string*s,*k) as int
===========================================
return instranyb(strptr(s),strptr(k), len(s), len(k), i, 1)
end function
function instrevany(int i,string*s,*k) as int
=============================================
return instranyb(strptr(s),strptr(k), len(s), len(k), i,-1)
end function