Solved

How to input date and time quickly

Posted on 2000-03-29
13
626 Views
Last Modified: 2008-03-10
VB6, win98

I want to let user input date and
time in textbox,
format is "YYYY-MM-DD HH:MM:SS"
near the textbox, I set a command button,
and let user click on it and pop
up a form to input Date and time
using the Mouse.
I think the setting date and time
in win98 (double click the time at
right and down of the win98) is ok,

Can anybody give me a sample code
about this, let user to input date
and time quickly?

0
Comment
Question by:hxb
  • 4
  • 3
  • 2
  • +2
13 Comments
 
LVL 2

Expert Comment

by:brice123
Comment Utility
Why don't you use the Datetime picker control provided with vb6?

Components -> Microsoft Windows Common Controls-3 6.0 (COMCT332.OCX)
0
 

Expert Comment

by:TheMask
Comment Utility
You can do what you asked for using this code:

'I assumed the user will type the date and time in TextBox Text1
Dim strTime As String
strTime = Format(Text1, "YYYY-MM-DD HH:MM:SS")
0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
TheMask, I think his problem is that he wants to validate the date/time entered before it hits the system.

Myself, for dates I pop the M$Calendar control when the user enters a date field on the screen. Then they can just click on the date and what is returned is automatically both a valid date and correctly formatted.

Assume we have a field called (in this example) ArrestDate. Then there are two event support routines that I need code for:

Private Sub ArrestDate_Click()
'
' Here when operator clicks on the date field.
'
NoFill = True
Me.Hide     'Vanish
DateFinder.Show vbModal     'Show date picker and wait
ArrestDate.Text = Format(DateFinder.When.Value, "dd-mmm-yyyy")    'Get date from picker and format
Me.Show     'Reappear
'
End Sub

Private Sub ArrestDate_KeyPress(KeyAscii As Integer)
'
' Fields are locked to prevent editing...
'
Select Case Chr(KeyAscii)
    Case vbCr, " "       'Treat <Enter> same as click
        Call ArrestDate_Click
        '
End Select
'
End Sub


Now you'll notice a reference to a DateFinder form. This is a plain form with just the M$Calendar control on it. The form is called DateFinder and the calendar control is called When. This is *all* the code on THAT form:

'
' Form to allow selection of dates
' Part of BOND-O application
' Copyright 2000 - Networking Experts, Inc. - All Rights Reserved
' By: Mark M. Lambert on February 28, 2000
'
' V1.0 - 28 Feb 00 - MML - Initial Code
'
Option Explicit

Private Sub Form_Activate()
'
' Default to today when shown
'
When.Value = Date
'
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'
' Ignore clicks in [X]
'
If UnloadMode <> vbFormCode Then Cancel = True
'
End Sub

Private Sub When_Click()
'
' Vanish after selection is made
'
Me.Hide
'
End Sub

So this pops a calendar on the screen as then enter the date field and returns a properly formatted, legitimate date.

Now you could do essentially the same thing with the time or you can have a set of combo boxes, one with hours, one with minutes. Again this prevents the operator from having to key in your format or from entering garbage into the system (30-Feb, etc.) - Not only that, but it looks cool!

M
0
 

Expert Comment

by:TheMask
Comment Utility
TheMask changed the proposed answer to a comment
0
 
LVL 4

Expert Comment

by:PBuck
Comment Utility
I just want to add a suggestion.

If you are using VB5/6, why do you not use the Mask control (MSMASK32.OCX)?  

With this control, you can pre-format the input.  Meaning, place a mask of HH:MM:SS into one, place YY-MM-DD into the other.

The user will get something like so:
__:__:__    __-__-__

After completion (Lostfocus) test it using the Isdate(sTIME) = True and IsDate(sDATE) = true to verify they enter valid time and date formats.

This way the user doesn't have to enter the dash (-) or the colons (:) - they are already present.

Hope this helps!  Good luck
0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
The best that the mask control can do is enter the -'s or /'s or :'s for you. It simply isn't smart enough to make sure the dates/times are valid.

While your suggestion of using isdate is valid, I think that it's conceptually incorrect to allow the operator to make an error and nag instead of just preventing the error to begin with.

If you pop a calendar control or have a list of hours/minutes then it's simply not possible for the operator to enter garbage data. This simplifies your code as you can go ahead assured that the data is clean and you don't have to put error checking in if the errors simply cannot occur. You'll find that user resistence and complaints will be reduced if the system prevents the errors from occurring instead of allowing them to make the error and them complaining to them.

FWIW

M
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:PBuck
Comment Utility
I never mentioned the smarts of the mask control - I mentioned the purpose (it is a formatted container).  People like to have an idea that ohhh time belongs here and date belongs there.  The programmer can have simple and small code to verify valid date and time - if it is invalid, clear the text and set focus to it.  Where is the nag in that?

It is all a matter of opinion.  Some people (like myself) do not like to have a list of 60 items to choose from (your suggestion of time).

I like your idea about the date picker, but I would never have a combo box filled with 24 hours and 60 minutes to choose from.

hxb - Take and combine any of the suggestions here.  
0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
Actually the way I do time is with a slider. You can scroll up and down until the time shows what you want - no 60 item drop down list.

"if it is invalid, clear the text and set focus to it. Where is the nag in that?"

The nag is that you're rejecting the operators input and making them try again until they get it 'right'. If you refuse to accept invalid input initially the operator only enters it once - correctly.

Got a program around here that someone else wrote. Data entry screen with 1/2 dozen or so assorted fields and a [Next] button. [Next] is enabled all the time. If you click on it without any entry it pops an error dialog "You must enter this" and puts you back. So you enter 'this' and try again, it responds "You must enter that' and puts you back. So you enter 'that' and try again and it responds "You must enter something else..." this cycle goes on for about six fields. How much less frustrating it would be if the !@#$%^ [Next] button didn't *enable* until AFTER all the inputs are correct?

Your program should never lie to a user - don't show that some function is available when it's really not. Don't force the user to double/triple enter things until they get it right - guide them, gently, to the correct values. Don't assume that they understand that something is implied.

I spend a *LOT* of time on "human factors" and the difference between the two approaches outlined above is often the difference between a usable and unusable program.

M
0
 
LVL 4

Expert Comment

by:PBuck
Comment Utility
I agree with you fully about nagging the user.  I try my best to never plop a message box upon the screen, if I must send some info (or provide guidence) - I do it within the statusbar or within a label.

But, once again, I feel as a programmer you must know your clients.  Are these kids playing games or are they data entry folks (who would rather use the keyboard anyday over grabbing the mouse)??

Some people don't like to switch back and forth from the keyboard and mouse.  I have spent time dealing with people factors also.

All this web page is for, is to provide solutions to problems.  When it comes to programming, there is usually ten different ways to accomplish the same thing.  I am just giving hxb other suggestion to try - not downplaying anybody's idea.  It is up to hxb to determine the proper solution for his/her users.
0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
Agreed, different strokes for different folx. I don't like to make the user hop back and forth from the mouse to the keyboard either. Slows data entry rates way down, but if you can "click-n-pick" instead of having to manually enter esp. where you're concerned about formatting you should do so.

m
0
 

Author Comment

by:hxb
Comment Utility
Thank for your help.

brice123,
  where is the the Datetime picker control in vb6?

Components -> Microsoft Windows Common Controls-3 6.0 (COMCT332.OCX)  SP3
only one control:  coolbar

what my crital question is  input
date and time quickly,
not the format of the date and time.
The pop up form can return the
date and time, I will check the
date and time, and change to the
correct format.
0
 
LVL 2

Accepted Solution

by:
brice123 earned 50 total points
Comment Utility
Oops, sorry. The DTPicker is in Microsoft Windows Common Controls-2 6.0


0
 

Author Comment

by:hxb
Comment Utility
Thank everybody,
but Brice123  is good.
I have completed the code.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now