Friday, June 24, 2005

Why not start with a "How Stupid..."?

I have been working in both VFP and .NET lately, and recently had a "blonde" moment due to the fact that in VFP, everything is 1-based, whereas in .NET, everything is 0-based.

In VFP, if you want to search for a string within a string, VFP has a function called AT(), which returns the starting point of the string within the string. If the string cannot be found, AT() returns 0.

I wanted to create the .NET equivalent of the following VFP code:

   lcEmailMessageBody = "<html> ...."

   IF AT("<html",lcEmailMessageBody)>0 THEN
      SendHTMLMail(lcEmailMessageBody)
   ELSE
      SendTextMail(lcEmailMessageBody)
   ENDIF


So I create the following .NET equivalent:

   lcEmailMessageBody = "<html>....";

   if(lcEmailMessageBody.IndexOf("<html")>0)
      SendHTMLMail(lcEmailMessageBody);
   else
      SendTextMail(lcEmailMessageBody);


Pretty straightforward, n'est-ce pas?

AAANNNN - wrong! When I ran this code, it only sent text mail.

***HEADSLAP***

Since strings in .NET are 0-based, a return value of 0 from IndexOf() means that the string was found in the first character of the string (character position 0 in the string). A return value of-1 means that the string is not found. so the proper if-statement is:

   if(lcEmailMessageBody.IndexOf("<html")!=-1)

The funny part is that before I got slapped, I created another project to test it there, andthen asked a colleague if he got the same result on his computer. And as the words came out of my mouth, I realized the mistake, and braced myself for the slap.
Welcome to my blog!

My name is Rick Hodder and this is my blog.

A little about me. I'm a computer programmer by trade, but my interests/hobbies include:

Improv Comedy:
Both short form (a series of games like the show Whose Line Is It Anyway?) and long form (the audience is asked for words or phrases, after which a half hour show is created on the spot). I have taken classes and have been an ensemble performer at
Gotham City Improv in New York City. GCI was started by a group of "improv"ers from the famous LA improv group called "the Groundlings." I find improv a great way to "get out of my head" - its amazing where your mind can take you. I especially enjoy the fact that you don't prepare: no scripts, just what happens, and how you react to it. You create your own reality, and watch it change as other performers embellish. It's also great for thinking on your feet.

Community Theater:
I have been involved in theater since highschool. The latest theater that I have been involved with is the Ridgefield Theater Barn in Ridgefield, Connecticut. Being a consultant has taken me away from performing - community theater doesn't tend to have understudies, and consultants usually can't promise to be in town for the practices, let alone the performances. So what do actors do when they cant act anymore? That's right - they direct! Next year I hope to direct one of my favorite musical, Damn Yankees.

Music:
Music has been an important part of my life. I play the guitar, violin, and piano, but my favorite instrument is voice. I've always been a singer: my mom always encouraged it (like her I was in choirs). In college I toured the US and Europe with the Notre Dame Glee Club. I love playing guitar and singing at coffeehouses. I'm a huge fan of James Taylor.

Lately I have been taking a stab at writing music. I am using with Sonar 4 Producer, by Cakewalk Software.

Programming:
.NET
C#
ASP.NET
SQLServer
Visual Foxpro
Visual Basic 6
Turbo Pascal

I am currently a C# programmer.

Mentoring/Teaching:
I really enjoy working with people in a learning setting. Teaching is in my blood. My mom was a teacher and later a vice-principal. My dad is a doctor who has taught medical school and led a medical residency program. I have presented at meetings on programming topics, and sessions on Design Patterns at Microsoft Devcons. I have published articles in Foxpro Advisor and Foxtalk, and was the VFP Pro on Fawcette Publications devx.com website.

Design Patterns:
I'm a huge fan of Design Patterns. They have totally changed my approach to object-oriented development.

Tool Creation:
I love to create tools (particularly for developers). My current favorite tool is CodeSmith: it's a template-based generation product. It is amazing to say the least!! The latest version is killer!

So what can you expect from my blog? Tune in and see!

I like the many connotations of "Head-Slapping" moments in everyday life and programming: everything from the "How could I be so stupid!" to the "Eureka!" to the "Rattling my head around (banging head against wall)" to get a new idea out. I plan to share these types of moments and what I learned from them (with code samples!).

Knee-slapping will be the humor that I will try to interject into what I present here.

Join me, won't you?