Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Data Types and inaccuracies with Trig functions in VBA

I am developing an application to calculate navigation data from Sun & Star
sights (interesting for sailors, boring for everyone else).

The problem is that I appear to be getting small inaccuracies when
calculating angles. I have used Double as the data type. Looking through
the help files I note that there should be a 'Decimal' data type that uses
many more digits so potentially improving accuracy. However, a line such
as:

Dim dLat as Decimal

results in a message: 'Compile error: Expected: New or type name'

I understand that this is saying it doesn't recognise the Decimal data type.
Do I have to add a library to use this? if so which one?

Any ideas gratefully received.

Peter Morris


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Data Types and inaccuracies with Trig functions in VBA

Peter,

From a Myrna Larson post:
'-----------------------------------
The decimal data type is a subtype of a variant. You must Dim the variable as a
variant, then put the data into it with the CDec function. Since Decimals can
have up to 28 significant figures, and doubles are limited to 15 or 16, how do
you assign a literal value to one? From a string representation of the number,
i.e.
Dim Dec As Variant
Dec = CDec("1234567890123456789012345678")
Debug.Print Dec, TypeName(Dec)
'------------------------------------
From a Chip Pearson post:
To display these values on a worksheet, you'll have to change them to
strings to prevent Excel from rounding them ...
Range("C2").Value = " ' " & CStr(Dec)
'-----------------------------------

Regards,
Jim Cone
San Francisco, CA

"Peter M" wrote in message
...
I am developing an application to calculate navigation data from Sun & Star
sights (interesting for sailors, boring for everyone else).
The problem is that I appear to be getting small inaccuracies when
calculating angles. I have used Double as the data type. Looking through
the help files I note that there should be a 'Decimal' data type that uses
many more digits so potentially improving accuracy. However, a line such
as:
Dim dLat as Decimal
results in a message: 'Compile error: Expected: New or type name'
I understand that this is saying it doesn't recognise the Decimal data type.
Do I have to add a library to use this? if so which one?
Any ideas gratefully received.
Peter Morris




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Data Types and inaccuracies with Trig functions in VBA

Jim,

Does this mean that I could get greater accuracy simply by declaring
variables as Variant rather than Double?

ie use: Dim x, y, z
rather than Dim x as double, y as double, z as double.

Peter Morris

"Jim Cone" wrote in message
...
Peter,

From a Myrna Larson post:
'-----------------------------------
The decimal data type is a subtype of a variant. You must Dim the variable

as a
variant, then put the data into it with the CDec function. Since Decimals

can
have up to 28 significant figures, and doubles are limited to 15 or 16,

how do
you assign a literal value to one? From a string representation of the

number,
i.e.
Dim Dec As Variant
Dec = CDec("1234567890123456789012345678")
Debug.Print Dec, TypeName(Dec)
'------------------------------------
From a Chip Pearson post:
To display these values on a worksheet, you'll have to change them to
strings to prevent Excel from rounding them ...
Range("C2").Value = " ' " & CStr(Dec)
'-----------------------------------

Regards,
Jim Cone
San Francisco, CA

"Peter M" wrote in message
...
I am developing an application to calculate navigation data from Sun &

Star
sights (interesting for sailors, boring for everyone else).
The problem is that I appear to be getting small inaccuracies when
calculating angles. I have used Double as the data type. Looking

through
the help files I note that there should be a 'Decimal' data type that

uses
many more digits so potentially improving accuracy. However, a line

such
as:
Dim dLat as Decimal
results in a message: 'Compile error: Expected: New or type name'
I understand that this is saying it doesn't recognise the Decimal data

type.
Do I have to add a library to use this? if so which one?
Any ideas gratefully received.
Peter Morris






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Data Types and inaccuracies with Trig functions in VBA

No. And you really can't get more accuracy unless you write your own
functions. If you passed a Variant of type Decimal to a built in function,
it would be converted to double or whatever the function normally works in.

I know someone has written an addin that does basic math with numbers of
creater precision than double, but I don't recall the name of it or the
author. You could try a google search on Excel, Addin, Precision or
something like that. Anyway, as I recall, this person was adding standard
functions to the addin to do more complex math at higher pecision. Note
that Excel works at the IEEE standard for double precision which is about 15
digits.

Also, Chip Pearson has a page on working with Latitudes and Longitudes-
maybe this has some bearing on your problem.
http://www.cpearson.com/excel/latlong.htm

Anyway, just declaring a variable as Variant will not make it a decimal
value if you assign it a number. It will retain whatever precision it had.
You would have to assign it to the variant with the cdec conversion function

Dim vVariant as Variant
vVariant = cdec(123.456567)

--
Regards,
Tom Ogilvy

"Peter M" wrote in message
...
Jim,

Does this mean that I could get greater accuracy simply by declaring
variables as Variant rather than Double?

ie use: Dim x, y, z
rather than Dim x as double, y as double, z as double.

Peter Morris

"Jim Cone" wrote in message
...
Peter,

From a Myrna Larson post:
'-----------------------------------
The decimal data type is a subtype of a variant. You must Dim the

variable
as a
variant, then put the data into it with the CDec function. Since

Decimals
can
have up to 28 significant figures, and doubles are limited to 15 or 16,

how do
you assign a literal value to one? From a string representation of the

number,
i.e.
Dim Dec As Variant
Dec = CDec("1234567890123456789012345678")
Debug.Print Dec, TypeName(Dec)
'------------------------------------
From a Chip Pearson post:
To display these values on a worksheet, you'll have to change them to
strings to prevent Excel from rounding them ...
Range("C2").Value = " ' " & CStr(Dec)
'-----------------------------------

Regards,
Jim Cone
San Francisco, CA

"Peter M" wrote in message
...
I am developing an application to calculate navigation data from Sun &

Star
sights (interesting for sailors, boring for everyone else).
The problem is that I appear to be getting small inaccuracies when
calculating angles. I have used Double as the data type. Looking

through
the help files I note that there should be a 'Decimal' data type that

uses
many more digits so potentially improving accuracy. However, a line

such
as:
Dim dLat as Decimal
results in a message: 'Compile error: Expected: New or type name'
I understand that this is saying it doesn't recognise the Decimal data

type.
Do I have to add a library to use this? if so which one?
Any ideas gratefully received.
Peter Morris








  #5   Report Post  
Posted to microsoft.public.excel.programming
jaf jaf is offline
external usenet poster
 
Posts: 300
Default Data Types and inaccuracies with Trig functions in VBA

Hi Tom,
I think this is the site. http://precisioncalc.com/
I don't see any trig functions. May be able to code them the hard way.


--
John
johnf 202 at hotmail dot com


"Tom Ogilvy" wrote in message
...
| No. And you really can't get more accuracy unless you write your own
| functions. If you passed a Variant of type Decimal to a built in
function,
| it would be converted to double or whatever the function normally works
in.
|
| I know someone has written an addin that does basic math with numbers of
| creater precision than double, but I don't recall the name of it or the
| author. You could try a google search on Excel, Addin, Precision or
| something like that. Anyway, as I recall, this person was adding
standard
| functions to the addin to do more complex math at higher pecision. Note
| that Excel works at the IEEE standard for double precision which is about
15
| digits.
|
| Also, Chip Pearson has a page on working with Latitudes and Longitudes-
| maybe this has some bearing on your problem.
| http://www.cpearson.com/excel/latlong.htm
|
| Anyway, just declaring a variable as Variant will not make it a decimal
| value if you assign it a number. It will retain whatever precision it
had.
| You would have to assign it to the variant with the cdec conversion
function
|
| Dim vVariant as Variant
| vVariant = cdec(123.456567)
|
| --
| Regards,
| Tom Ogilvy
|
| "Peter M" wrote in message
| ...
| Jim,
|
| Does this mean that I could get greater accuracy simply by declaring
| variables as Variant rather than Double?
|
| ie use: Dim x, y, z
| rather than Dim x as double, y as double, z as double.
|
| Peter Morris
|
| "Jim Cone" wrote in message
| ...
| Peter,
|
| From a Myrna Larson post:
| '-----------------------------------
| The decimal data type is a subtype of a variant. You must Dim the
| variable
| as a
| variant, then put the data into it with the CDec function. Since
| Decimals
| can
| have up to 28 significant figures, and doubles are limited to 15 or
16,
| how do
| you assign a literal value to one? From a string representation of the
| number,
| i.e.
| Dim Dec As Variant
| Dec = CDec("1234567890123456789012345678")
| Debug.Print Dec, TypeName(Dec)
| '------------------------------------
| From a Chip Pearson post:
| To display these values on a worksheet, you'll have to change them to
| strings to prevent Excel from rounding them ...
| Range("C2").Value = " ' " & CStr(Dec)
| '-----------------------------------
|
| Regards,
| Jim Cone
| San Francisco, CA
|
| "Peter M" wrote in message
| ...
| I am developing an application to calculate navigation data from Sun
&
| Star
| sights (interesting for sailors, boring for everyone else).
| The problem is that I appear to be getting small inaccuracies when
| calculating angles. I have used Double as the data type. Looking
| through
| the help files I note that there should be a 'Decimal' data type
that
| uses
| many more digits so potentially improving accuracy. However, a line
| such
| as:
| Dim dLat as Decimal
| results in a message: 'Compile error: Expected: New or type name'
| I understand that this is saying it doesn't recognise the Decimal
data
| type.
| Do I have to add a library to use this? if so which one?
| Any ideas gratefully received.
| Peter Morris
|
|
|
|
|
|
|




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 error "some chart types cannot be combined with other chart types. Select a different chart types" roadsidetree Charts and Charting in Excel 15 June 2nd 09 10:53 AM
Trig Function seems odd. Ken McLennan Excel Worksheet Functions 9 May 8th 08 01:26 PM
Trig functions Kokopeelle Excel Worksheet Functions 3 September 30th 06 08:58 PM
Data types when importing Excel data to SQLServer [email protected] Excel Discussion (Misc queries) 1 September 27th 06 12:48 PM
how can I perform trig. functions usings grads 400deg per circle davystuff Excel Worksheet Functions 2 March 30th 06 03:00 PM


All times are GMT +1. The time now is 01:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"