473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Non-Integer time measurement

Zwoker
66
Hi All,

I'm using MS Access 2003. I have been trying to find out why portions of my VBA code have been running slower than expected, using code like the following:

Expand|Select|Wrap|Line Numbers
  1. Dim StartTime, EndTime As Date
  2. Dim TimeDelta As Single
  3.  
  4. StartTime = Time
  5. <Call some procedure>
  6. EndTime = Time
  7. TimeDelta = EndTime - StartTime
  8.  
The problem I have is that TimeDelta is always an integer number of seconds, after I multiply it by 86400 (the number of seconds in a day). Is there a way of getting the fractional portion of elapsed time, using a different mechanism? Or is this as accurate as VBA/MS Access gets?


Thanks.
Feb 24 '08 #1
11 2396
Scott Price
1,384 Expert 1GB
One point that you likely aren't aware of is that VBA requires a specific type declaration for each variable, otherwise it defaults to Variant data type.

Thus your first line is resulting in one Variant and one Date variable.

It's possible that the resulting unintended type coercion is causing your integer conversion. Try changing this and then trying again.

Regards,
Scott
Feb 25 '08 #2
Zwoker
66
Hi Scott,

Thanks for the reply.

Just to be sure I understand what you wrote, are you saying that the following two blocks of code are not identical from a VBA code perspective?

Expand|Select|Wrap|Line Numbers
  1. Dim StartTime, EndTime As Date
Expand|Select|Wrap|Line Numbers
  1. Dim StartTime As Date
  2. Dim EndTime As Date
Presuming that IS what you meant, I made all the variables involved in the time calculations have explicit AS "type" declarations, but the result is still the same. I get integer seconds calculated (allowing for rounding - some come out as 1.999999, as an example).

I googled a bit on this before posting, and what little I learned seemed to imply that the integer nature of the internal Time function was normal.

Any other ideas? Can I create a timer type variable on the fly and use that? If I was writing this in Delphi I'd try something like that. :)
Feb 25 '08 #3
Scott Price
1,384 Expert 1GB
You are right! In VBA (as opposed to other programming languages) the two variable declarations are not equal!

The Date data type provides an Integer value of the date passed to it. With Access there is a notorious problem using floating-point calculations, especially when there are any type conversions, of possible rounding errors.

Try passing your calculations through a specific forced conversion to double: i.e. CDbl([numbervalue]) before doing your calculations.

Regards,
Scott
Feb 25 '08 #4
Scott Price
1,384 Expert 1GB
As for the second part of your question, I'm not quite clear on what you are attempting to do.

You can take advantage of a timer in vba, but I'm not sure how that applies to what you are doing?

Regards,
Scott
Feb 25 '08 #5
ADezii
8,834 Expert 8TB
Hi All,

I'm using MS Access 2003. I have been trying to find out why portions of my VBA code have been running slower than expected, using code like the following:

Expand|Select|Wrap|Line Numbers
  1. Dim StartTime, EndTime As Date
  2. Dim TimeDelta As Single
  3.  
  4. StartTime = Time
  5. <Call some procedure>
  6. EndTime = Time
  7. TimeDelta = EndTime - StartTime
  8.  
The problem I have is that TimeDelta is always an integer number of seconds, after I multiply it by 86400 (the number of seconds in a day). Is there a way of getting the fractional portion of elapsed time, using a different mechanism? Or is this as accurate as VBA/MS Access gets?


Thanks.
If you don't mind me saying, you are using the completely wrong algorithm for accurately timing processes. Take a few minutes, and read this prior Tip:
timeGetTime() API Function
Feb 25 '08 #6
Zwoker
66
Thanks ADezii.

The example in that thread is exactly what I was looking for. I can now accurately measure where all the time in going in my VBA code.
Feb 25 '08 #7
NeoPa
32,556 Expert Mod 16PB
The point that ADezii makes in the article about running the procedure through a loop is the one I was going to make. His article is the Bees Knees though :) Everything in one place.
Feb 25 '08 #8
missinglinq
3,532 Expert 2GB
His article is the Bees Knees though :)
That's what I love about you Brits, you're so naturally Retro! I bet your local still has Glenn Miller on the juke box!

;0)>
Feb 25 '08 #9
NeoPa
32,556 Expert Mod 16PB
Sorry, he must be from before my time Linq ;)
Feb 25 '08 #10
ADezii
8,834 Expert 8TB
Sorry, he must be from before my time Linq ;)
We are talking about Glen who, guys?
Feb 25 '08 #11
NeoPa
32,556 Expert Mod 16PB
Nice try ADezii. No-one's believing you, you know :D
Feb 25 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
14
by: Patrick Kowalzick | last post by:
Dear all, I have an existing piece of code with a struct with some PODs. struct A { int x; int y; };
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
0
by: amitvps | last post by:
Secure Socket Layer is very important and useful for any web application but it brings some problems too with itself. Handling navigation between secure and non-secure pages is one of the cumbersome...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.