Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2002-03-12
7
Medium Priority
?
198 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 20 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

926 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