|
-
Nov 27th, 2008, 09:02 AM
#1
Thread Starter
New Member
HH:mm to minutes problem.
-
Nov 27th, 2008, 10:06 AM
#2
Thread Starter
New Member
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?
-
Nov 27th, 2008, 10:11 AM
#3
Thread Starter
New Member
-
Nov 27th, 2008, 10:38 AM
#4
Re: HH:mm to minutes problem.
 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
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Nov 27th, 2008, 10:56 AM
#5
Thread Starter
New Member
Re: HH:mm to minutes problem.
ooOOOoo... thanks CDRIVE!
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?
 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
-
Nov 27th, 2008, 11:04 AM
#6
Re: HH:mm to minutes problem.
 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.
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Nov 27th, 2008, 11:10 AM
#7
-
Nov 27th, 2008, 11:32 AM
#8
Re: HH:mm to minutes problem.
 Originally Posted by mrfikri
ooOOOoo... thanks CDRIVE!
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? 
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
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Nov 27th, 2008, 01:06 PM
#9
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.
-
Nov 29th, 2008, 05:51 AM
#10
Member
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
-
Nov 29th, 2008, 06:20 AM
#11
Thread Starter
New Member
Re: HH:mm to minutes problem.
-
Nov 30th, 2008, 06:58 AM
#12
Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|