tags:

views:

55

answers:

4
+2  Q: 

VB6 null boolean

I'm working on an application in vb6 that draws information from a database. I've come across many problems that come from null values in the database as vb6 functions and subroutines don't like nulls. The string problem is easily solved by concatenating an empty string to the value. But what do I do for a null value where a boolean should be?

Thanks for your help!

+1  A: 

Try using isnull and specifying the .value of the field, as otherwise the isnull() checks the field object (and not the value):

If (IsNull(l_BankAccount.Recordset.Fields("BANKCODE").value) = True) Or _

For more information see this post.

Justin Ethier
+2  A: 

This assumes you are using the ADO objects for data access.

Dim boolField As Boolean
If Not IsNull(fields("FieldName").value) Then
    boolField = CBool(fields("FieldName").value)
End If   
ChaosPandion
A: 
Dave
+1  A: 

I'm using most of these function to handle nulls

'--- type-casting without errors'
Public Function C2Str(Value As Variant) As String
    On Error Resume Next
    C2Str = CStr(Value)
    On Error GoTo 0
End Function

Public Function C2Lng(Value As Variant) As Long
    On Error Resume Next
    C2Lng = CLng(Value)
    On Error GoTo 0
End Function

Public Function C2Cur(Value As Variant) As Currency
    On Error Resume Next
    C2Cur = CCur(Value)
    On Error GoTo 0
End Function

Public Function C2Dbl(Value As Variant) As Double
    On Error Resume Next
    C2Dbl = CDbl(Value)
    On Error GoTo 0
End Function

Public Function C2Date(Value As Variant) As Date
    On Error Resume Next
    C2Date = CDate(Value)
    On Error GoTo 0
End Function

Public Function C2Bool(Value As Variant) As Boolean
    On Error Resume Next
    C2Bool = CBool(Value)
    On Error GoTo 0
End Function

You can use C2Bool in your case :-))

wqw