Solved

Easy - Time TextBox

Posted on 2004-09-27
3
393 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

757 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

21 Experts available now in Live!

Get 1:1 Help Now