Spam and If

Just saw this BBC story about the possibility of spam being canned in two years. Yeah right. Tttthhhhhppppthp.

OK, no more ranting and general obstreperousness. Time to get to some code. Whether it's bad practice to end up in this kind of scenario is a debate for another day, but I came up with a function today that was extremely useful. I had some legacy code with reams of If foo=blah then bar=woo… nonsense in it. Each If statement was taking up around 4 - 5 lines (plenty of Elses too…), and I got bored with it all. It looked plain nasty. This looks much better to my mind:

strTmp = doIF(Isempty(doc.Field) ,"Gah!", doc.Field(0))

The function is very simple, and like I say, is purely for brevity and ease of reading:

Function doIF(intEval As Integer, strThen As String,_
strElse As String) As String
   If intEval Then
      doIF = strThen
      doIF = strElse
   End If
End Function


  1. yeah, spam is going away. That's why I found this old posting of mine from 1990 discussing spam we were dealing with on our VAX VMS systems…
    LinkEd Brill#
  2. Still whizzing through the Google groups then Ed?
    Those things can take years away. Ah, my wee posts from 1995 when I was [email protected]… and I posted from a Mac Classic with a 28.8 modem (yes! 28.8!!)Ben Poole#
  3. "Gah!"

    lol, that is my new fave exclamation, right up there with "works a treat!"jonvon#
  4. "Gah" is a crucial assert in the Poole programming world.Ben Poole#

Comments on this post are now closed.


I’m a software architect / developer / general IT wrangler specialising in web, mobile web and middleware using things like node.js, Java, C#, PHP, HTML5 and more.

Best described as a simpleton, but kindly. You can read more here.