PDA

View Full Version : Solved: time change



pingupingu
04-06-2007, 05:44 AM
hey people,

i have been trying to do something with VBA in word. i wanted to prompt the user to write the time in 24 hr format and then convert it and bring up a msg box that showed the time in 12 hr format. i know that there are vba commands that say long time and short time but i don't really know how to code it to work. i looked up some sites breifly but didn't find anything specific. can anyone help???

matthewspatrick
04-06-2007, 06:05 AM
Dim TimeEntry As String

TimeEntry = InputBox("Please enter time in hh:mm")
MsgBox Format(TimeValue(TimeEntry), "h:mm AM/PM")

pingupingu
04-06-2007, 01:19 PM
thanks,

that worked really well, sort of what i was doing but not really. thanks again.

mdmackillop
04-06-2007, 01:56 PM
Hi Pingupingu
Welcome to VBAX.
If this is solved, you can mark it so using the Thread Tools dropdown
Regards
MD

fumei
04-07-2007, 02:04 PM
Is this more of what you were asking about?
Dim TimeEntry As String
Dim msg As String
Dim response
Do Until response = vbYes
TimeEntry = InputBox("Please enter the time in 24 hour format.")
msg = "You have entered " & Format(TimeValue(TimeEntry), "h:mm AM/PM") & _
". Is this correct?"
response = MsgBox(msg, vbYesNo)
Loop
MsgBox Format(TimeValue(TimeEntry), "h:mm AM/PM")It will keep asking for the time entry until the user clicks Yes, it is correct.

I am wondering. Are you aware of the default interpretation VBA does for time values?

Entering 1.8 in the input box returns 1:08 AM. You do NOT have to use an actual semi-colon. A dot (.) will do, AND VBA interprets single digits after a . to mean there is a 0 before that digit.

Hence 1.8 = 1.08 = 1:08 = 1:08 AM
13.7 = 13.07 = 13:07 = 1:07 PM

mdmackillop
04-07-2007, 02:39 PM
but they don't like 24:00 or 24.0 etc.

fumei
04-08-2007, 01:48 AM
For good reason. There IS no 24:00 or 24.0. There is 23.59...then 0:00.

mdmackillop
04-08-2007, 03:37 AM
For good reason. There IS no 24:00 or 24.0. There is 23.59...then 0:00.
That's just a technological foible. In the real world it is used and understood, and even our PCs require it to be used.

In Excel, format Cols A & B to hh:mm
A1 = 09:00
B1 = 00:00
B1 - A1 = #############

A1 = 09:00
B1 = 24:00 (which changes to 00:00)
B1 - A1 = 15:00

Three questions
How many hours between 09:00 and 06:00?
How many hours between 09:00 and 24:00?
How many hours between 09:00 and 0:00?

fumei
04-08-2007, 10:47 PM
In Excel, format Cols A & B to hh:mm
A1 = 09:00
B1 = 00:00
B1 - A1 = #############

A1 = 09:00
B1 = 24:00 (which changes to 00:00)
B1 - A1 = 15:00

Sorry, I am not an Excel person at all.

Are you saying that if you have a formula B1 - A1, and keeping A1 constant at 09:00, if you enter 00:00 into B1 you get an error? But entering 24:00 you do not?

How many hours between 09:00 and 06:00? 3 (or 21 if your date format includes days, and the 06:00 is for the next one....<grin>)
How many hours between 09:00 and 24:00? 15
How many hours between 09:00 and 0:00? 15

mdmackillop
04-09-2007, 01:35 AM
Are you saying that if you have a formula B1 - A1, and keeping A1 constant at 09:00, if you enter 00:00 into B1 you get an error? But entering 24:00 you do not? Correct

How many hours between 09:00 and 06:00? 3 (or 21 if your date format includes days, and the 06:00 is for the next one....<grin>)
How many hours between 09:00 and 24:00? 15
How many hours between 09:00 and 0:00? 15 or maybe 9?

fumei
04-10-2007, 01:21 AM
How many hours between 09:00 and 0:00? 15 or maybe 9?

Uh....right. Dumb me.