xasan
asked on
How to read a date in a specified format
I am using Turbo Pascal for DOS ver 7.0
I would like to read a date from user as DD/MMM/YY where DD is the Day and MMM is the first three characters of the month and YY is the year ie 98. As user enters DD I would like to move cursor after the '/' etc. Then I would like to I would like to display how many days since first of Jan that year. Ie. if user enters 12/Feb/98 I would display 43 days of yaer 98 so far.
I wonder if this is possible in Pascal ( I am do VB programming and have some Pascal background). Really I am after some code that can actually do rhis without using assembler
Please if posting code add comments. You can send code to hshhussein@mcmail.com or post it here
Thank you all
I would like to read a date from user as DD/MMM/YY where DD is the Day and MMM is the first three characters of the month and YY is the year ie 98. As user enters DD I would like to move cursor after the '/' etc. Then I would like to I would like to display how many days since first of Jan that year. Ie. if user enters 12/Feb/98 I would display 43 days of yaer 98 so far.
I wonder if this is possible in Pascal ( I am do VB programming and have some Pascal background). Really I am after some code that can actually do rhis without using assembler
Please if posting code add comments. You can send code to hshhussein@mcmail.com or post it here
Thank you all
ASKER
ScrapDog
Thank you very much for the idea and I will attempt it. However, I do not think I will be able to do it. My Pascal is very basic. If you could give me code to do what you said I would be so grateful. Or at least how to read the date date from the user using ReadKey and also validating it
Thanks again - I know I am asking too much, but that is how desperate I am.
Thanks once more
Thank you very much for the idea and I will attempt it. However, I do not think I will be able to do it. My Pascal is very basic. If you could give me code to do what you said I would be so grateful. Or at least how to read the date date from the user using ReadKey and also validating it
Thanks again - I know I am asking too much, but that is how desperate I am.
Thanks once more
Damn, I just wrote a program that would do exactly what you wanted. But my computer crashed, and I forgot to save the damn thing!!!
I will rewrite it but I am not in the mood right now. I will get back to you later.
I will rewrite it but I am not in the mood right now. I will get back to you later.
ASKER
Sorry ScrapDog but I have to let others answer it because I need it urgently.
It is still open to you so please try again
It is still open to you so please try again
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you there?
This is a small routine that I have used in the passed have a look.
Uses Crt;
Var
Date : String;
Mask : String;
Procedure ReadString(X,Y : Byte;Var S : String; MaxLength : Byte);
Var
Ch : Char;
TmpString : String;
WasSlash : Boolean;
Begin
TmpString := '';
GotoXY(X,Y);
Repeat
Repeat
Ch := UpCase(Readkey);
Until (Ch In ['A'..'Z',#13,#8,'0'..'9'] );
WasSlash := False;
If Ch = #8 Then
If TmpString[Length(TmpString )] = '/'
Then Delete(TmpString,Length(Tm pString)-1 ,2)
Else Delete(TmpString,Length(Tm pString),1 );
Case Length(TmpString) Of
0..1 : If Ch In ['0'..'9'] Then
Begin
TmpString := TmpString + Ch;
End;
3..5 : If Ch In ['A'..'Z'] Then
Begin
TmpString := TmpString + Ch;
End;
6..8 : If Ch In ['0'..'9'] Then
Begin
TmpString := TmpString + Ch;
End;
End;
If Length(TmpString) = 2 Then TmpString := TmpString + '/';
If Length(TmpString) = 6 Then TmpString := TmpString + '/';
GotoXY(X,Y);
Write(' ');
GotoXY(X,Y);
Write(TmpString);
Until Ch = #13;
S := TmpString;
End;
Begin
ReadString(1,1,Date,9);
End.
Uses Crt;
Var
Date : String;
Mask : String;
Procedure ReadString(X,Y : Byte;Var S : String; MaxLength : Byte);
Var
Ch : Char;
TmpString : String;
WasSlash : Boolean;
Begin
TmpString := '';
GotoXY(X,Y);
Repeat
Repeat
Ch := UpCase(Readkey);
Until (Ch In ['A'..'Z',#13,#8,'0'..'9']
WasSlash := False;
If Ch = #8 Then
If TmpString[Length(TmpString
Then Delete(TmpString,Length(Tm
Else Delete(TmpString,Length(Tm
Case Length(TmpString) Of
0..1 : If Ch In ['0'..'9'] Then
Begin
TmpString := TmpString + Ch;
End;
3..5 : If Ch In ['A'..'Z'] Then
Begin
TmpString := TmpString + Ch;
End;
6..8 : If Ch In ['0'..'9'] Then
Begin
TmpString := TmpString + Ch;
End;
End;
If Length(TmpString) = 2 Then TmpString := TmpString + '/';
If Length(TmpString) = 6 Then TmpString := TmpString + '/';
GotoXY(X,Y);
Write(' ');
GotoXY(X,Y);
Write(TmpString);
Until Ch = #13;
S := TmpString;
End;
Begin
ReadString(1,1,Date,9);
End.
ASKER
Scrapdog,
Sorry, Christmas shopping is taking all my time. Thanks for the answer, I learned a lot from it and I have actually modified a little to suit me.
Sorry, Christmas shopping is taking all my time. Thanks for the answer, I learned a lot from it and I have actually modified a little to suit me.
ASKER
Bobbyo
Your routine is excellent and I am trying to incorporte it into my program. Thanks. You made it all look aesy!!
Your routine is excellent and I am trying to incorporte it into my program. Thanks. You made it all look aesy!!
To get the julian date, you will first have to determine if the current year is a leap year. Do this by taking the year mod 4. If it is 0, (with the possible exception of the year being 00), it is a leap year.
Make an array (constant) containing the julian date of the begin of each month (i.e. month 1 = 1, month 2 = 32, month 3 = 50, month 4 = 81, etc.). If you call this array montharray, you could calculate the day of the year using this formula
day := montharray[monthnum]+dayof
if leapyear and monthnum>2 then day := day + 1;