Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to input date and time quickly

Posted on 2000-03-29
13
Medium Priority
?
672 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
ID: 2668163
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
ID: 2668635
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
ID: 2669143
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Expert Comment

by:TheMask
ID: 2669471
TheMask changed the proposed answer to a comment
0
 
LVL 4

Expert Comment

by:PBuck
ID: 2669765
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
ID: 2670258
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
 
LVL 4

Expert Comment

by:PBuck
ID: 2670407
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
ID: 2670492
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
ID: 2670556
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
ID: 2670602
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
ID: 2671668
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 200 total points
ID: 2671960
Oops, sorry. The DTPicker is in Microsoft Windows Common Controls-2 6.0


0
 

Author Comment

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 …
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

971 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