API 2 Bit Me This Week And I Wasn’t Even Using It

I had one of those weeks where my nearly 20 years of Xojo knowledge went up in smoke.  I started a new project and was using the classic API.  I did this because it was a database application and I’m not convinced that the major database changes with API 2.0 are tried, true, tested, and worthy of every day usage.

I was testing to see if a string was contained in another string and did this:

Dim bDoesNotHave As Boolean = sString1.InStr(kSomeConstant) = -1

Gosh, where do I even begin to explain the hot mess this is?  First, InStr (classic API) returns a zero if sString1 doesn’t contain the string kSomeConstant.  Second, the API 2.0 replacement is String.IndexOf but that does return -1 if the string isn’t there.

Thankfully, testing discovered that the code wasn’t working but I felt pretty dumb.  This is one of those areas where I think API 2.0 is totally going to mess old timers like me up.  I’ve used Instr for nearly 20 years and all of a sudden my brain tells me, oh, no, this returns -1 if the string isn’t there.  True – only if you’re using API 2 and I was not.  Which is so weird because I’ve not created ANY new projects in API 2 – just some random testing.

I’m mad at myself for not remembering and mad at Xojo for changing the rules.