Easy - Time TextBox

Posted on 2004-09-27
Last Modified: 2010-05-02
Anyone know where I might find a TextBox for time, where it seperates hours, minutes and seconds, and you can change any set with the little up/down buttons. I've looked through some of the included VB6 components, but could not find anything. If you don't know what I'm talking about, open you system clock... the box that you edit the system's time... that's what I'm looking for!
Question by:RunBoris
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 20 total points
ID: 12162063
There is a stardard ActiveX control called DateTimePicker. Must be there...
LVL 85

Accepted Solution

Mike Tomlinson earned 30 total points
ID: 12162083
Hi RunBoris,

Click on Project --> Components and place a check next to "Microsoft Windows Common Controls-2 6.0" and click "OK".  Some components will be added to your toolbox.  One of them is the DateTimePicker jaime_olivares refers to.  When you hover over it, the tooltip says "DTPicker".

Drag one onto your form and set the Format property to 2 (dtpTime).



Expert Comment

ID: 12162941
Why not roll your own? You will not need to worry about adding files to your program, or copyright, or anything like that? That is what I do. Here is a simple form that does what you want. It has a label that displays the time (set by a Timer control once per second), six buttons that allow you to set the hour, minute and second up or down, and a text box and "Set" button to allow yo to set the time bu inputting it as text. Much more fun this way, and you have total control over look and feel and such. Here is the code, written in VB 4, which is upward compatible with VB 6. If you need it, I can email you the form itself.

Begin VB.Form TimeSet
   Caption         =   "Time Setter"
   ClientHeight    =   2520
   ClientLeft      =   2790
   ClientTop       =   2100
   ClientWidth     =   3345
   Height          =   2925
   Left            =   2730
   LinkTopic       =   "Form1"
   ScaleHeight     =   2520
   ScaleWidth      =   3345
   Top             =   1755
   Width           =   3465
   Begin VB.CommandButton cmdSetTimeFromText
      Caption         =   "Set"
      Height          =   375
      Left            =   1680
      TabIndex        =   8
      Top             =   480
      Width           =   975
   Begin VB.TextBox Text1
      Height          =   375
      Left            =   120
      TabIndex        =   7
      Top             =   480
      Width           =   1335
   Begin VB.CommandButton cmdDownOneSecond
      Caption         =   "vSecond"
      Height          =   495
      Left            =   2160
      TabIndex        =   6
      Top             =   1680
      Width           =   975
   Begin VB.CommandButton cmdUpOneSecond
      Caption         =   "^Second"
      Height          =   495
      Left            =   2160
      TabIndex        =   5
      Top             =   1080
      Width           =   975
   Begin VB.CommandButton cmdDownOneMinute
      Caption         =   "vMinute"
      Height          =   495
      Left            =   1200
      TabIndex        =   4
      Top             =   1680
      Width           =   735
   Begin VB.CommandButton cmdUpOneMinute
      Caption         =   "^ Minute"
      Height          =   495
      Left            =   1200
      TabIndex        =   3
      Top             =   1080
      Width           =   735
   Begin VB.CommandButton cmdDownOneHour
      Caption         =   "v Hour"
      Height          =   495
      Left            =   240
      TabIndex        =   2
      Top             =   1680
      Width           =   735
   Begin VB.CommandButton cmdUpOneHour
      Caption         =   "^Hour"
      Height          =   495
      Left            =   240
      TabIndex        =   1
      Top             =   1080
      Width           =   735
   Begin VB.Timer Timer1
      Interval        =   100
      Left            =   2640
      Top             =   0
   Begin VB.Label Label1
      Caption         =   "Label1"
      Height          =   255
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   2175
Attribute VB_Name = "TimeSet"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit

Private Sub cmdDownOneHour_Click()

'Set time back one hour
Time = Time - 1 / 24

End Sub

Private Sub cmdDownOneMinute_Click()

'Set time back one minute
Time = Time - 1 / 24 / 60

End Sub

Private Sub cmdDownOneSecond_Click()

'Set time back one second
Time = Time - 1 / 24 / 60 / 60

End Sub

Private Sub cmdSetTimeFromText_Click()

' Protect against invalid time
On Error Resume Next

'Set time from text box
Time = TimeValue(Text1.Text)
If Err Then Err.Clear

End Sub

Private Sub cmdUpOneHour_Click()

'Advance time one hour
Time = Time + 1 / 24

End Sub

Private Sub cmdUpOneMinute_Click()

'Advance time one minute
Time = Time + 1 / 24 / 60

End Sub

Private Sub cmdUpOneSecond_Click()

'Advance time one second
Time = Time + 1 / 24 / 60 / 60

End Sub

Private Sub Timer1_Timer()

Label1 = Format$(Time, "HH:MM:SS A/P")

End Sub


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now