string literal for half-a-second

Ross Wise
Ross Wise used Ask the Experts™
on
Is there an acceptable string literal in the VBA (Access 2013) TimeValue function to express fractions of a second?
In this particular case a Half-Second.

TU_HALF_SECOND = TimeValue("00:00:00.5")         ' Type mismatch error

As a work-around I have calculated it mathematically from a value of one-second:

   TU_HALF_SECOND = TimeValue("00:00:01")         '  The smallest (non-zero) literal I have found that works
   TUVal_HALF_SECOND = CDbl(TU_HALF_SECOND)
   
   TUVal_HALF_SECOND = TUVal_ZERO_SECONDS + (TUVal_HALF_SECOND - TUVal_ZERO_SECONDS) / 2  
                                                                      '  Zero seconds obtained via TimeValue("00:00:00")    ::     I'm aware that this may be redundant
   TU_HALF_SECOND = CDate(TUVal_HALF_SECOND)

So this is not an emergency, I'm just curious.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
MIS Liason
Most Valuable Expert 2012
Commented:
I think this my be relavent.

http://www.devx.com/dbzone/Article/39046

This was a popular question a few years ago, but I think interest faded when people discovered that they rarely need this level of precision, ...and the amount of work to get it, ...was not really worth it...

Hope this helps

JeffCoachman
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
Your workaround is correct, though a little long-winded as you can calculate it directly:

    TU_HALF_SECOND = TimeValue("00:00:01") / 2

If you need more that this single value or calculations on split seconds, you can use the code provided by Jeff.

/gustav
Ross WiseInformation Technology Support Coordinator

Author

Commented:
Thank you both.
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
You are welcome!

/gustav

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial