[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Easy - Time TextBox

Posted on 2004-09-27
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 55

Assisted Solution

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

Accepted Solution

Mike Tomlinson earned 120 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

650 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