Assign a value if null

In VB6 the way to assign a value to null was nz(value,value if null). What is the equivalent in xojo?

I don’t know VB6. Are you looking for:

if nz is nil then nz = value

This will also work in the latest Xojo:

nz = if( nz is nil, value, nz )

Here is my code. I have queryed the database to count how many records exist with the id given. Then I want to assign this number to intPrecheck

intPrecheck = if(rs.Field("qty").Value is nil,rs.Field("qty").Value,0)

This is what I have written from your suggestion.

it gives me the same error.

What is the error?

Note that if the field exists in the database, rs.Field(“qty”).Value will be non-nil. If you want to test for a null value, use

if rs.Field("qty").Value.IsNull

That didn’t work for me but the following did.

if rs.FieldCount < 1 then

I found that their was no fieldcount returned from the query.

That would indicate a deeper problem. You likely got an error from the query. Check the .Error and .ErrorMessage properties of your database object.

Could you move the NULL check into your database query so the data comes out in the format you want before Xojo gets it’s hands on it? As in this MSSQL query…

FROM [table]
WHERE [ID] = 99999999999

(Unless I’m misunderstanding the issue)