More on Null Conversion

More on Null Conversion

This tip has been published more than once on pages of VBPJ(See “99 of the Hottest Tech Tips For VB Developers,”Supplement to the February 1996 issue of VBPJ, page 17).

This code is recommended to convert Null values in the numericdatabase fields to zeroes:

 Dim nVar As IntegernVar = 0 & rs!nField' assumed that nField ' is a numeric field in ' the recordset

The expression 0 & rs!nField actually returns a string,not a number. If, say, rs!nField contains 1, 0 &rs!nField results in “01.”

The code above works due to the automatic conversion of types.If, however, you need to assign the numeric value, not to a numericvariable, but to a grid cell or a text box, you do not get whatyou want, and additional data formatting is required.

You might consider three other ways to get rid of Nulls:

 ' This will work, and in VB4 you do ' not have to include MSAFINX.DLL ' with your project' (as you did in VB3). However, the ' expression might look a bit too long...nVar = IIf(IsNull(rs!nField), 0, _        rs!nField)

This will work, both in VB3 and VB4:

 nVar = Val("" & rs!nField)


 nVar = Val(0 & rs!nField)

I always use:

 "" & n  

instead of Str$(n) when I do not need (and I hardly ever needit!) the leading space produced by Str$() function.

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved