By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,986 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,986 IT Pros & Developers. It's quick & easy.

DTPicker-

100+
P: 153
Hi all,

I'm figuring out VB and now onto DTPcker.

I've done quite well in a little experiment to learn how to do calculations - now i'm stumped. I've done a basic form with 2 dtpicker, both with just time (anyone know how to get rid of seconds that'll be great too!) I have a command button and a label. It seems to work fine but if i calculate 19:05:00 - 07:00:00 (through coding obviously) then the answer is the same as 19:50:00 - 07:00:00, They both display 12.5, I want first calculation to display 12.05. I feel like a pain already and I've only just joined this morning but if any one has any quick ideas, thank you Here's code:

Dim time1hour, time2hour, total, time1minute, time2minute As Variant
Dim totalall As Variant



Private Sub Command1_Click()
time1hour = DTPicker1.Hour
time1minute = DTPicker1.Minute
time2hour = DTPicker2.Hour
time2minute = DTPicker2.Minute
total1 = time1hour & "." & time1minute
total2 = time2hour & "." & time2minute
totalall = total2 - total1
Label1.Caption = totalall

End Sub
Nov 30 '07 #1
Share this Question
Share on Google+
4 Replies


P: 55
you could try formating the date

dim dhourminute as string
dhourminute = format(dtpicker1.value, "hh:mm")

this eliminates the seconds in the time

then just convert the string to an int with the cInt(dhourminute)

you could probably format the date to just get the hour and another variable for the minute for ur caculations
Nov 30 '07 #2

100+
P: 153
I can't win!

I just subtracted as in code in first post, everything fine except 12.05 was being displayed as 12.5.

Now I have further researched dtpicker and fond date diff. The code below though is calculating wrong. Try all variable types, it's not that.

for instance: 00:00 and 13.05 is being calculated as 13.0833333, it should be 13.05 shouldn't it? Please help me if you can

Dim time1hour, time2hour, time1minute, time2minute As Variant
Dim total1, total2 As Variant
Dim minutesdiv As Variant
Dim timediff As Variant




Private Sub Command1_Click()
time1hour = DTPicker1.Hour
time1minute = DTPicker1.Minute
time2hour = DTPicker2.Hour
time2minute = DTPicker2.Minute
total1 = time1hour & "." & time1minute
total2 = time2hour & "." & time2minute
timediff = DateDiff("n", total1, total2)
minutesdiv = timediff / 60
Label1.Caption = minutesdiv

End Sub
Nov 30 '07 #3

P: 55
i see, i'll check the calculations and will try to give you a code when i got home :P
Dec 1 '07 #4

100+
P: 153
no worries jaz215

sorted it

thanks
Dec 1 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.