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:
Share on facebook
Share on twitter
Share on linkedin


The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may