Wrox Programmer Forums Is there a NaN in VBA?
 | Search | Today's Posts | Mark Forums Read
 Access VBA Discuss using VBA for Access programming.
 Welcome to the p2p.wrox.com Forums. You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com

February 15th, 2008, 07:40 AM
 Registered User Join Date: Feb 2008 Location: London, , United Kingdom. Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts

In fact, there is a way to use the Excel formula #N/A value in VBA.

You can achieve this by using the Variant type and the following function:

Function NaN() As Variant
NaN = CVErr(xlErrNA)
End Function

For more information, and also to find out how to check for these #N/A values, please refer to:

http://www.bilokon.co.uk/finance/ind..._values_in_VBA

Hope this helps.

Regards,
Paul

March 6th, 2016, 08:40 AM
Registered User
 Points: 3, Level: 1
 Activity: 0%

Join Date: Mar 2016
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Yes you can!

Here is code to create all special value types for a double

Code:
```Option Explicit

Public Declare Sub CopyMemory Lib "kernel32" Alias _
"RtlMoveMemory" (destination As Any, source As Any, _
ByVal length As Long)

Public Function PosQNaN() As Double
'returns positive qnan
Dim Oput As Double
Dim l(1 To 2) As Long
l(1) = 0
l(2) = &H7FF80000
CopyMemory Oput, l(1), 8
PosQNaN = Oput
End Function

Public Function NegQNaN() As Double
'returns negative qnan
Dim Oput As Double
Dim l(1 To 2) As Long
l(1) = 1
l(2) = &HFFF80000
CopyMemory Oput, l(1), 8
NegQNaN = Oput
End Function

Public Function Indeterminate() As Double
'returns an indeterminate
Dim Oput As Double
Dim l(1 To 2) As Long
l(1) = 0
l(2) = &HFFF80000
CopyMemory Oput, l(1), 8
Indeterminate = Oput
End Function

Public Function PosInfinity() As Double
'returns a positive infinity
Dim Oput As Double
Dim l(1 To 2) As Long
l(1) = 0
l(2) = &H7FF00000
CopyMemory Oput, l(1), 8
PosInfinity = Oput
End Function

Public Function NegInfinity() As Double
'returns a negative infinity
Dim Oput As Double
Dim l(1 To 2) As Long
l(1) = 0
l(2) = &HFFF00000
CopyMemory Oput, l(1), 8
NegInfinity = Oput
End Function```

Last edited by Nickledeg; March 6th, 2016 at 08:43 AM..

 Similar Threads Thread Thread Starter Forum Replies Last Post NaN elayaraja.s XSLT 2 September 9th, 2008 04:10 AM NaN spinout ASP.NET 2.0 Basics 4 August 5th, 2007 06:07 AM Formatting NaN in a matrix gidsy BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 May 8th, 2007 10:50 AM Actionscript NaN brainchild Flash (all versions) 1 March 21st, 2007 07:29 AM format-number NaN rbdave XSLT 1 October 23rd, 2003 06:48 AM