GetErrorCode for wcCode 5

This code is released to the public domain. Do with it what you will. There
are no promises or guarantees related to this code. Specifically, there is no
suitability to purpose guarantee.


WHAT IS IT?
So what is it? Typically, you have error handling in your wcCode application
something like this:

  dim err as integer = GetLastError

Followed at some point with something like this:

  TemplateSetVariable("error", hex(err))

These code snippets were, in fact, taken from MSI's HTML-CREATE MESSAGE.WCC
file. The problem is, if you use this code then your user gets a rather
cryptic error message, like this:

  There was an error posting your message (error code 2000001d).

Now what on earth is error code 2000001d? Do YOU know? Is your user going to
know (and are they going to be able to report it to you accurately)? As it
turns out, that error code is DUPLICATE RECORD -- which actually tells you a
bit more. Your user was trying to send a message. They get a DUPLICATE RECORD
error. So what does that mean? They were trying to send an exact copy of a
message they've already sent -- something WINS does not allow! See the
difference an error code can make?

So how would you like your programs to return legitimate error codes when
there's a problem -- error codes that you can DO something with? You can,
assuming you're a wcCode author, and it's never been simpler.


HOW TO MAKE IT WORK
First, copy the GetErrorCode.wcc into your source directory (where you've got
all your wcCode source). Then, get your error just as before (you know, using
that "dim err" line from above). But instead of just converting that number to
Hex, convert it to a valid code using this command:

  dim errstring as string = GetErrorCode(err)

Now you have a text string (in the variable ERRSTRING) that you can use to
display what went wrong. It's still in "Programmer-eze" rather than in
English, but at least you've got an error that somebody can make some sense
out of without having to hunt up a reference book.

Alternately, you can insert it into a template, by modifying the string you
see in MSI's example above, so it looks like this:

  TemplateSetVariable("error", GetErrorCode(err))

One last thing -- in order to make this work properly, you can either copy the
function from the GetErrorCode.wcc and paste it into your project, *OR* just
add the following line to the beginning of your .wcc file:

  #include "GetErrorCode.wcc"

There you go...that's it. You can see the source yourself, to see what's going
on. The codes were provided by Bob Jones in an email dated 1/22/97 (it just
took me this long to think "Hey...I could do something USEFUL with those!").