Solved

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

Posted on 2002-03-12
7
191 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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