Misinformation on the Internet

Recently I’ve been writing code to produce a database of Alumni in the University’s Architecture Department where I work. Somewhat irritatingly the servers all run on IIS which required me to learn how to talk to SQL Server with ASP. The irritating part being that I’ve only just learnt how to talk to MySQL with PHP in order to make bits of this site work (like the diary).

During this process I’ve spent quite a while looking through the Microsoft documentation available on MSDN as well as searching the Internet. It’s laborious to search through documentation when so much is available just by firing up a search engine.

For my latest project at work I’ve had to rename photographs to match details in an Excel Spreadsheet. Since I already had Excel up-and-running, I decided to use Visual Basic for Applications to write a Macro to do the job. Although I’ve been programming in BASIC for years there’s lots of API calls to learn to make Excel do what you want it to.

In my youth I had never learnt the mysteries of escaping character strings. Now in many programming languages character strings are delimited using double quotes (“). Thus to store a string one could use a command like the following:

$poem = "Mary had a little lamb."

Now let’s see what happens if we store a more complicated string. I’m going to try: Mary had a little lamb, whose name was “Flossy.” Now let’s put that in the code:

$poem = "Mary had a little lamb, whose name was "Flossy.""

Now there’s a problem. The character string starts with the first set of quotes, and ends with the second set. So our string becomes “Mary had a little lamb, whose name was “, and the remaining characters cause an error.

So I fired up the Internet, and searched for “visual basic escape quotes.” I found several solutions along the following lines:

$poem = "Mary had a little lamb, whose name was " & Chr(34) & "Flossy." & Chr(34)

That is, instead of writing the quotes as part of the string, we join them in using their character code. A little guess work (and further searching) established the proper way of doing things:

$poem = "Mary had a little lamb, whose name was ""Flossy.""

I.e. you double each set of quotes.

I suppose the moral of the tale is not to trust everything you read on the Internet, but you knew that anyway. Perhaps it isn’t such a good substitute for buying decent programming books and downloading the proper specifications.

This entry was posted in Uncategorized. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Trackback

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>