For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > December 2005 > Time Repair???









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Time Repair???
HotRod

2005-12-12, 6:56 pm

Has anyone ever created or seen some VB code to help repair time. I have a
list of 60'000 times that I need to check to make sure they are valid and
then reapir them. In general all of the problems are input related. Here are
some examples of problems I keep repairing. I want to be able to jsut input
the range for the times in my selection and then see if the code can
possible figure out the solution. I was just wondering if anyone has seen
anything???

Visually it's easy to repair but a little harder in code. I'd like to use
the isTime to determine if it's a date and then try and fix it.

4:50 p.m.
450 pm
4:50pm
10:30a
1030a


kpg

2005-12-12, 6:56 pm

HotRod <NOSPAM@youremail.com> said something like

> # Name resolution details: file://c:\temp\575384.htm (12/12/2005
> 3:15:06 PM) # Has anyone ever created or seen some VB code to help
> repair time. I have a list of 60'000 times that I need to check to
> make sure they are valid and then reapir them. In general all of the
> problems are input related. Here are some examples of problems I keep
> repairing. I want to be able to jsut input the range for the times in
> my selection and then see if the code can possible figure out the
> solution. I was just wondering if anyone has seen anything???
>
> Visually it's easy to repair but a little harder in code. I'd like to
> use the isTime to determine if it's a date and then try and fix it.
>
> 4:50 p.m.
> 450 pm
> 4:50pm
> 10:30a
> 1030a


lol - I have a routine in Assembly that takes user input and
tries to make a time out of it - a similar problem to what you
have. It proceedes left to right trying to make valid hour, min
and seconds - but first you need to know if its 12 or 24 hour, so
I check for am/pm first - this limits what a valid hour can look like.

IMHO isDate is not going to work for you. I would bite the bullet
and just start coding. You'll have to have rules to handle ambiguous
input, but if you can look at it and tell what the time is just let
that be your guide.
Bob Butler

2005-12-12, 6:56 pm

"HotRod" <NOSPAM@youremail.com> wrote in message
news:%23YfEn$1$FHA.3140@TK2MSFTNGP14.phx.gbl
> Has anyone ever created or seen some VB code to help repair time. I
> have a list of 60'000 times that I need to check to make sure they
> are valid and then reapir them. In general all of the problems are
> input related. Here are some examples of problems I keep repairing. I
> want to be able to jsut input the range for the times in my selection
> and then see if the code can possible figure out the solution. I was
> just wondering if anyone has seen anything???
>
> Visually it's easy to repair but a little harder in code. I'd like to
> use the isTime to determine if it's a date and then try and fix it.
>
> 4:50 p.m.
> 450 pm
> 4:50pm
> 10:30a
> 1030a


I don't understand what you mean by "input the range for the times in my
selection" but here's some quick and dirty code that fixes the examples
given

Private Sub Main()
Debug.Print FixTime("4:50 p.m.")
Debug.Print FixTime("450 pm")
Debug.Print FixTime("4:50pm")
Debug.Print FixTime("10:30a")
Debug.Print FixTime("1030 a")
End Sub

Public Function FixTime(ByVal TimeIn As String) As String
Dim sTest As String
Dim sXM As String
' remove spaces and dots from input
sTest = Replace(Replace(TimeIn, ".", ""), " ", "")
' check for a/am/p/pm at the end of the string
' first remove any trailing 'm'
If StrComp(Right$(sTest, 1), "m", vbTextCompare) = 0 Then
sTest = Left$(sTest, Len(sTest) - 1)
End If
' now look for trailing a or p and store in sXM
If InStr(1, "ap", Right$(sTest, 1), vbTextCompare) > 0 Then
sXM = UCase$(Right$(sTest, 1)) & "M"
sTest = Left$(sTest, Len(sTest) - 1)
End If
' check for embedded colon and insert if not found
If InStr(1, sTest, ":") = 0 Then
If Len(sTest) < 3 Then
sTest = "0:" & Right$("00" & sTest, 2)
Else
sTest = Left$(sTest, Len(sTest) - 2) & ":" & Right$(sTest, 2)
End If
End If
' restore AM/PM indicator
sTest = sTest & sXM
Debug.Print TimeIn & " -> " & sTest & " -> ";
' if is recognizable then return standardized format
If IsDate(sTest) Then
FixTime = Format$(CDate(sTest), "hh:nn:ss")
Else
FixTime = "Invalid"
End If
End Function



--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Jeff Johnson [MVP: VB]

2005-12-12, 6:56 pm


"HotRod" <NOSPAM@youremail.com> wrote in message
news:%23YfEn$1$FHA.3140@TK2MSFTNGP14.phx.gbl...

> Has anyone ever created or seen some VB code to help repair time.


If you do, could you please stop me from getting married?



(Seriously, am I the only one who read the question like that?)


Bob Butler

2005-12-12, 6:56 pm

"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:O12oyZ2$FHA.3048@TK2MSFTNGP15.phx.gbl
> "HotRod" <NOSPAM@youremail.com> wrote in message
> news:%23YfEn$1$FHA.3140@TK2MSFTNGP14.phx.gbl...
>
>
> If you do, could you please stop me from getting married?
>
> (Seriously, am I the only one who read the question like that?)


Yes, you are. <g>

It does sound like the start of a science fiction novel though

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Joe O

2005-12-12, 6:56 pm

Shhhhhhh Jeff... National organization for women will label you wimp

"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:O12oyZ2$FHA.3048@TK2MSFTNGP15.phx.gbl...
>
> "HotRod" <NOSPAM@youremail.com> wrote in message
> news:%23YfEn$1$FHA.3140@TK2MSFTNGP14.phx.gbl...
>
>
> If you do, could you please stop me from getting married?
>
>
>
> (Seriously, am I the only one who read the question like that?)
>
>



MikeD

2005-12-12, 6:56 pm


"HotRod" <NOSPAM@youremail.com> wrote in message
news:%23YfEn$1$FHA.3140@TK2MSFTNGP14.phx.gbl...
> Has anyone ever created or seen some VB code to help repair time. I have a
> list of 60'000 times that I need to check to make sure they are valid and
> then reapir them. In general all of the problems are input related.


IMO, the "problem" lies right there. Don't let people input invalid times
to begin with. Either verify it before it gets written/saved OR use
something like the DTPicker control to ensure only valid times can be input.

Having to correct "bad data" after it's been written/saved is something
that, theoretically at least, you should never have to do. But, I've taken
over programs which didn't perform data validation and so I understand that
sometimes you may have to correct bad data on a mass scale.

You can write code to catch common data entry errors, but if there's been no
validation whatsoever on what users input, you can't possibly write code to
deal with all of them. Therefore, you still need to provide some way of
manually correcting the data. For example, you write code to automatically
fix the most common mistakes, but if those all fall through (IOW, from the
data, you can't determine what the time really should be) then you need to
show a dialog box (or MsgBox) allowing manual correction.

--
Mike
Microsoft MVP Visual Basic


Michael C

2005-12-12, 6:56 pm

"Joe O" <jp3BlessNoSpam@hotmail.com> wrote in message
news:OCKaGq2$FHA.1124@TK2MSFTNGP10.phx.gbl...
> Shhhhhhh Jeff... National organization for women will label you wimp


Not if he goes back to before he was married :-)

Michael


Kevin Provance

2005-12-12, 9:55 pm


> Has anyone ever created or seen some VB code to help repair time.


If time is broken, we all have bigger problems. <g>

Sorry, couldn't resist!

- Kev


Kevin Provance

2005-12-12, 9:55 pm

No Jeff...it was the first thing I thought of when I read that first
sentance. Some smart alec answer in regards to time travel.

Actually, I have one short sci-fi story that revolves around the fact that
the current time index is stuck in the year 2095 because the fifth dimension
has crossed the forth dimension (time) which is allowing extra-dimensionals
to cross into our universe. The team assigned to stop these
inter-dimensionals and fix the time index are TDIs (temporal displacement
investigators) and the whole story revoles around that.

I thought about writing it as a pilot and pitching it to sci-fi channel. :)

- Kev


"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:O12oyZ2$FHA.3048@TK2MSFTNGP15.phx.gbl...
>
> "HotRod" <NOSPAM@youremail.com> wrote in message
> news:%23YfEn$1$FHA.3140@TK2MSFTNGP14.phx.gbl...
>
>
> If you do, could you please stop me from getting married?
>
>
>
> (Seriously, am I the only one who read the question like that?)
>



Lenny Abbey

2005-12-13, 7:55 am

Whenever I need a date or time input I immediately convert it to Julian Date
(with decimals). The business I am in needs this anyway (astronomy).

Then you can do any mathematics you need, and convert the answer back to
regular notation for display.

Lenny


"HotRod" <NOSPAM@youremail.com> wrote in message
news:%23YfEn$1$FHA.3140@TK2MSFTNGP14.phx.gbl...
> Has anyone ever created or seen some VB code to help repair time. I have a
> list of 60'000 times that I need to check to make sure they are valid and
> then reapir them. In general all of the problems are input related. Here

are
> some examples of problems I keep repairing. I want to be able to jsut

input
> the range for the times in my selection and then see if the code can
> possible figure out the solution. I was just wondering if anyone has seen
> anything???
>
> Visually it's easy to repair but a little harder in code. I'd like to use
> the isTime to determine if it's a date and then try and fix it.
>
> 4:50 p.m.
> 450 pm
> 4:50pm
> 10:30a
> 1030a
>
>



HotRod

2005-12-13, 6:56 pm

THANKS for the suggestions. I wish I could validate the data and solve the
problems but some of this data is from the last decade. If I could get the
"Time Repair" machine working I could go back and write some sort of COBOL
validation program but that might be more work then just fixing the times I
have.

P.S. I've noticed that "time" may be broken. When I visit some newsgroups
people have posted messages for dates and times that haven't happened yet so
it begs the question am I a few days behind or are they ahead??? Also why
won;to they tell me what the winning lottery numbers are when I ask them in
their post???

THANKS Everyone.




"HotRod" <NOSPAM@youremail.com> wrote in message
news:%23YfEn$1$FHA.3140@TK2MSFTNGP14.phx.gbl...
> Has anyone ever created or seen some VB code to help repair time. I have a
> list of 60'000 times that I need to check to make sure they are valid and
> then reapir them. In general all of the problems are input related. Here
> are some examples of problems I keep repairing. I want to be able to jsut
> input the range for the times in my selection and then see if the code can
> possible figure out the solution. I was just wondering if anyone has seen
> anything???
>
> Visually it's easy to repair but a little harder in code. I'd like to use
> the isTime to determine if it's a date and then try and fix it.
>
> 4:50 p.m.
> 450 pm
> 4:50pm
> 10:30a
> 1030a
>
>



Saga

2005-12-13, 6:56 pm


See it this way:

If -you- knew the winning numbers for the lottery and some one asked
you, would you tell them? <eg>

Saga

"HotRod" <NOSPAM@youremail.com> wrote in message
news:u5WQdiAAGHA.4012@TK2MSFTNGP10.phx.gbl...
> THANKS for the suggestions. I wish I could validate the data and solve
> the problems but some of this data is from the last decade. If I could
> get the "Time Repair" machine working I could go back and write some
> sort of COBOL validation program but that might be more work then just
> fixing the times I have.
>
> P.S. I've noticed that "time" may be broken. When I visit some
> newsgroups people have posted messages for dates and times that
> haven't happened yet so it begs the question am I a few days behind or
> are they ahead??? Also why won;to they tell me what the winning
> lottery numbers are when I ask them in their post???
>
> THANKS Everyone.
>
>
>
>
> "HotRod" <NOSPAM@youremail.com> wrote in message
> news:%23YfEn$1$FHA.3140@TK2MSFTNGP14.phx.gbl...
>
>



Jeff Johnson [MVP: VB]

2005-12-13, 6:56 pm


"HotRod" <NOSPAM@youremail.com> wrote in message
news:u5WQdiAAGHA.4012@TK2MSFTNGP10.phx.gbl...

> P.S. I've noticed that "time" may be broken. When I visit some newsgroups
> people have posted messages for dates and times that haven't happened yet
> so it begs the question am I a few days behind or are they ahead???


This is known as future-posting and it's extremely rude. It's the newsgroup
equivalent of cutting in line. I generally rip people a new one when I see
them do it.


HotRod

2005-12-14, 6:57 pm

I understand. I was just trying to be humorous.


"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:u1XRIPDAGHA.2320@TK2MSFTNGP11.phx.gbl...
>
> "HotRod" <NOSPAM@youremail.com> wrote in message
> news:u5WQdiAAGHA.4012@TK2MSFTNGP10.phx.gbl...
>
>
> This is known as future-posting and it's extremely rude. It's the
> newsgroup equivalent of cutting in line. I generally rip people a new one
> when I see them do it.
>



Phill W.

2005-12-15, 6:55 pm

"HotRod" <NOSPAM@youremail.com> wrote in message
news:%23YfEn$1$FHA.3140@TK2MSFTNGP14.phx.gbl...
> Has anyone ever created or seen some VB code to help repair time.


Don;t let dodgy data in the front door and you won't have to clear it up and
the other end.
But you've been told that already.

Your 60,000 list problem remains, so let's have a stab at it.

Your list:

> 4:50 p.m.
> 450 pm
> 4:50pm
> 10:30a
> 1030a


IsTime won't help, because it uses fairly strict rules, which the above
don't
stick to. However, you could apply some preliminary data cleaning, then
have a stab at making sense of whatcomes out of that, something like

sTime = LCase( (any of the above) )
sTime = Replace( sTime, " ", "" ) ' trash the spaces
sTime = Replace( sTime, ".", "" ) ' and the '.'s
sTime = Replace( sTime, "a", "" ) ' and the "am", "pm" thingies
sTime = Replace( sTime, "m", "" )

If Instr( sTime, "p" ) > 0 Then
sTime = Replace( sTime, "p", "" )
bAdd12Hours = True
End If

which reduces the above list to

4:50 (+12 hours)
450 (+12 hours)
4:50 (+12 hours)
10:30
1030

Now we can start making guesses about what's left -

If there's a ":" in there, we can split it directly into Hours and minutes,
giving us

4h 50m (+12 hours)
450 (+12 hours)
4h 50m (+12 hours)
10h 30m
1030

For the rest, we have to *assume* that they've got 2-digits-worth of minutes
(i.e. they put "1:05" or "105" for five after one, not just "15"), so we can
break
it up into the last two (minutes) characters and anything else has to be the
hours,
giving us

4h 50m (+12 hours)
4h 50m (+12 hours)
4h 50m (+12 hours)
10h 30m
10h 30m

Then add in the extra 12 hours for the "pm" bit we spotted earlier, giving
us a
final list of

16:50
16:50
16:50
10:30
10:30

If that manages to kill of 80% of them [:-)] it'll only leave you to sort
out
the other 12,000 [:-{]

HTH,
Phill W.


HotRod

2005-12-15, 6:55 pm

I'll repost the code once I get everything worked out, this may take a
while. Thanks for the suggestions. I plan on using IsTime just to determine
if I need to start formatting bad time.


"Phill W." <p-.a-.w-a-r-d@o-p-e-n.a-c.u-k> wrote in message
news:dnrtpm$dqg$1@yarrow.open.ac.uk...
> "HotRod" <NOSPAM@youremail.com> wrote in message
> news:%23YfEn$1$FHA.3140@TK2MSFTNGP14.phx.gbl...
>
> Don;t let dodgy data in the front door and you won't have to clear it up
> and
> the other end.
> But you've been told that already.
>
> Your 60,000 list problem remains, so let's have a stab at it.
>
> Your list:
>
>
> IsTime won't help, because it uses fairly strict rules, which the above
> don't
> stick to. However, you could apply some preliminary data cleaning, then
> have a stab at making sense of whatcomes out of that, something like
>
> sTime = LCase( (any of the above) )
> sTime = Replace( sTime, " ", "" ) ' trash the spaces
> sTime = Replace( sTime, ".", "" ) ' and the '.'s
> sTime = Replace( sTime, "a", "" ) ' and the "am", "pm" thingies
> sTime = Replace( sTime, "m", "" )
>
> If Instr( sTime, "p" ) > 0 Then
> sTime = Replace( sTime, "p", "" )
> bAdd12Hours = True
> End If
>
> which reduces the above list to
>
> 4:50 (+12 hours)
> 450 (+12 hours)
> 4:50 (+12 hours)
> 10:30
> 1030
>
> Now we can start making guesses about what's left -
>
> If there's a ":" in there, we can split it directly into Hours and
> minutes,
> giving us
>
> 4h 50m (+12 hours)
> 450 (+12 hours)
> 4h 50m (+12 hours)
> 10h 30m
> 1030
>
> For the rest, we have to *assume* that they've got 2-digits-worth of
> minutes
> (i.e. they put "1:05" or "105" for five after one, not just "15"), so we
> can break
> it up into the last two (minutes) characters and anything else has to be
> the hours,
> giving us
>
> 4h 50m (+12 hours)
> 4h 50m (+12 hours)
> 4h 50m (+12 hours)
> 10h 30m
> 10h 30m
>
> Then add in the extra 12 hours for the "pm" bit we spotted earlier, giving
> us a
> final list of
>
> 16:50
> 16:50
> 16:50
> 10:30
> 10:30
>
> If that manages to kill of 80% of them [:-)] it'll only leave you to sort
> out
> the other 12,000 [:-{]
>
> HTH,
> Phill W.
>
>



Bob Butler

2005-12-15, 6:55 pm

"HotRod" <NOSPAM@youremail.com> wrote in message
news:%23NZltCZAGHA.3456@TK2MSFTNGP11.phx.gbl
> I'll repost the code once I get everything worked out, this may take a
> while. Thanks for the suggestions. I plan on using IsTime just to
> determine if I need to start formatting bad time.


IsTime? Do you mean IsDate?

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com