Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Time Tenth & Hundredths

58 views
Skip to first unread message

BeeJ

unread,
Oct 12, 2012, 5:12:54 PM10/12/12
to
Is there a better way than ... ?
Want two digit string. 00 .. 99

Public Function TimerTH() As String

' fractional part
' returning first two digits after the decimal point
' e.g.
' 1234 -> 00
' 1234.5 -> 50
' 1235.69 -> 69
'
Dim sTimer As String
Dim lPtr As Long

sTimer = Timer
lPtr = InStr(1, sTimer, ".")

If lPtr Then '
' handle 1234.5 and 1234.55 etc.
TimerTH = Left$(Mid$(sTimer, lPtr + 1, 2) & "0", 2)

Else
' special case when there is no decimal point
TimerTH = "00"

End If

End Function 'TimerTH


Eduardo

unread,
Oct 12, 2012, 6:18:33 PM10/12/12
to

"BeeJ" <nos...@spamnot.com> escribió en el mensaje
news:k5a14h$3fd$1...@speranza.aioe.org...
sTimer = Timer
TimerTH = Right(Format(sTimer, "#.00"), 2)


BeeJ

unread,
Oct 12, 2012, 8:02:23 PM10/12/12
to
Eduardo formulated on Friday :
Changed to
TimerTH = Right(Format(Timer, "#.00"), 2)
Then
TimerTH = Right$(Format$(Timer, "#.00"), 2)

IDE or compiled can't see any real difference.

Compared to my code, your takes roughly twice as long to get the
answer.
But in the real world application, yours is easier to understand and
simpler, smarter coding.

Thanks!


Larry Serflaten

unread,
Oct 12, 2012, 10:16:28 PM10/12/12
to
BeeJ wrote:
> Is there a better way than ... ?
>
> Want two digit string. 00 .. 99


It would be better to leave off fussing with a string variable until you have
the digits you need:

LFS


Public Function Timer00() As String
Dim hnd As Long
Dim tmr As Long

tmr = Timer * 100
hnd = (tmr \ 100) * 100
tmr = tmr - hnd

If tmr < 10 Then
Timer00 = "0" & CStr(tmr)
Else
Timer00 = CStr(tmr)
End If

End Function

Mike Williams

unread,
Oct 13, 2012, 4:56:25 AM10/13/12
to
"BeeJ" <nos...@spamnot.com> wrote in message
news:k5ab2e$oa4$1...@speranza.aioe.org...
>>>
>>> [BeeJ said] Want two digit string. 00 .. 99 [from Timer
>>> function] returning first two digits after the decimal point.
>>> Is there a better way than ... ?
>>> [most of BeeJ's code snipped]
>>> sTimer = Timer
>>> lPtr = InStr(1, sTimer, ".")
>>> If lPtr Then . . .
>>
>> [Eduardo said] Try the following:
>> sTimer = Timer
>> TimerTH = Right(Format(sTimer, "#.00"), 2)
>
> [BeeJ said] Compared to my code, your code
> takes roughly twice as long to get the answer.

But you didn't ask for a faster way BeeJ, you asked for a better way, and
that's what Eduardo gave you. Eduardo's code works, whereas yours does not
(at least not in countries which use a different character for the decimal
point). There are of course various ways of performing the task both faster
and better, as Larry has shown, but if I was asked to choose between your
own code and Eduardo's I would choose Eduardo's every time. Code that works
is always better than code that does not ;-)

Mike



Eduardo

unread,
Oct 13, 2012, 5:04:56 AM10/13/12
to

"Mike Williams" <Mi...@WhiskyAndCoke.com> escribió en el mensaje
news:k5babm$ag2$1...@dont-email.me...
> "BeeJ" <nos...@spamnot.com> wrote in message
> news:k5ab2e$oa4$1...@speranza.aioe.org...

> (at least not in countries which use a different character for the decimal
> point).

Yes, I didn't mention that I had to change the hardcoded "." to "," for
BeeJ's code to work here.


BeeJ

unread,
Oct 13, 2012, 10:56:04 AM10/13/12
to
Mike Williams formulated the question :
I evoked what I needed.

Keep forgetting about 'them foreigners'. Ah but then there was Bridget
and Elke and Sophia ... Showing my age.

On my way to the kitchen to cook up some bacon.


CoderX

unread,
Oct 13, 2012, 12:16:52 PM10/13/12
to
Interesting choice of word. Evoke. Defined as "To summon, or call forth."
Is that what you consider these real programmers? Folks to summon, for what
you need? Sounds about right to me.

"BeeJ" <nos...@spamnot.com> wrote in message
news:k5bve2$rou$1...@dont-email.me...

BeeJ

unread,
Oct 13, 2012, 4:27:37 PM10/13/12
to
Larry Serflaten explained on 10/12/2012 :
Nice. The best!


Deanna Earley

unread,
Oct 15, 2012, 5:51:55 AM10/15/12
to
On 13/10/2012 03:16, Larry Serflaten wrote:
> If tmr < 10 Then
> Timer00 = "0" & CStr(tmr)
> Else
> Timer00 = CStr(tmr)
> End If

Can't this bit be replaced with:
Timer00 = Format(tmr, "00")

--
Deanna Earley (dee.e...@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)

Mike Williams

unread,
Oct 15, 2012, 7:47:10 AM10/15/12
to
"Deanna Earley" <dee.e...@icode.co.uk> wrote in message
news:k5gmbp$lqq$1...@speranza.aioe.org...
> On 13/10/2012 03:16, Larry Serflaten wrote:
>> If tmr < 10 Then
>> Timer00 = "0" & CStr(tmr)
>> Else
>> Timer00 = CStr(tmr)
>> End If
>
> Can't this bit be replaced with:
> Timer00 = Format(tmr, "00")

Yes, but the former is maybe seven or eight microseconds faster and BeeJ
seemed really concerned about those few extra microseconds, even though he
is only using it a few times per second and even though the Timer he is
using is stuck to a best resolution of somewhere between one thousand and
fifteen thousand microseconds ;-)

Mike


Larry Serflaten

unread,
Oct 15, 2012, 7:57:58 AM10/15/12
to
Deanna Earley wrote:

> > If tmr < 10 Then
> > Timer00 = "0" & CStr(tmr)
> > Else
> > Timer00 = CStr(tmr)
> > End If
>
> Can't this bit be replaced with:
>
> Timer00 = Format(tmr, "00")


Very observant of you. Also, this bit:

tmr = Timer * 100
hnd = (tmr \ 100) * 100
tmr = tmr - hnd

could very well be replaced with:

tmr = (Timer - Int(Timer)) * 100

Applying the changes, the whole function could then be (ala Rick Rothstein)

Function Timer00() As String
Timer00 = Format$(Now, "yyyymmddhhnnss") & Format$((Timer - Int(Timer)) * 100, "00")
End Function

So is it really necessary to have such a function at all???

;-)
LFS

BeeJ

unread,
Oct 16, 2012, 10:55:19 AM10/16/12
to
After serious thinking Mike Williams wrote :
Are you referring to the problem of roll-over?
If you run the algo as fast as possible it shows on my laptop that
there is a disconnect between Timer and Now. i.e. seconds on Now
mismatch for seconds from Timer. So I am using Timer to generate the
time portion.
So even if I run the algo at a slow sample rate it is possible to get
an invalid value unless I use the Timer to et HHNNSS portion.
I do not care about the accuracy just that the next algo value is the
same as or larger than the previous. Larry's later input, adding a
counter, makes it such that all algo returns are unique and increment.
I added that the my timer solution so that I do get a time relative
value. I do not care about the femtoseconds, nanoseconds, or
microseconds nor even the milliseconds other than a way to see that is
later in time.


Larry Serflaten

unread,
Oct 16, 2012, 1:17:55 PM10/16/12
to
BeeJ wrote:

> If you run the algo as fast as possible it shows on my laptop that
> there is a disconnect between Timer and Now. i.e. seconds on Now
> mismatch for seconds from Timer. So I am using Timer to generate the
> time portion.
> So even if I run the algo at a slow sample rate it is possible to get
> an invalid value unless I use the Timer to et HHNNSS portion.


Here is another way to avoid that mismatch; add Timer to the current date:

LFS


Function TimeID() As String
Static old As String, cnt As Long
Dim tmr As Single, dtm As String

tmr = Timer
dtm = Format$(DateAdd("s", tmr, Date), "yyyymmddhhnnss") & Format$((tmr - Int(tmr)) * 100, "00")
If dtm = old Then
If cnt < 999 Then cnt = cnt + 1
Else
cnt = 0
End If
old = dtm
TimeID = dtm & Format$(cnt, "000")
End Function

Mike Williams

unread,
Oct 16, 2012, 1:57:33 PM10/16/12
to
"BeeJ" <nos...@spamnot.com> wrote in message
news:k5jsgp$l5p$1...@dont-email.me...
>> After serious thinking Mike Williams wrote :
>> Yes, but the former is maybe seven or eight microseconds
>> faster and BeeJ seemed really concerned about those few
>> extra microseconds . . .
>
> I do not care about the femtoseconds, nanoseconds, or microseconds nor
> even the milliseconds other than a way
> to see that is later in time.

So why did you complain about the speed of Eduardo's code when you said, and
I quote, "Compared to my code, yours takes roughly twice as long to get the
answer"? Make your mind up, BeeJ!

Mike


BeeJ

unread,
Oct 16, 2012, 9:52:40 PM10/16/12
to
Mike Williams expressed precisely :
Exploring the options and expanding the envelope.
One of the reasons I was so successful in my career besides getting the
job done.


Mike Williams

unread,
Oct 17, 2012, 5:33:02 AM10/17/12
to

"BeeJ" <nos...@spamnot.com> wrote in message
news:k5l31c$r7a$1...@dont-email.me...
>>> [BeeJ said] I do not care about the femtoseconds, nanoseconds
>>> or microseconds nor even the milliseconds other than a way
>>> to see that is later in time.
>>
>> [Mike said] So why did you complain about the speed of Eduardo's
>> code when you said, and I quote, "Compared to my code, yours takes
>> roughly twice as long to get the answer"? Make your mind up, BeeJ!
>
> [BeeJ said] Exploring the options and expanding the envelope. One of
> the reasons I was so successful in my career besides getting the job done.

Yeah. It's good to see an expert at work. In fact you're the first
professional Copier and Paster I've ever met ;-)

Mike


BeeJ

unread,
Oct 17, 2012, 10:05:54 PM10/17/12
to
It happens that Mike Williams formulated :
You must be blind. And you are telling me that you never took sample
code and used or amplified it.

Anyway, using sample code is an insignificant part of the millions, yes
millions, of lines of code that I have written in the last 40 years in:

Assembly language
Fortran
C
PLM
BASIC
VB6
Java (not much)
C++ (not much)
Labview

I do not claim to be an expert in any of them. But I get the job done!
And that is more that I can say about many of the people that I hired
and fired over the years. They came to work for a paycheck and I had
to do their design work for them but not for long because the door
closed quickly behind them.

I have written and sold complete operating systems in assembly language
for the early PCs: Altair and IMSAI. This just before CP/M.
And when CP/M came out I wrote assembly language drivers for hardware I
designed.
My assembly code has been published in national magazines.
I wrote text editors in assembly language that were sold by a large
national PC manufacturer in the early days of the PC. I got nice
commission checks every quarter.
I have written production code that was approved by and sold to the
U.S. Government and is still in operation across the U.S. without one
code problem.
Most of my code was written for hardware that I designed or embedded
computer subsystems that I designed into my systems.
When I design a system I design the hardware and the software so I do
not have to decipher the crap documentation provided by Microsoft or
others. I create my own crap documentation that others had to
decipher. lol
My last hardware design, from scratch, consisted of 56 unique pieces of
electronic hardware, each taking up a D size VXI board. Then I
designed and wrote all the software to integrate them. That was a
multi-million dollar piece of hardware.

etc. etc.

You know nothing about who I am or what I do or have done.
Cheap shots only reflect on those that make them.

So maybe I am not up on Windows stuff, so what. I freely admit that
Windows is new territory for me. And maybe my memory is not as good as
it used to be, it isn't. Isn't this a rehash of a previous
conversation!
I am here to learn new things, challenge myself and others, and do
other things that you and a few others simply do not seem understand.

At 70 years of age, I think I am doing fairly well.
So let's cut out the senior abuse and get down to VB6 business.

But then you and a few others are looking only through the peep hole
that you choose to look through.


CoderX

unread,
Oct 17, 2012, 11:52:14 PM10/17/12
to
This is the Internet, where anyone can claim anything.

Did you know I played chess with Bill Gates in 1995? Or that I wrote the
updated firmware for the space shuttle?

I'll bet you didn't.

"BeeJ" <nos...@spamnot.com> wrote in message
news:k5no5t$q21$1...@dont-email.me...

BeeJ

unread,
Oct 18, 2012, 1:45:58 AM10/18/12
to
CoderX used his keyboard to write :
Congratulations. Either for doing it or telling a tall tale.
I really could not care what you believe as long as you support this
group and contribute. Unfortunately I am too new at the Windows/VB6
detail stuff so I have little to offer other than questions. Oh wait
... that is half of the purpose.


Mike Williams

unread,
Oct 18, 2012, 2:04:16 AM10/18/12
to
"BeeJ" <nos...@spamnot.com> wrote in message
news:k5no5t$q21$1...@dont-email.me...
> It happens that Mike Williams formulated :
>> Yeah. It's good to see an expert at work. In fact you're
>> the first professional Copier and Paster I've ever met ;-)
>
> You must be blind. And you are telling me that you
> never took sample code and used or amplified it.

Of course I have. Everybody is a least partially the product of everyone
else. This is true in all walks of life, and for programmers it sometimes
involves copying and pasting code that was written by someone else. It's
just that you seem to have gone the whole hog and have actually made a
profession out of copying and pasting ;-)

> At 70 years of age, I think I am doing fairly well.
> So let's cut out the senior abuse . . .

Pulling the old fart one, eh? Don't bother, it doesn't work on me.

Mike



Deanna Earley

unread,
Oct 18, 2012, 5:16:57 AM10/18/12
to
On 18/10/2012 04:52, CoderX wrote:
> This is the Internet, where anyone can claim anything.
>
> Did you know I played chess with Bill Gates in 1995? Or that I wrote the
> updated firmware for the space shuttle?

Is this a game of cheat?
I never was very good at it.. :p

Deanna Earley

unread,
Oct 18, 2012, 5:33:28 AM10/18/12
to
On 16/10/2012 15:55, BeeJ wrote:
> I do not care about the accuracy just that the next algo value is the
> same as or larger than the previous.

So why not just use a sequential number?
Number = Number + 1
If Number is a Long then it won't overflow in any reasonable amount of
time (68 years at once a second).

Eduardo

unread,
Oct 18, 2012, 6:20:15 AM10/18/12
to

"BeeJ" <nos...@spamnot.com> escribió en el mensaje
news:k5no5t$q21$1...@dont-email.me...

> I have written and sold complete operating systems in assembly language
> for the early PCs: Altair and IMSAI. This just before CP/M.

So you are one of the fathers of computers?


Schmidt

unread,
Oct 18, 2012, 6:23:38 AM10/18/12
to
Am 18.10.2012 11:33, schrieb Deanna Earley:
> On 16/10/2012 15:55, BeeJ wrote:
>> I do not care about the accuracy just that the next algo value
>> is the same as or larger than the previous.
>
> So why not just use a sequential number?
> Number = Number + 1
> If Number is a Long then it won't overflow in any reasonable
> amount of time (68 years at once a second).
>

I assume, it is just used as a kind of "UniqueID" -
(useful for example, when you want to create unique
identifiers for DB-Records on the clientside).

And when used for that, you would have to ensure, that your
proposed CounterValue remains unique (or "alive"), even when
you close and restart the Client-Application.

The current system-time is then just "handy" as a nice
Base-Initializer which changes between App-sessions
(and also differs at least a little bit among different client-
machines, due to differently ticking "hardware-clock-chips",
even if there's a synchronizing time-server in the LAN).

A higher grade of uniqueness (even when the ID-Generator
is called pretty frequently as e.g. in a loop) is then
ensured over the amount of decimal-places in the
ms, µs or nano-sec part - and when you ensure that
this second (high-resolution) part of such a concatenated
unique timestamp also always increases its value between calls.

I use a similar thing (also a Sytem-VB-DateTime based stamp,
but finally converted to a 64Bit Integer-Value with a resolution
in the nano-second-range) in my DB-classes, to be able to create
64Bit UniqueIDs, which don't take up that much space in the DB
(8 Bytes only), compared to a String-based Timestamp-ID -
and they can be treated within SQL-Queries without forcing the
query-engine to switch into "slower string- or character-mode"
(in Key-Lookups or Joins, whatever).

The nice side-effect (e.g. when used in DB-Tables as the
Record-identifier or Primary-Key) is, that you ensure a
"timely-sort" of the records you add to a table pretty
much automatically - and that this UniqueID (this primary
key of the record) is always interpretable also as a
VB-DateTime-stamp on the client-side (and so you have
the creation-time of the record always available).

Not sure, what BeeJ is using that for - but the approach is
known and useful.

Olaf

Eduardo

unread,
Oct 18, 2012, 8:31:18 AM10/18/12
to

"Schmidt" <s...@online.de> escribió en el mensaje
news:k5olbi$365$1...@dont-email.me...
What about this?: http://support.microsoft.com/kb/176790/en-us


CoderX

unread,
Oct 18, 2012, 9:07:39 AM10/18/12
to
<eg>

"Deanna Earley" <dee.e...@icode.co.uk> wrote in message
news:k5ohe7$4e7$1...@speranza.aioe.org...

ralph

unread,
Oct 18, 2012, 10:49:50 AM10/18/12
to
On Thu, 18 Oct 2012 12:23:38 +0200, Schmidt <s...@online.de> wrote:

<snipped>

>
>The nice side-effect (e.g. when used in DB-Tables as the
>Record-identifier or Primary-Key) is, that you ensure a
>"timely-sort" of the records you add to a table pretty
>much automatically - and that this UniqueID (this primary
>key of the record) is always interpretable also as a
>VB-DateTime-stamp on the client-side (and so you have
>the creation-time of the record always available).
>
>Not sure, what BeeJ is using that for - but the approach is
>known and useful.
>

That fact that we don't know what the OP is using it for, nor the
environment in which it plays, is a key and limiting factor to any
advice.

Your emphasis on "timely-sort" is note-worthy. Given the OP's
propensity for linear and asynchronous solutions it is possible it is
being used to monitor concurrency.

-ralph

ralph

unread,
Oct 18, 2012, 10:51:48 AM10/18/12
to
On Thu, 18 Oct 2012 09:49:50 -0500, ralph <nt_cons...@yahoo.com>
wrote:
Or "synchronous", depending on view. <g>

Schmidt

unread,
Oct 18, 2012, 5:00:26 PM10/18/12
to
Am 18.10.2012 14:31, schrieb Eduardo:

[UniqueID as 64Bit Integer with TimeInformation]
Yep, that's an alternative which is a little bit less "risky"
with regards to "true uniqueness" (the probability of a
collision due to an already existing, equally created Key-
Value is a few magnitudes lower, but only in a multiuser-
multiple-clientmachines-scenario where the clients are
"tightly time-synchronized").

The disadvantages of GUIDs are (especially in context of DB-Usage)
- no timestamp-information
- takes up a lot more Bytes in a DB-Field
- usually stored as String-based PrimaryKey - which means
slower sorts, slower indexing, slower Join-comparisons
- slower inserts of DB-Records, due to "untimely, non-increasing
sort-order" (PrimaryKeys have an automatic index in place - and
when a new record with such a random GUID-value as its primary
key is inserted, then the updating of the primary-key-index-area
of the given table has to place this new GUID "somewhere inbetween",
which is more costly with regards to CPU-Cycles, compared with
a new UniqueValue which luckily can be inserted at the end of
an existing Primary-Key-Index-Area in most cases.


Olaf

Schmidt

unread,
Oct 18, 2012, 5:06:12 PM10/18/12
to
Am 18.10.2012 16:49, schrieb ralph:

> Your emphasis on "timely-sort" is note-worthy. Given the OP's
> propensity for linear and asynchronous solutions it is possible
> it is being used to monitor concurrency.

Considering his latest 'WebCam-Questions', it could
also be used as a "FrameID-TimeStamp", especially when
the capturing happens in multiple ActiveX-Exe-Threads
(against multiple Cams), which I think BeeJ also has
mentioned some time ago... but just guessing...

<shrug>

Olaf

BeeJ

unread,
Oct 19, 2012, 9:06:12 PM10/19/12
to
General purpose. And with Larry's input even better. I was
concentrating too hard on just getting mSec. The later post from Arne
about GetSystemTime makes it easier than my crude code. I never knew
such a call was available. All Googling about time only talked about
the time to seconds unless talking about timers.

Again, I am not looking for accuracy just a way of documenting when
something approximatly happened and that the sequence of events is
correct.

If I was younger and had more energy I would write a book about all I
have learned. Unfortunately, another VB would not be high on the best
sellers list.


BeeJ

unread,
Oct 19, 2012, 9:15:52 PM10/19/12
to
Eduardo wrote :
I wish. I was actually designing a computer, using TTL logic and count
them, magnetic core memory, when the 8080 hit the market. Then I was
totally blown out of the water with the advent of the Altair. So I got
on board that train and rode along for a great ride. I designed
hardware interfaces on the S100 bus for things like paper tape
reader/punch units and interfaces to military equipment. All fun and
very interesting. I got to travel all over the country. I had
sub-contractors in several eastern states that built my equipment.
Every fly into West Virginia? What a hoot. The plane does not descend
for landing, it just flys almost level to the top of a mountain. Very
strange feeling the first time watching the ground coming up with no
sensation of descending. I had the window seat.


BeeJ

unread,
Oct 19, 2012, 9:21:50 PM10/19/12
to
OK, interesting, but I want time tag as part of the filename.


0 new messages