|
VB AnnoyancesI use Visual Basic 6 and VBA at work all the time. Although I couldn't really say I hate the language, there are times when it catches you out for reasons that make little sense.
"Huston, we have null problems" Null values are one of the biggest headaches in the entire VB world. None of the basic data types can store a null (except Variant, which takes virtually anything so has no type safety and suffers from poor performance), so if you're reading from a database or accessing control values, you have to check every value. For instance: lOrderID = rst("fldOrderID")
will generate an error if fldOrderID is null -- you need to test it first: If Not IsNull(rst("fldOrderID")) Then
In Access you can use the null-to-zero function, which simplifies things a lot: lOrderID = Nz(rst("fldOrderID"))
And a little-known fact is that the Format function will convert nulls to zero-length strings: strOrderID = Format(rst("fldOrderID"))
although it will truncate strings longer than 255 chars -- remember that when you're reading memo fields from Access. Perhaps the most irritating of all features of nulls is that if you evaluate a true/false expression containing a null, the answer will always be false. If Me.cboOrderID.Value <> lngOrderID Then ' If Me.cboOrderID.Value is null, the
condition is ALWAYS false,
Me.cboOrderID.Value = lngOrderID
That issue has caught me up more times than I care to mention.
|