Solved

VB.NET IsNull?

Posted on 2003-12-01
2
6,476 Views
Last Modified: 2008-05-30
in vb6 there was IsNull()... is there a replacement in vb.net?

   - Marc
0
Comment
Question by:MarcGraff
2 Comments
 
LVL 39

Accepted Solution

by:
appari earned 500 total points
Comment Utility
there is no direct function as in VB 6.

but there are few otherways of checking for null. like check whether the variable is nothing or using dbNull. here is an example which i use in my .net projects, code is from http://www.freevbcode.com/ShowCode.Asp?ID=5810

    Enum enumObjectType
        StrType = 0
        IntType = 1
        DblType = 2
    End Enum

Public Function CheckDBNull(ByVal obj As Object, _
    Optional ByVal ObjectType As enumObjectType = enumObjectType.StrType) As Object
        Dim objReturn As Object
        objReturn = obj
        If ObjectType = enumObjectType.StrType And IsDBNull(obj) Then
            objReturn = ""
        ElseIf ObjectType = enumObjectType.IntType And IsDBNull(obj) Then
            objReturn = 0
        ElseIf ObjectType = enumObjectType.DblType And IsDBNull(obj) Then
            objReturn = 0.0
        End If
        Return objReturn
 End Function

you can change above function to suit your needs.
0
 
LVL 1

Author Comment

by:MarcGraff
Comment Utility
Wow! Works great! Thanks!

   - Marc
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now