Warnings GaloreMy dearest VB.NET programmers (and C# programmers up to a point), I once again have to inform you of one of my pet peeves. This is pretty much a follow-up to one of my previous posts, but more than two years after, I still work in projects from various online sources as well as professionally that are littered with the warnings about undefined variables:

warning BC42104: Variable 'X' is used before it has been assigned a value. A null reference exception could result at runtime.

At runtime, these warnings usually translate into the dreaded NullReferenceException:
NullReferenceException was unhandled, Object Reference not set to an instance of an object.

So, what causes this and how can can we fix this? Let’s take a look at a piece of code that demonstrates something incredibly common, especially in VB circles:

Dim MyString As String

If ThisAndThat Then
    MyString = "Some Value"
End If

...

SomeFunction(MyString)

If the boolean ThisAndThat evaluates to False, MyString will never be defined, and a NullReferenceException will arise when the SomeFunction function tries to do anything with MyString. Remember that The System.String class does not have a default constructor, so no constructor is implicitly called. MyString is NOT String.Empty, but NULL.

To fix this, all you need is an Else statement in your code and some default value that you’d like to assign to MyString:

Dim MyString As String

If ThisAndThat Then
    MyString = "Some Value"
Else
    MyString = String.Empty
End If

...

SomeFunction(MyString)

in fact, the best way to handle default values is to define the variable upon declaration:

Dim MyString As String = String.Empty

If ThisAndThat Then
    MyString = "Some Value"
End If

...

SomeFunction(MyString)

Or you could even eliminate the If statement entirely by using the IIf function:

Dim MyString As String = IIf(ThisAndThat, "Some Value", String.Empty).ToString()

...

SomeFunction(MyString)

And even though I’m using the class System.String as an example, this should be applicable to any variable of any data type. It’s a good practice and will eliminate many of those pesky runtime errors that can be difficult to trace.

Don’t use Turbo C, that’d be great yeah..

Turbo C++I don’t know how many times I’ve ran into people that need help with a piece of C code that should run perfectly fine but for some reason it just doesn’t. Of course, after much going back and forward, you find out that the person you’re trying to help is using Borland’s Turbo C compiler version 2.01, released 20 years ago in 1989..

While the compiler is freely download-able from several websites labeled as an “Antique”, it’s really not a great tool to start programming with on modern systems. If you really (really) want to use Turbo C, buy an old 286 and go at it but don’t use your Intel Core i7. Here’s why. PS, this also applies to Turbo C++

1. The compiler is 20 years old, it won’t support the current C99 standard so many things you might have learned, you now have to unlearn in order to get the program working.

2. Turbo C is an MS-DOS compiler, chances are if you are learning C now, you have never used DOS in your life; there’s no reason to go back, nostalgia doesn’t apply to DOS. Furthermore, Windows does not support DOS programs from the 80′s, so you would have to emulate DOS in order to get your programs working properly.

3. There are many free compilers available that are 100% compatible with today’s hardware and not bound by any limitations. Even if your Turbo C compiler is 32 bit compatible, it’s not a great match for your 64 bit CPU and Operating System.

4. You’re stuck on the command line interface with no way out. Even if you make the best command line program for DOS, nobody besides yourself will ever want to use it. Converting your program to Win32 requires a new compiler that will yell at you for using coding practices from 1989 and break your program.

In other words, if the following code compiles without warning, you know you need another compiler.

#include <stdio.h>

main()
{
    printf("Hello, World!");
}

Annual Minutes Requirement Scam

Here’s a little tip for US business owners. If you get a document in the mail called: “Annual Minutes Requirement Statement Directors and Shareholders”, do not pay it, this is a scam. The Florida Department of State has now posted a warning about this on its front-page as well:

While this document might look very authentic, in the small print it states:

This product has not been approved or endorsed by any government agency and this offer is not being made by an agency of the government.

Needless to say, you should never send shareholder information to any non-government organization, and your actual annual meeting information should only be addressed to a government organization or posted at SunBiz.org.

The letter that I originally received had the following return address:

COMPLIANCE SERVICES
400 Capital Cir SE, Ste 18321
Tallahassee, FL 32301

Edit 1:
Thanks to all of the people who have posted a comment, here’s a list of all the street address instances used by this scammer so far, there were more instances reported below in the comment section without addresses. Also, if you happen to have more information or an address that’s not listed, please post it below, it will most certainly help many people.

  • California (1)
    P.O. Box 1265,
    Studio City, CA 91614-0265
  • California (2) as Corporate Compliance Center
    2740 Fulton Ave,
    Sacramento CA 95821-5183
  • Florida
    400 Capital Cir SE, Ste 18321,
    (Postal Mail Box 18321 as of 2011/02/17),
    Tallahassee, FL 32301
  • Georgia (1)
    931 Monroe Drive NE, STE A-102 #333,
    Atlanta, GA 30308-1795
  • Georgia (2)
    Annual Minutes Disclosure Services/Business Processing Division,
    5805 State Bridge Road,
    Duluth GA 30094,
    Phone 866-390-1176
  • Georgia (3)
    Annual Minutes Disclosure Services,
    5805 State Bridge Road Ste. G–380,
    Duluth, GA 30097
  • Massachusetts
    Compliance Services,
    71 Commercial St. #241,
    Boston, MA 02109
  • New York
    Annual Minutes Disclosure Services / Business Processing Division
    911 Central Avenue #134,
    Albany, NY 12206
  • North Carolina (1)
    324 S. Wilmington St.,
    Postal Mail Box 407,
    Raleigh, NC 27601
  • North Carolina (2)
    2820 Selwyn Ave,
    Postal Mail Box 847,
    Charlotte, NC 28209

Edit 2:
I can’t believe that after more than a year, I’m still receiving comments on this post from people that received the letter. If you got the letter and it has a different address than listed above is on the envelope, post a comment and let us know, since you might be saving someone $125!

Edit 3:
It’s been almost two years now, and sadly, this scam is still going strong. In fact, a new address in Sacramento California has popped up that I’ve added to the list above. Keep those comments going and help your fellow business owner save an unnecessary $125, especially if you have a new address to report.

Edit 4:
The scammers now have put up a very simple web page at http://www.corpsrvc.com/. If you didn’t have doubts about Compliance Services before, take a look at their site.

Edit 5
Good news for those of you in North Carolina. Earlier this month, a court settlement was reached between North Carolina State and Corporate Services Inc. This means that if you live in NC, you will no longer be receiving the scam in your mailbox. Sadly, Corporate Services, Inc. is still able to operate in any other state, so while this victory is minor, it’s still a victory.

An email arrived in my inbox today from a reader who want me to make you aware of Mr. Selwyn J. Monarch, a disbarred attorney from California who is also the owner of Corporate Services, Inc. If you do a quick Google search, you’ll see that this is one untrustworthy person with quite a bit of legal baggage!

Edit 6
Contrary to the previous update, readers are still reporting receiving the scam letter in North Carolina.

Phoenix dead

Maybe Phoenix will live up to its name and start functioning again soon, until then:

Phoenix: RIP

I don’t like Visual Basic, yet in many Microsoft shops, VB is still being used especially in combination with ASP.NET. The problem with Visual Basic is that it’s not very strongly typed. Conventions are often thrown out of the window and Senior VB developers often hold their seniority as experience which, is more fiction than fact.

How many more times do I have to see Functions which don’t return anything and should have been declared as Subs.

Or: Variable 'XYZ' is used before it has been assigned a value.
Or: Variable declaration without an 'As' clause; type of Object assumed.

Visual Basic ErrorsUgh. You’d think that people with 15 years of development experience wouldn’t dismiss this kind of stuff and just do the right thing.