allows a user to input two dates.
• Dates have to be valid
• Both dates have to be greater than the current date (today) and less
than a year from the current date
• The second date has to be greater than the first date
I have done a few smaller practice projects, but I guess I have not
gotten to the chapter that covers what I would GUESS is using the
OCONV tool to convert the dates and then somehow check to make sure
the rules above are enforced. I am hoping that by seeing this code
written out I can use it as a way to learn some of the syntax, and get
a better understanding of how to do something simple like this Like I
said, ANY help would be greatly appreciated!
Here's some code that ought to do what you want.
It is by no means pretty, nor do I post it as an example of good
programming.
However, it should provide what you need, namely code that will enable you
to learn some of the relevant syntax. If nothing else, you have sometihing
with which to start until somebody comes along with something better (which
shouldn't be at all difficult!)
Regards
Mike Wooding
P.S. I haven't worked on a Unidata system so am not familiar with that
variant, but this is pretty much R83 compliant Pick/Basic so I hope it works
for you?
001 CRT @(-1)
002 PROMPT ""
003 * today is today's date in internal format
004 today = date()
005 * nextyear is a year from today (internal format)
006 nextyear = OCONV(today,"dd"):" ":OCONV(today,"dma"):"
":(OCONV(today,"dy")+
1)
007 nextyear = OCONV(nextyear,"DI")
008 * date1 is first date to input
009 valid=0
010 LOOP UNTIL valid DO
011 CRT "Enter First Date: ":
012 date1 = ""
013 INPUT value
014 GOSUB date.valid
015 IF valid THEN date1 = value
016 REPEAT
017 * date2 is second date to input
018 valid=0
019 LOOP UNTIL valid DO
020 CRT "Enter Second Date: ":
021 date2 = ""
022 INPUT value
023 GOSUB date.valid
024 IF valid THEN
025 IF internal.date LE OCONV(date1,"DI") THEN
026 valid=0
027 CRT "Second Date Must be Greater than First Date"
028 END ELSE
029 date2 = value
030 END
031 END
032 REPEAT
033 *
034 STOP
035 ********************************************
036 date.valid: * Internal Sub to Validate Date.
037 * Check Valid Date by Converting to Internal Value
038 internal.date = OCONV(value,"DI")
039 IF internal.date NE "" THEN
040 * Is a valid date
041 IF internal.date GE today THEN
042 IF internal.date LT nextyear THEN
043 valid=1
044 END ELSE
045 CRT "Must be less than 1 year hence"
046 END
047 END ELSE
048 CRT "Must be greater than or equal to today's date
(":OCONV(today,"d"):
")"
049 END
050 END ELSE
051 CRT "Must be a valid date"
052 END
053 RETURN
For general multi-value resources, go to www.pickwiki.com
I would also recommend reading the "Getting Started in OpenQM" books
available from www.rushflat.co.nz While OpenQM is not UniData, it is
close enough that you'll be able to learn a lot.
Cheers,
Brian
This might help just a little bit for starters, while examples and the
U2 documentation will be of more help for your specific assignment,
but you can get a little taste by looking especially at the last two
in the little trilogy of flashcards here
http://tincat-group.com/mv/trilogy.html
Welcome to the MV/PICK community. cheers! --dawn
I would do this
internal.date = ICONV(value,"D")
instead of this
038 internal.date = OCONV(value,"DI")
Hi,
The date thing is a bit complicated because of the ways the date can
be entered.
You may enter Day Month Year, Month Day Year, Year Month Day etc.
Because you have a year worth of dates you may ignore the year
altogether because you know that if the user enters March and now is
September then is March next year for sure.
There is an issue when using numbers only that is:
3-7-2010 is it March 7th or July 3rd ?
If today is February both dates are this year's valid dates.
Therefore you should show the user the required format and validate
it.
For example:
PRINT 'First date [dd/MMM]: ':
GOSUB GET.DATE
IF OK THEN....
....
GET.DATE:
OK = 1
DT = ''
INPUT BUFF
IF BUFF MATCHES '2N"/"3A':@VM:'1N"/"3A' THEN
DT = ICONV(BUFF,'D')
IF DT MATCHES '1N0N' THEN
IF DT < DATE() THEN DT = DT + 365
RETURN
END
END
OK = 0
RETURN
In this example BUFF MATCHES... validates the format.
On my system (it is not Unidata) if successful the date conversion
ICONV(BUFF,'D') creates a number, otherwise leaves DT as is. Next
statement validates DT to be a number of at least 1 digit long "1N" to
as many as required (zero) "0N".
Note that @VM is CHAR(253) and this notation is not supported on all
Multivalue flavors.
Please note that the above validation is incomplete as it does not
work correctly for leap years.
A note about Mike's example:
nextyear = OCONV(today,"dd"):" ":OCONV(today,"dma"):" ":
(OCONV(today,"dy")+1)
does not work if today is February 29th.
Instead use:
nextyear = date() + 365
Genuine question, (bearing all the caveats from my original post in mind),
Why?
Thanks
Regards
Mike
I've only seen the DI used in dict items on certain releases, but
that's just me.
Hey all!
Just wanted to say thanks to all who offered up any help/input! I got
it figured out after several days of reading (both Forums and the PICK/
BASIC books I found :-)
And help from all of you (and others) Thanks again!
* Dates have to be valid
* Both dates have to be greater than the current date and less than
a year from the current date
* The second date has to be greater than the first date
CS=@(-1) ; * CLEAR SCREEN
CLLN=@(-4); * CLEAR LINE
CRT CS
PROMPT ':'
DATE.OK=1
LOOP
CRT @(5,5):CLLN:'ENTER DATE 1 ':
INPUT DATE1
DATE1=UPCASE(DATE1)
IF DATE1='X' OR DATE1='' THEN GO 999
DATE1 = ICONV(DATE1,'D')
* IF DATE1 > DATE() THEN
* IF DATE1 < (DATE() + 365) THEN DATE.OK=0
* END
UNTIL (DATE1 > DATE()) AND (DATE1 < (DATE() + 365)) DO
CALL NT.ERRORS('INVALID! MUST BE GREATER THAN THE CURRENT')
REPEAT
CRT 'DATE OK'
LOOP
CRT 'ENTER DATE 2 ':
INPUT DATE2
IF DATE2='X' OR DATE2='' THEN GO 999
DATE2 = ICONV(DATE2,'D')
IF DATE2 > DATE() THEN
IF DATE2 < (DATE() + 365) THEN
IF DATE2 > DATE1 THEN EXIT
END
END
CRT 'INVALID! THIS DATE MUST BE GREATER THAN THE FIRST DATE
ENTERED'
REPEAT
999 END
Cheers