Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DTPicker , time interval to 5 minutes 2

Status
Not open for further replies.

jshanoo

Programmer
Apr 2, 2002
287
IN
Hi all,
I have DTpicker control, i want to set the minutes interval to 5 minutes,
format will be like HH:mm, no seconds is dsiplayed there.
can any one please help me in this

Best regards
JOhn Philip

*** Even the Best, did the Bad and Made the Best ***

John Philip
 
jshanoo,

Put timer control on the form and copy the code below:

Option Explicit

Private Sub Form_Load()
DTPicker1.Format = dtpCustom
DTPicker1.CustomFormat = "hh:mm"
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
Dim intMinute As Integer

intMinute = CInt(Left(Right(CStr(Time), 8), 2))

If intMinute Mod 5 = 0 Then
DTPicker1.Minute = CInt(Left(Right(CStr(Time), 8), 2))
DTPicker1.Refresh
End If

End Sub

Good luck,

vladk
 
jshanoo,

This version is better. You dont need to set a minute, just read the time again.

Option Explicit

Private Sub Form_Load()
DTPicker1.Format = dtpCustom
DTPicker1.CustomFormat = "hh:mm"
DTPicker1.Value = Time
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
Dim intMinute As Integer

intMinute = CInt(Left(Right(CStr(Time), 8), 2))

If intMinute Mod 5 = 0 Then
DTPicker1.Value = Time
DTPicker1.Refresh
End If

End Sub
 
Hi
I accept your answere.

But the user is selecting the time
so when move up or down arrow for selecting time, it should come in multiple of 5 how to do that?
Regards
John

*** Even the Best, did the Bad and Made the Best ***

John Philip
 
I use 2 textboxes and an UpDown control. Set one textbox as an AutoBuddy to the UpDown. Set the UpDown for minimum -1 and maximum of 289 (number of 5 minute intervals in day + 1 overrun in both directions). Set the second textbox value in the first textbox Change event, and show it as Text1/288, formatted as "hh:nn". Check for rollover and reset Text1 as required. Text1 can be behind Text2, or just set Visible to False.

I rolled this all up into an activex control, as I have used it on several projects.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Hi John,
I have shortage of time, so is there anything whihc can be done with dtpciker control itself.

Regards
John

*** Even the Best, did the Bad and Made the Best ***

John Philip
 
I'm not aware of a way to do it directly with a DTPicker.

With the level of detail that I've given for the other solution, it shouldn't take more than a few minutes to do!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
jshanoo,

This code works well only if the minutes highlited. I dont know how to detect what is highlited: minutes or hours.

Private Sub DTPicker1_Change()

With DTPicker1
If .Minute >= 55 Then
.Minute = 0
Else
.Minute = .Minute + 4
End If
End With

End Sub

Private Sub Form_Load()
DTPicker1.Format = dtpTime
End Sub

Vladk
 

This code works when minutes selected only... but only in one direction: on increase.

Private Sub DTPicker1_Change()
Dim intMinute As Integer

With DTPicker1

If .Minute = 55 Then
.Minute = 0
Else
intMinute = .Minute + 4
If intMinute Mod 5 = 0 Then
If .Minute > 55 Then
.Minute = 0
Else
.Minute = .Minute + 4
End If
End If
End If
End With

vladk
End Sub
 
Try this:

Private Sub DTPicker1_Change()
Dim intMinute As Integer
Static intOldMinute As Integer

With DTPicker1
.Second = 0
If intOldMinute = 0 And .Minute = 59 Then
.Minute = 55
intOldMinute = .Minute
Exit Sub
End If

If intOldMinute < .Minute Then
If .Minute = 55 Then
.Minute = 0
Else
intMinute = .Minute + 4
If intMinute Mod 5 = 0 Then
If .Minute > 55 Then
.Minute = 0
Else
.Minute = .Minute + 4
End If
End If
End If
Else
If .Minute = 55 Then
.Minute = 0
Else
intMinute = .Minute - 4
If intMinute Mod 5 = 0 Then
If .Minute > 55 Then
.Minute = 0
Else
.Minute = .Minute - 4
End If
End If
End If
End If

intOldMinute = .Minute

End With
End Sub

Private Sub Form_Load()
DTPicker1.Format = dtpTime
DTPicker1.Value = Time
End Sub


 
Hi vladk,
wel that was too good, let em try for decrease also, if successful will post back here.

Regards
John


*** Even the Best, did the Bad and Made the Best ***

John Philip
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top