Albeit scarred for life, I just survived an encounter with Visual Basic for Excel (VB 6.3). I haven't had to muck around with this kind of shit in forever (getting close to a decade), but thought it'd be neat to save the day and flex a little programming foo. Last time I did anything with VB... it was essentially contrived data munging taken from an easy to manipulate spreadsheet. This challenge? Reading a chunk of user entered data and populating a drop-down list box. Not so hard, right? Right? Oh. My. God.
The data input required me to iterate over a non-unique list of values in a column of a spreadsheet, create a unique list, sort, and insert the result in to a combo box (drop down list, whatever your widget vernacular). Figuring this must be a well documented method or function, I searched inside of Microsoft's VB help editor for term array to get a list of helper functions. It should have been a clue that this was gunna suck when the result was nearly empty and largely irrelevant.
But, being the stubborn clod that I am with regards to being able to hammer through problems, this did not deter (hindsight? I should have run for the hills, tail tucked firmly between legs). Jumping over to $GOOG, I didn't see anything that indicated there was any kind of a unique() function or method. More surprisingly, there isn't a sort() method. Unbelievable. Wanna know what's sad? I'm not the first one to deal with this.
I dare you: type in to your search engine of choice, a search query that goes something to the extent of: "[language] array sort" or change out "sort" for "unique". Ruby, C++, Java and even PHP: all well documented and easy to search for. VB? bwhahahaha! Not so much.
After a few dozen useless search results, I started panic'ing and the reality of having to dust of a qsort() routine from some of my more anctient brain tapes was starting to seem like a less than awful idea. Fortunately, I struck gold and it turns out other people carry around little stashes of code that return a unique array... Though I've misplaced the link, my favorite blurb of VB code was an implementation of qsort(). Honestly, when was the last time you had to write/include array primitives?
Oh! And did you know that VB lacks the ability to continue an iteration in a for loop? Try writing the C equiv in VB: for (int i = 0; i < 100; ++i) continue; I would have given my left hangnail to be able to write Continue For in the VB version. Supposedly newer versions of VB have this, but that just seems like a language omission that's beyond brain-dead. Thank god for Goto labels otherwise I'd be still hacking away I fear. *facepalm*
Microsoft has made VB painful to develop in and has crippled its help functionality on Windows. In fact, it is so bad on Windows that I resorted to using the help editor on my Mac laptop, should've been a clue (the irony of having better VB help in Mac Office can't be understated). VB remains as painful of an experience as I remember, but now that I've got a boatload more experience under my belt, it stands out even more as a technical perversion.
UniqueArray() function included after the break. I don't want to have to dick around searching for that ever again. *sigh*