?
Solved

How to check for NULL Values

Posted on 2005-03-01
7
Medium Priority
?
5,453 Views
Last Modified: 2012-06-22
What is the best way to check for bull values. I dont want to covert to string if data is null is there a function i can use


cboOriginalCurrency.Value = CType(dtPaymentHeader.Rows(0)(prsgpaymentheader.Columns.vchOriginalCurrency), String)
0
Comment
Question by:anwarmir
7 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13429779
isdbnull(object) ? what do you want to do if the value is dbnull
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13429815
or like

cboOriginalCurrency.Value = iff(isdbnull(dtPaymentHeader.Rows(0)(prsgpaymentheader.Columns.vchOriginalCurrency), "nullvalue",CType(dtPaymentHeader.Rows(0)(prsgpaymentheader.Columns.vchOriginalCurrency), String))

0
 

Author Comment

by:anwarmir
ID: 13430506
id the object is null or empty string then i dont want to do anything....Our standards wont let us use backward compatible functions like IIF
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13430527
then just do

if not isdbnull(dtPaymentHeader.Rows(0)(prsgpaymentheader.Columns.vchOriginalCurrency)) then
   cboOriginalCurrency.Value = CType(dtPaymentHeader.Rows(0)(prsgpaymentheader.Columns.vchOriginalCurrency), String)
end if
0
 

Author Comment

by:anwarmir
ID: 13430899
i'm getting isDbNull not declared d o i have to declare it with imports or something?
0
 
LVL 28

Accepted Solution

by:
iboutchkine earned 1000 total points
ID: 13431437
fro example you want to check if X is null

if x Is Sytem.DBNull.VAlue then...
0
 

Expert Comment

by:rbirnesser
ID: 13472522
i had this same problem this is a function that if the value is null replace it with a certain value based on its data type

Public Function cNull(ByVal objData As Object, ByVal objType As String) As Object
        If IsDBNull(objData) Then
            Select Case objType
                Case "Boolean"
                    Return False
                Case "DateTime"
                    Return DateTime.MinValue
                Case "Decimal", "Double", "Integer", "Long", "Short", "Single"
                    Return 0
                Case "String"
                    Return String.Empty
            End Select
        Else
            Return objData
        End If
    End Function

to use the function correctly here is an example

Dim myWidth As Integer= cNull(myDvRow("bldg_width"), "Integer")
Dim myDoor As Double = cNull(myDvRow("door_height"), "Double")
Dim myActive As Boolean = cNull(myDvRow("active_flag"), "Boolean")

etc... i hope this helps also if u put that function in a module u can use it on any form in ur project
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…

601 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