Solved

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

Posted on 2002-03-12
7
193 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:vmandem
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 3

Expert Comment

by:jjmartin
ID: 6858093
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.
0
 
LVL 18

Accepted Solution

by:
mdougan earned 5 total points
ID: 6858123
If you simply put the word NULL in the SQL when you are updating the database it will work for you:

Dim sSQL as String

sSQL = "Update MyTable Set "
sSQL = sSQL & "Quantity = " & txtQty.text & ", "

if chkDiscount.Value = vbChecked then
   sSQL = sSQL & "Discount = " & txtDiscount.text & " "
Else
   sSQL = sSQL & "Discount = NULL "
End If

sSQL = sSQL & "WHERE RECID = " & gRecID

' sSQL could have:
' Update MyTable Set Quantity = 100, Discount = NULL WHERE RECID = 197
' Update MyTable Set Quantity = 100, Discount = .50 WHERE RECID = 197

oCMD.Execute sSQL
0
 

Author Comment

by:vmandem
ID: 6858128
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:trkcorp
ID: 6858129
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...
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6858155
Whoah!! I posted before I read your last comment...  Variant won't even do that... I don't think anything will.
0
 
LVL 3

Expert Comment

by:jjmartin
ID: 6858170
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
0
 

Author Comment

by:vmandem
ID: 6861144
Thanks very much for you answer.
VM
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question