Solved

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

Posted on 2002-03-12
7
189 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now