Link to home
Start Free TrialLog in
Avatar of RunBoris
RunBoris

asked on

Easy - Time TextBox

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!
SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Leithauser
Leithauser

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