[Coco] INSTR question
alsplace at pobox.com
Thu Feb 9 16:48:23 EST 2017
> On Feb 9, 2017, at 3:40 PM, Salvador Garcia via Coco <coco at maltedmedia.com> wrote:
> It returns one because when the string to search is empty it returns the Start position. Since you've omitted this, it defaults to 1.
> Try this:
> PRINT INSTR(3,"1234567","")
> This is what happened with VB6. It seems that this version of Basic carried over the behavior from earlier versions, including CoCo BASIC.
> Have a look at the table under the section for Return Value:
Excellent. Thank you! That answers my question. Not a bug, but the way it works, which means it cannot be used without checking the string to be empty first, or doing a workaround like I just tried.
10 IF A$<>"" THEN LN=INSTR("ABCD",A$):ON LN
It's a pity, because ON x GOTO/GOSUB ignore the 0 value, so it it worked the same way, this could be done:
ON INSTR("ABC",INKEY$) GOTO 100,200,300
That's quite a bit faster than using a variable.
More information about the Coco