Board index » delphi » Empty field not reported as NULL

Empty field not reported as NULL

Hi.

I've just finished work on a program for a client that works very well
except for one thing:

Every Monday, they need to generate a fixed-width text file of all data
entered for the previous week. The routine that creates this file is
pretty straightforward. The problem is that when I come across an empty
field, it does not get interpreted as NULL.

In the code fragment below, CREDITACCT is actually empty, but the
VarIsNull function fails.

        If VarIsNull(Query['CREDITACCT']) then begin
            ulfCreditAcct := Space(8);
            ulfCreditAmt := Space(10);
            ulfCreditCont := Space(10);
        end else begin
            ulfCreditAcct := Query['CREDITACCT'];             <== ERROR
            TmpFloat := Query['CREDITAMT'] * -1;
            ulfCreditAmt := Format('%10.2f', [TmpFloat]);
            TmpInt := Query['CREDITCONT'];
            ulfCreditCont := Format('%10.10d', [TmpInt]);
        end;

Of course, and here's the groaner, this works fine on my machine but
fails on the client's machine.

Any help would be appreciated. Thanks.

Elie Tordjman
El...@UMS1.Lan.McGill.Ca

 

Re:Empty field not reported as NULL


Quote
>In the code fragment below, CREDITACCT is actually empty, but the
>VarIsNull function fails.

>        If VarIsNull(Query['CREDITACCT']) then begin
>            ulfCreditAcct := Space(8);
>            ulfCreditAmt := Space(10);
>            ulfCreditCont := Space(10);
>        end else begin
>            ulfCreditAcct := Query['CREDITACCT'];             <== ERROR
>            TmpFloat := Query['CREDITAMT'] * -1;
>            ulfCreditAmt := Format('%10.2f', [TmpFloat]);
>            TmpInt := Query['CREDITCONT'];
>            ulfCreditCont := Format('%10.10d', [TmpInt]);
>        end;

>Of course, and here's the groaner, this works fine on my machine but
>fails on the client's machine.

>Any help would be appreciated. Thanks.

Does the VarIsNull function look at a string?  If so also check for ''.  I've
found that to work better at times then NULL.  Don't ask me why...

HTH

********************************
Michael Glatz              
glatzfa...@aol.com
mgl...@briefcase.com
There are very few personal problems that cannot be solved through a suitable
application of high explosives.

Re:Empty field not reported as NULL


In article <36F2B90B.276CB...@po-box.mcgill.ca>, Elie Tordjman
<eto...@po-box.mcgill.ca> writes

<snip>

Quote
>Every Monday, they need to generate a fixed-width text file of all data
>entered for the previous week. The routine that creates this file is
>pretty straightforward. The problem is that when I come across an empty
>field, it does not get interpreted as NULL.

<snip>

This may, or may not be the answer! Even my observations may be wrong!!
But it's something to look in to.

When I was using MS-Access (retch) the other day, I noticed a similar
sort of problem. I came to the conclusion that if a new record was
created with no field default value, then it was NULL. If the user added
data to that field, and then deleted the data, it was an empty string
''. Could this be happening in your case?
--
Chris Randle (ch...@amlog.demon.co.uk)

Re:Empty field not reported as NULL


My understanding is that a field not yet created is NULL, but an empty
field may or may not be NULL dependent upon the datatype. Empty is a
valid entry for some field types - for example strings. NULL in this
case would be misleading - it is just empty.

Quote
Elie Tordjman <eto...@po-box.mcgill.ca> wrote:
>Hi.

>I've just finished work on a program for a client that works very well
>except for one thing:

>Every Monday, they need to generate a fixed-width text file of all data
>entered for the previous week. The routine that creates this file is
>pretty straightforward. The problem is that when I come across an empty
>field, it does not get interpreted as NULL.

>In the code fragment below, CREDITACCT is actually empty, but the
>VarIsNull function fails.

>        If VarIsNull(Query['CREDITACCT']) then begin
>            ulfCreditAcct := Space(8);
>            ulfCreditAmt := Space(10);
>            ulfCreditCont := Space(10);
>        end else begin
>            ulfCreditAcct := Query['CREDITACCT'];             <== ERROR
>            TmpFloat := Query['CREDITAMT'] * -1;
>            ulfCreditAmt := Format('%10.2f', [TmpFloat]);
>            TmpInt := Query['CREDITCONT'];
>            ulfCreditCont := Format('%10.10d', [TmpInt]);
>        end;

>Of course, and here's the groaner, this works fine on my machine but
>fails on the client's machine.

>Any help would be appreciated. Thanks.

>Elie Tordjman
>El...@UMS1.Lan.McGill.Ca

+---------------------------------------------+
+ Be sure that you go to the author to get at +
+ his meaning, not to find yours -John Ruskin +
+                                             +
+ Views expressed are my own.                 +
+                                             +
+ AndyC      a...@telecam.nospam.demon.co.uk  +
+---------------------------------------------+

Other Threads