Solved

Easy - Time TextBox

Posted on 2004-09-27
3
398 Views
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!
0
Comment
Question by:RunBoris
3 Comments
 
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...
0
 
LVL 85

Accepted Solution

by:
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).

Regards,

Idle_Mind
0
 
LVL 5

Expert Comment

by:Leithauser
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.

VERSION 4.00
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
   End
   Begin VB.TextBox Text1
      Height          =   375
      Left            =   120
      TabIndex        =   7
      Top             =   480
      Width           =   1335
   End
   Begin VB.CommandButton cmdDownOneSecond
      Caption         =   "vSecond"
      Height          =   495
      Left            =   2160
      TabIndex        =   6
      Top             =   1680
      Width           =   975
   End
   Begin VB.CommandButton cmdUpOneSecond
      Caption         =   "^Second"
      Height          =   495
      Left            =   2160
      TabIndex        =   5
      Top             =   1080
      Width           =   975
   End
   Begin VB.CommandButton cmdDownOneMinute
      Caption         =   "vMinute"
      Height          =   495
      Left            =   1200
      TabIndex        =   4
      Top             =   1680
      Width           =   735
   End
   Begin VB.CommandButton cmdUpOneMinute
      Caption         =   "^ Minute"
      Height          =   495
      Left            =   1200
      TabIndex        =   3
      Top             =   1080
      Width           =   735
   End
   Begin VB.CommandButton cmdDownOneHour
      Caption         =   "v Hour"
      Height          =   495
      Left            =   240
      TabIndex        =   2
      Top             =   1680
      Width           =   735
   End
   Begin VB.CommandButton cmdUpOneHour
      Caption         =   "^Hour"
      Height          =   495
      Left            =   240
      TabIndex        =   1
      Top             =   1080
      Width           =   735
   End
   Begin VB.Timer Timer1
      Interval        =   100
      Left            =   2640
      Top             =   0
   End
   Begin VB.Label Label1
      Caption         =   "Label1"
      Height          =   255
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   2175
   End
End
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


0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 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