Link to home
Start Free TrialLog in
Avatar of vmandem
vmandem

asked on

How to pass a null value which is of data type double

I declared like this:

Dim x as double

When i don't have a record in a table
i want to pass nothing like null value.

It is by default taking zero, but i want to pass
Null value like : ""

It gives me  typemismatch error if i put.

x = ""

VM
Avatar of jjmartin
jjmartin

double is a numeric data type.

"" is a zero length string, which is why you get the type mismatch error.

try passing a numeric value such as zero.
ASKER CERTIFIED SOLUTION
Avatar of mdougan
mdougan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vmandem

ASKER

jjmartin

I'm doing some division like if i get a number
from a table like: 1230

I'm dividing by 1000 like: x = 1230/1000 = 1.230

so that is why i declared x as double.

What other data type i can use were i can pass
null values and get value with decimals when i divide by 1000.

Thanks
VM
Ordinarily I would never recommend doing this but...
if you change the data type from Double to Variant then you can place either value in it as it will "become" whatever it needs to be.  Still, Variants need to be steered away from, not only do they carry a lot of overhead but there is no such thing in .net...
Whoah!! I posted before I read your last comment...  Variant won't even do that... I don't think anything will.
Try checking for Null before you do any computation.  If the variable is null, then take the appropriate action...

If IsNull(MyVar) = True then
   'Do appropriate action for a null value
else
   'Do normal function.
end if
Avatar of vmandem

ASKER

Thanks very much for you answer.
VM