Solved

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

Posted on 2002-03-12
7
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

710 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