Yes, OK, I know. VB6 is a dead, bloated monster, as in fact is my edition of the ADO controls. But we have to use them for this project.
And my God, it's funny how terrible it is.
My latest 1-hour-scratching-your-head puzzle is purely an ADO thing. Now, I was designing the interface for filtering a table of appointments, based on Staff Name and/or text in the Appointment Memo or Appointment Type (amongst various other options).
The strategy is building a string for the Filter property of the Recordset. So first I test it with a Staff name. Great! It picks up the not-blank, substitutes it into the SQL filter, and shows the new list.
Now, let's test the Memo/Type filter. Great! It only shows appointments with memos or types containing "Software".
So let's test them both together.
BIG MISTAKE. Runtime Error 3001: Arguments are of the wrong type, are out of acceptable range, or are in conflict with each other.
So I sit there, scratching my head, wrapping things in multiple parantheses to ensure that I'm not accidentally AND-ing together two strings or something. No joy.
So I start searching the internet. 14,000 results. Oh, good. Not just me then.
But there happen to be *thousands* of different ways of generating this error.
Anyway, I eventually track down this ancient, shelved Microsoft Help and Support document. Guess what?
"...Though there is no precedence for AND and OR, the ADO Filter property does not allow you to group OR clauses within parentheses and AND clauses without parentheses...."
That is, the syntax "(cond1 OR cond2) AND cond3" is illegal.
Yep.
Totally illegal.
The article helpfully suggests the following alternatives:
- "(cond1 AND cond2) OR cond3"
- "(cond1 OR cond2) OR cond3"
- "(cond1 AND cond2) AND cond3"
... before pointing out that "... the rules of logic result in very different results ...". No sh*t, Sherlock. We should, in fact, "Be sure that your two filter statements are logically equivalent." What an idea(!)
It finishes by pointing out that "(cond1 OR cond2) AND cond3" is equivalent to "(cond1 AND cond3) OR (cond2 AND cond3)". Thanks. They can expand Boolean brackets!
'ho's a clever boy 'en?
Of course, this isn't that helpful if you don't know how many AND conjunctions you're going to be making. In fact, it's damn near useless without writing a function that expands the brackets at runtime.
Oh wait, it *hasn't* quite finished yet.
Status: This behavior is by design.
Well that's just f***ing perfect.
As to the VB6 side of things, check out this hilarious article by Dr. Dobb, written in 2000. Yes, yet all of the issues remain relevant.
And funny.
V - peace.
1 Comment