Category Archives: Code

Elevator ‘close’ button

In the building where I’m currently working, I think I’ve found the first “close doors” button on an elevator that actually does something.

I might have come across one other elevator where the close button causes the doors to close. I’ve heard that it’s always put there, but not hooked up to anything – to provide psychological relief while waiting – to give the occupants a sense of control. Is this true, or are the door close alogorithms such that pressing the button normally has no effect?

I am not alone in considering the door close algolrithms. Apparently having a door close button that works is considered a feature by some lift manufacturers.

The User Interface on elevators is highly variable and most questionable.

And another thing: what’s this fascination with refurbishing elevators, with the shiny mirrors, the inlaid wood panelling, halogen downlights and computerised displays featuring today’s weather forecast – but an ongoing inability to tell which floor they’re on, nor operate in a manner that even the occupants of the elevator can tell is an efficient journey-planning mechanism?

Are elevators something that has preoccupied our readers’ attentions? Do they wish to rant?

When things become super freaky do a RebuildAll

I just solved an irritating problem. I had a program sending heartbeats to another, but with the wrong frequency.

Putting in a breakpoint at the point where that frequency is set showed the value at 2000ms, rather than the 5000ms we had in the registry. So I checked the registry reading code was pulling the right value into the appropriate variable, and indeed it was. No other lines of code referred to the member that held this value. There was no way of setting the value other than reading from the registry in this one location. Even putting a breakpoint on change to that variable failed to show what was going on – it never broke on change – although the program did run like a dog with that breakpoint on. Much pulling of hair ensued.

Then I took the opportunity to inspect this. And I noticed, browsing through the various values, that there was a value of 2000 in the preceeding variable.

I then proceeded to use the old adage, “When things become super freaky do a RebuildAll”, and the problem was solved. Seems like there was some sort of link problem. I just wish I’d tried it earlier.

Quick and dirty animation

I was asked how I did the animation of building the desks on my personal blog.

The camera was set up on a tripod in the corner of the room. It wasn’t set to automatically take pictures; instead I set it to its 10-second timer and periodically took pictures, generally when I was about to do something. So in a sense the pictures are all posed, and apart from the varying light outside you can’t tell that it took quite a few hours to put the first desk together, followed by a gap of a couple of days before the second one was done.

Unfortunately the camera got moved a bit while doing the second desk. I also forgot until later to take a picture of the completed desks, and by that point the tripod had been put away, so that last shot is handheld, and askew from the others. It was late, and I couldn’t be arsed lining it up exactly. Close enough.

I ended up not using some of the pictures, discarding many of those that had nobody in them, because I thought it would look better to see people moving around in each shot, rather than flashing in and out of view.

To do the animation, I considered what formats would work best for appearing on the blog page (rather than in a separate player or as a download). This ruled out using MovieMaker (which for online-use produces WMV only, so wouldn’t be playable on anything other than Windows). Animated GIF might have been quite economical bandwidth-wise, since much of each frame didn’t change, but I don’t have any good tools for that. Besides, GIF for photos sucks. MPEG compression would work a treat for something like this, but I didn’t have the time nor energy to properly explore that.

I ended up with Flash, using an old copy of Swish that came as a magazine freebie. (I have an old copy of Flash sitting around somewhere, but I never took the time to properly learn it). I’d previously used Swish for the toxiccustard.com 404 page and “Wanky Flash intro”, and while it isn’t as flexible as fully-fledged Flash, it’s not bad for simple stuff, and very easy to learn.

Swish was formerly installed on one of my old computers, and though the version I used (1.5.2) is discontinued, to my surprise I was able to re-download it from the Swish website and resurrect my old freebie licence via their web site. Full points to Swish for that.

All the frames were resampled in Photopaint to 400×300, and saved with some heavy JPEG compression to keep the filesize down to 15kb or so per frame. Plenty of artefacts, but who cares when each would be displayed for less than a second. I did use less compression on the first and last frames, which are displayed for longer. Again, properly using the newest Flash movie-playback features would probably have made possible much better compression, but no time Bellamy, no time!

Loaded a few of the pictures into Swish, and set them up to appear/hide every 4 frames (at 12 frames a second, so three pictures per second). I tried a few different options to get a speed I was happy with; fast enough that the whole thing isn’t too long and is interesting (I hope), and provides comic effect. But also slow enough that you can see some of the detail, such as hiding behind the polystyrene, and holding the beer bottle. The kids having a light-sabre fight with polystyrene didn’t quite work, as one of them was out of shot.

I noticed later that Swish lets you set the number of frames per second, making it dead easy to change the overall speed. Which would have avoided some fiddling. Oh well.

The final SWF Flash file came out at 450Kb or so, which shouldn’t be too slow to start up, even on dialup connections. Not that the speed of playback is critical anyway in this case.

I’m quite happy with the end effect, and people who saw it appeared to enjoy it too.

.NET security bites back

I was running a .NET app, and all it did was say:

Request for the permission of type System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
Request for the permission of type System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.

After I hit Ok, the app crashed with an exception. I didn’t write it. Others could run it, I couldn’t. What was I doing wrong?

I was running the exe from a network share. Copying the exe to local fixed the problem.

NVU

I’ve been playing around with the NVU web page editor, an open source application available for Windows, Mac and Linux. So far it’s good stuff, certainly rivalling Frontpage, and heaps better for new users looking for something cheap or free other than MS Word (which has well-known problems).

Now up to version 1.0, it probably isn’t on a par with Dreamweaver, but for basic WYSIWYG web page editing, definitely worth a look.

Hiding Excel warnings during automation

Well, I sorted out my problem of confusing warnings appearing whilst controlling Excel with VBA. Turns out there is an Application.DisplayAlerts property which, when set to false, hides warnings such as the one I was getting. It took a little Googling to find the solution, which wasn’t readily apparently in any of the MS help for the methods I’d got the warnings from.

The other Office applications also have a DisplayAlerts property.

Needless Excel automation warnings

Okay, this is annoying. I’m working on a VB program that uses the Excel object library to automate a fairly complex update into Excel. The general idea when you’re automating Excel is to smoothly do your operation behind-the-scenes, to hide the complexity from the user.

Excel warning

So the last thing you need is complicated dialog boxes popping up to ask the user questions. I’m the programmer: I’m meant to make the decisions. Tell me, the programmer, that if I save this Shared Workbook with a password that certain parts of the file won’t be encrypted. Don’t tell my user, and ask them to decide if it should happen or not.

Office’s garbled HTML

Brian Jones on why Microsoft Office 2000 (and later) produces such godawful HTML:

Our scenario was that people would start saving “docs” as HTML on their intranet sites and browse them with the browser. We viewed the browser as “electronic paper” that we had to “print” to (i.e. perfect fidelity). We had already got a lot of feedback from our Word97 Internet Assistant add-in that any loss of fidelity when saving as a web page was unacceptable and a “bug”. As it turned out, this usage scenario did not become as common as we thought it would and a zillion conspiracy theories formed about why we “really” did it. Many people assumed that a better approach would have been to save as “clean” HTML even if the result did not look exactly like what the user saw on the screen. We felt that the core office applications (other than FrontPage) were not really meant to be web page authoring tools, so we focused on converting docs to exact replicas in HTML. We didn’t want people losing any functionality when saving to HTML so we had to figure out a way to store everything that could have existed in a binary document as HTML. We thought we were clever creating a bunch of “mso-” css properties that allowed us to roundtrip everything. HTML didn’t take off in the same way we had expected, and today, the main use for Office HTML is for interoperability on the clipboard, though of course the biggest use is within e-mail (WordMail).

None of this explains why Office 2003’s “Filtered HTML” is so riddled with proprietary tags, though. Admittedly, a filtered HTML file is smaller than a roundtrip HTML file out of Word, but it’s still hugely bigger than the type of HTML you’d write from scratch (or in a web page editor such as Dreamweaver or Frontpage), and the source code is unreadable.

To my mind, Filtered HTML should be just that: HTML, filtered in such a way that the basic structure of the document is preserved, but none of the junk that Word (or whatever) stores along with it. Leave that for the roundtrip HTML — though I can’t see the appeal in that either, since if you want to store documents in a viewable form on the great InterWeb, PDF is the way to go. Or just store it in the native Office format for internal use, when you know every user will have the application or a viewer.

Word warning(By the way, when I was trying out the roundtrip HTML the other day, while reloading, Word presented me with a strange warning that it was going to query from some nonsense “Z” table to put data in the document. Bizarro. The test document did quote some SQL, but this would seem to suggest the roundtrip HTML isn’t all it’s cracked up to be.)

Anyway, Brian’s full article is about the progression of the Office formats from binary in the 90s into the XML to be used in the next version. Well worth a read if you want some background on the history, and where they’re going now.

Backslashes/Web dev toolbars

If you mistakenly put backslashes in your relative hyperlinks, IE silently replaces them with forward slashes. Does IE do this on Macs I wonder? It seems a very DOS-centric way of doing things. This is not “embrace and extend”. This is “be nice to sloppy people, breaking it for everybody else”. Firefox doesn’t like backslashes, correctly replacing them with %5C and then choking.

Meanwhile, MS has released a developer’s toolbar for IE (beta). I don’t normally use IE, but I had a quick look. WTF — it requires a complete system reboot to take effect. It looks like it has some handy features, but boy, it’s a bit buggy… try and view table outlines, and it takes ages if there’s more than a handful. Not so good.

Frankly, the Firefox web developer extension craps all over it.

Sneaky popups at Fairfax

The Age and SMH web sites have seen the writing on the wall for popup adverts, with browser popup blockers now blocking most ads that don’t occur as a result of direct user action.

So you know what they’ve done? Triggered a popup if you happen to click on part of an article window which normally wouldn’t be considered clickable, such as on a non-hyperlinked word. It’s a user action, so the popup gets around the blocker. It only seems to be triggered to happen occasionally though, so you don’t notice how the popup is triggered. Sneaky.