1 Attachment(s)
HH:mm to minutes problem.
Hi,
I am working on an assignment given by my lecturer. She wanted us to develope a 'Parking System'. I've no problem with the system. The only problem I have is to convert HH:mm to minutes.
You can look at my attachment. That's how my system looks like. I have coded it. I need you to help me, to convert HH:mm to minutes because I need it in minutes to do the bill's calculation.
This is my code:
Code:
Private Sub Command1_Click()
Text1.Text = Format(Time$, "HH:mm")
timeIn = Text1.Text
Command1.Enabled = False
Command2.Enabled = True
End Sub
------------------------------------------------
Private Sub Command2_Click()
Text2.Text = Format(Time$, "HH:mm")
totalTime = TimeValue(Text2.Text) - TimeValue(Text1.Text)
Picture1.Cls
Picture1.Print Format(totalTime, "HH:mm")
Command2.Enabled = False
Command1.Enabled = True
End Sub
------------------------------------------------
Private Sub Form_Load()
Command2.Enabled = False
End Sub
On the same time, I also need someone to explain to me, what is actually 'Time$' written in the code for? I got the code to set HH:mm from a few websites but I have no idea the use of 'Time$'. I hope, you don't mind to help me on this. :) I'm waiting for responses.
Re: HH:mm to minutes problem.
anyone? i don't know wether this question is too easy or what... but to let you know, i did search on this but i couldn't found any. There are source codes which are similar to my problem but i found that those source codes couldn't be used as the solution. There are not converting on the way I want but on other side.... PLUS I want to know what actually 'Time$' use to be. Is it an instant declaration for a variable or maybe is it a code for timer? :)
Re: HH:mm to minutes problem.
wait! wait! wait!
never mind guys... i think, i found one :D
at last, i found codes which are similar to this. It is in this forum too. :D
for anyone who are facing the same problem, look at http://www.vbforums.com/showthread.php?t=540890 .
Thanks ;)
Re: HH:mm to minutes problem.
Quote:
Originally Posted by mrfikri
anyone? i don't know wether this question is too easy or what... but to let you know, i did search on this but i couldn't found any. There are source codes which are similar to my problem but i found that those source codes couldn't be used as the solution. There are not converting on the way I want but on other side.... PLUS I want to know what actually 'Time$' use to be. Is it an instant declaration for a variable or maybe is it a code for timer? :)
The Time Statement returns the current time as a Variant Date. The '$' is another way of declaring a variable as String. I would think be adding the dollar sign ($) as Time$ you would be telling VB to format Time as a String but I don't know why you would want to do that. Possibly so you can easily work with it as a String with any further code. Guessing??
Code:
Debug.Print TypeName(Time$) ' return data type
Re: HH:mm to minutes problem.
ooOOOoo... thanks CDRIVE! :D
I copied the code somewhere from the internet. I'm afraid it will not going to work if i remove 'Time$', that's why i still use it. Thanks for your explaination. i really appreciate that. ;)
ps: the way it's declared was like in PHP, huh? :D
Quote:
Originally Posted by CDRIVE
The Time Statement returns the current time as a Variant Date. The '$' is another way of declaring a variable as String. I would think be adding the dollar sign ($) as Time$ you would be telling VB to format Time as a String but I don't know why you would want to do that. Possibly so you can easily work with it as a String with any further code. Guessing??
Code:
Debug.Print TypeName(Time$) ' return data type
Re: HH:mm to minutes problem.
Quote:
Originally Posted by mrfikri
Hi,
I am working on an assignment given by my lecturer. She wanted us to develope a 'Parking System'. I've no problem with the system. The only problem I have is to convert HH:mm to minutes.
Actually, I didn't find anything wrong here. The code ran with no errors. I hope you weren't trying to enter data into Text1 & Text2, as this code doesn't take user input except for your two CommandButtons. Your TextBoxes are used for display output not input.
Re: HH:mm to minutes problem.
I forgot to mention that your code will work with or without the '$' String designator. The only difference will be that the data displayed in Picture1 will be a Variant Date instead of a String. ;)
EDIT: Misspeak... It will be a Double regardless!:eek:
Re: HH:mm to minutes problem.
Quote:
Originally Posted by mrfikri
ooOOOoo... thanks CDRIVE! :D
I copied the code somewhere from the internet. I'm afraid it will not going to work if i remove 'Time$', that's why i still use it. Thanks for your explaination. i really appreciate that. ;)
ps: the way it's declared was like in PHP, huh? :D
Actually, at second glance, I don't see the purpose of '$' because 'totaltime' will return a Double with it or without it. Try it! I really don't think '$' should be used here. BTW, I know the Type designator dates back to at least Quick Basic.
Code:
Option Explicit
Dim timein
Dim totaltime
'Dim Time$
Private Sub Command1_Click()
Text1.Text = Format(Time, "HH:mm") ' no $. Try it both ways
timein = Text1.Text
Command1.Enabled = False
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
Text2.Text = Format(Time, "HH:mm") ' no $. Try it both ways
totaltime = TimeValue(Text2.Text) - TimeValue(Text1.Text)
Picture1.Cls
Picture1.Print Format(totaltime, "HH:mm")
Debug.Print TypeName(totaltime) ' return data type
Command2.Enabled = False
Command1.Enabled = True
End Sub
Private Sub Form_Load()
Command2.Enabled = False
End Sub
Re: HH:mm to minutes problem.
Just to tell the shortest way to tell the minutes from a Date containing only the time:
Code:
Private Sub Command1_Click()
Dim dtmTime As Date
' using a variable just to explicitly show we are indeed using Date data type
dtmTime = Time
' 1440 = 24 * 60 = hours in a day * minutes in an hour
MsgBox (dtmTime * 1440#)
End Sub
This can be done because time is represented as fractions of a day: 0 <= TIME < 1
Each time you increment a date by one you jump to the next day.
Re: HH:mm to minutes problem.
Just a thought or two about the basic requirement of the program. Are the calculations being based on a 24 hour clock or 12 hour clock.
Consider parking at 11:00 am on the 29 th day and leaving at 1:00 pm (13:00) on the 29 th day; this is 2 hours parking. Now consider parking at 11:00 am on the 29 th day and leaving at 1:00 am on the 30 th day; this is 14 hours parking.
As I suggest, this is not a criticism but a thought for the fullness of the program such that the date may also be considered in the program
Re: HH:mm to minutes problem.
before that, thanks guys for your replies. :) actually, i finished writing the codes and there is no bug. :D
you're saying the true... luckily, the system will end at 2100H because the lot gonna be closed. But, i want to learn more on the solution of the problem you said. if you've any idea to solve it, please post it here while i'll think of an answer for that. ;)
thanks yeah! :D
Quote:
Originally Posted by Tony Aston
Just a thought or two about the basic requirement of the program. Are the calculations being based on a 24 hour clock or 12 hour clock.
Consider parking at 11:00 am on the 29 th day and leaving at 1:00 pm (13:00) on the 29 th day; this is 2 hours parking. Now consider parking at 11:00 am on the 29 th day and leaving at 1:00 am on the 30 th day; this is 14 hours parking.
As I suggest, this is not a criticism but a thought for the fullness of the program such that the date may also be considered in the program
Re: HH:mm to minutes problem.
See Date in the help file.
Use Date instead of and as well as Time
Format(Now, "ddddd ttttt")
You have done the work already with Time and it should be easy to convert this to the Date facility