chama
chama

Reputation: 6163

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!

Upvotes: 2

Views: 3424

Answers (4)

Justin Ethier
Justin Ethier

Reputation: 134167

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 _

Upvotes: 0

wqw
wqw

Reputation: 11991

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 :-))

Upvotes: 2

Dave
Dave

Reputation: 1234

This is an old problem with VB6 and ASP. I use Trim(l_BankAccount.Recordset.Fields("BANKCODE").value & " ") which gets rid of many problems including the dbNull.
For a whole number field CLng("0" & Trim(l_BankAccount.Recordset.Fields("BANKCODE").value & " ")) works.

Upvotes: 0

ChaosPandion
ChaosPandion

Reputation: 78242

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   

Upvotes: 2

Related Questions