|
||||||||
|
|
![]() |
|
|
|
|
||
|
Save Those Keystrokes! Hey, Ted: If I had to use some of the software I've written, I'd hunt myself down and shoot myself between the eyes with a .38 Special. I'm ashamed to say that some of the trash I've written was as user-unfriendly as the vending machines at the local post office. But I've learned a few things along the way, like the need to look for ways to reduce the number of keystrokes required to fill in a screen. I thought your readers might like to have this routine, which reduces the number of keystrokes needed to key dates. My routine, FILLDATE, accepts a 6-byte character value that is supposed to contain all or part of a date. It makes some assumptions about the keyed data and, if possible, reformats the date into MMDDYY format. If the incoming date has only two digits, FILLDATE assumes they stand for month and day and that the year is the current year. A value of 13 means January 3 of the current year. Three digits are assumed to mean a one-digit month and a two-digit day. See the comments in the program for the other assumptions. One other thing I do to help users is to strip off leading blanks. Users usually key the partial dates left-adjusted, but if they accidentally get a space or two on the front, it's no big deal. After applying the assumptions to the incoming date, FILLDATE tests the resulting date to make sure it's valid. If the date is valid, FILLDATE returns the filled-out date in the second parameter and sets the return code to zero. If the date is not valid, the return code is set to 1 and the output date is unchanged. This works well from prompt screens in CL programs. I pass an indicator to the return code parameter. Then I use the indicator to condition field attributes and display error messages. FILLDATE remains active when you call it to complete a date. A calling program should call FILLDATE one last time, with no parameters, to shut it down. Interested parties may prefer to implement this routine as an ILE module. I know from experience that this technique is a time-saver, as I take advantage of the ability to key partial dates when I'm testing. --Cletus the Codeslinger Dear Readers: Cletus the Codeslinger sent me some tips for publication under the condition that I not reveal anything that might help to identify him, such as his real name, age, where he lives, underwear size, or beverage of choice. Look for more tips from Cletus in upcoming issues of Midrange Guru. --Ted
* FILLDATE -- Fill a partial date.
*
* Parameters:
* iDate Input 6 char
* blank -- invalid
* 1 digit -- invalid
* 2 digits -- assume MD
* 3 digits -- assume MDD
* 4 digits -- assume MMDD
* 5 digits -- assume MDDYY
* 6 digits -- assume MMDDYY
* oDate Output 6 char
* MMDDYY format
* oRtnCode Output 1 char
* 0=valid date, 1=invalid date
D FillDate PR ExtPgm('FILLDATE')
D iDate 6a Const
D oDate 6a
D oRtnCode 1a
D FillDate PI
D iDate 6a Const
D oDate 6a
D oRtnCode 1a
D Valid C Const('0')
D Invalid C Const('1')
D wDate S 6a
D wDateLen S 10i 0
D wCurrYear S 2a
/Free
// If fewer than 3 parameters passed, shut down.
If %Parms < 3;
*INLR = *ON;
Return;
Endif;
// Assume the input date is invalid.
oRtnCode = Invalid;
// Strip off leading blanks.
wDate = %TrimL(iDate);
wDateLen = %Len(%Trim(wDate));
wCurrYear = %EditC(UYear:'X');
// Fill the date with the missing part(s).
Select;
When wDateLen <= 1;
Return;
When wDateLen = 2;
wDate = '0' + %SubSt(wDate:1:1)
+ '0' + %SubSt(wDate:2:1)
+ wCurrYear;
When wDateLen = 3;
wDate = '0' + %SubSt(wDate:1:1)
+ %SubSt(wDate:2:2)
+ wCurrYear;
When wDateLen = 4;
wDate = %SubSt(wDate:1:2)
+ %SubSt(wDate:3:2)
+ wCurrYear;
When wDateLen = 5;
wDate = '0' + %SubSt(wDate:1:1)
+ %SubSt(wDate:2:2)
+ %SubSt(wDate:4:2);
EndSl;
// Make sure the date is valid.
Test(DE) *MDY0 wDate;
If %Error;
Return;
Endif;
// If the date is valid, update the output parameters.
oDate = wDate;
oRtnCode = Valid;
Return;
/End-free
Editors: Howard Arner, Joe Hertvik, Ted Holt, David Morris,
Managing Editor: Shannon Pastore
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message. |
|
| Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |