Recent

Author Topic: Want to see something funny?  (Read 1870 times)

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Want to see something funny?
« on: January 24, 2023, 10:07:52 pm »
Yes, I say funny, though it's not funny at all!  It's really Bull$#!t!!

Just look at the line where the problem is!   WHAT??

I ask the system for the time, turn it into a string, and write it back as a TDate.
Simple, right?   No!!
I should see the 4.4!@#$%^&* e+004 Crap, Right?   Sys don't think so!!


How does the darn system give me the Wrong Format??

PS:  I included the Assembler window in case that means anything to Y'all.  To me it's just gibberish.
« Last Edit: January 24, 2023, 10:12:42 pm by OC DelGuy »
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2056
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Want to see something funny?
« Reply #1 on: January 24, 2023, 10:12:57 pm »
How does the darn system give me the Wrong Format??
How about you show your used code instead of what the debugger show. That might be funnier than asking the glass sphere  8-)
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #2 on: January 24, 2023, 10:14:39 pm »
I don't get it Zwerg??  Isn't that the whole right side of the pic?
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #3 on: January 24, 2023, 10:19:34 pm »
Oh, there's no hidden code that does anything with the date formats.  It's all there.  All the other stuff isn't used.
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2056
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Want to see something funny?
« Reply #4 on: January 24, 2023, 10:22:24 pm »
This is what your picture shows me. Only parts...
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #5 on: January 24, 2023, 10:25:03 pm »
This what you're looking for?:

Code: Pascal  [Select][+][-]
  1. program Consoleprog;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   crt, sysutils
  7.   { you can add units after this };
  8.  
  9. Type
  10.   Tperson = Record
  11.     Fname, Lname    : String;
  12.     Age, Billet     : Integer;  //Billet is their room and bed.
  13.     Gender          : Char;
  14.     InDate, OutDate : TDate;    //Date they sign in and out.
  15.     InTime, OutTime : TTime;    //Time they sign in and out.
  16.   end;
  17.  
  18. var
  19.   GResident : array[1..300] of Tperson;
  20.   Recs, Recds : Integer;
  21.  
  22. procedure OutputFile;
  23.   var
  24.      Filename: Textfile;
  25.      Recds    : Integer;
  26.   Begin
  27.     assignfile(Filename, 'TextFile.txt');
  28.     try
  29.       rewrite(Filename);
  30.       for Recds:= 1 to Recs Do
  31.       Begin
  32.       WriteLn(Filename, GResident[recds].Fname);
  33.       WriteLn(Filename, GResident[recds].Lname);
  34.       WriteLn(Filename, GResident[recds].Age);
  35.       WriteLn(Filename, GResident[recds].Billet);
  36.       WriteLn(Filename, GResident[recds].Gender);
  37.       WriteLn(Filename, GResident[recds].InDate);
  38.       WriteLn(Filename, GResident[recds].InTime);
  39.       WriteLn(Filename, GResident[recds].OutDate);
  40.       WriteLn(Filename, GResident[recds].OutTime);
  41.       ReadLn(GResident[recds].Fname);
  42.       ReadLn(GResident[recds].Lname);
  43.       ReadLn(GResident[recds].Age);
  44.       ReadLn(GResident[recds].Billet);
  45.       ReadLn(GResident[recds].Gender);
  46.       ReadLn(GResident[recds].InDate);
  47.       ReadLn(GResident[recds].InTime);
  48.       ReadLn(GResident[recds].OutDate);
  49.       ReadLn(GResident[recds].OutTime);
  50.       end;
  51.       close(Filename);
  52.     except
  53.       WriteLn('File Error - Please Check Your File');
  54.     end;
  55.   end;
  56.  
  57. procedure InputFile;
  58.   Var
  59.     Filename: Textfile;
  60.     Recds    : Integer;
  61.  
  62.   Begin
  63.     assignfile(Filename, 'TextFile.txt');
  64.     Recds:=1;
  65.     try
  66.       reset(Filename);
  67.       while not eof(Filename) do
  68.         begin
  69.           ReadLn(Filename, GResident[recds].Fname);
  70.           ReadLn(Filename, GResident[recds].Lname);
  71.           ReadLn(Filename, GResident[recds].Age);
  72.           ReadLn(Filename, GResident[recds].Billet);
  73.           ReadLn(Filename, GResident[recds].Gender);
  74.           ReadLn(Filename, GResident[recds].InDate);
  75.           ReadLn(Filename, GResident[recds].InTime);
  76.           ReadLn(Filename, GResident[recds].OutDate);
  77.           ReadLn(Filename, GResident[recds].OutTime);
  78.           WriteLn(GResident[recds].Fname);
  79.           WriteLn(GResident[recds].Lname);
  80.           WriteLn(GResident[recds].Age);
  81.           WriteLn(GResident[recds].Billet);
  82.           WriteLn(GResident[recds].Gender);
  83.           WriteLn(GResident[recds].InDate);
  84.           WriteLn(GResident[recds].InTime);
  85.           WriteLn(GResident[recds].OutDate);
  86.           WriteLn(GResident[recds].OutTime);
  87.           Recds:=Recds+1;
  88.         end; {while}
  89.       Recs:=Recds;
  90.       close(Filename);
  91.     except
  92.       WriteLn('File Error - Please Check Your File');
  93.     end; {try}
  94.  
  95.  
  96.   end; {proc InputFile}
  97.  
  98. Procedure MakeNewfile;
  99.   Begin
  100.     GResident[1].Fname  :='Taylor';
  101.     GResident[1].Lname  :='Swift';
  102.     GResident[1].Age    :=33;
  103.     GResident[1].Billet :=1989;
  104.     GResident[1].Gender :='F';
  105.     GResident[1].InTime :=StrToDateTime('13:30:34'); // This is here to show that
  106.                                                      // there's no problem with time.
  107.     GResident[1].InDate :=Now;
  108.     WriteLn(now);              // This works.
  109.     WriteLn('This is Now:    ', datetostr(now)); // This does too.
  110.     WriteLn('This is Nothing');    // Nothing wrong here.
  111.     WriteLn('Now This is Now:', StrToDate(datetostr(now)));    // What??
  112.     WriteLn('This is also Nothing');      // This is here to show that the
  113.                                           // problem occured before this line.
  114.     GResident[1].InDate :=StrToDateTime('24-Jan-23');
  115.  
  116.     GResident[1].OutDate:=StrToDateTime('2/17/22');
  117.     GResident[1].OutTime:=StrToDateTime('15:50');
  118.  
  119.     GResident[2].Fname  :='Scarlett';
  120.     GResident[2].Lname  :='Johansson';
  121.     GResident[2].Age    :=38;
  122.     GResident[2].Billet :=1984;
  123.     GResident[2].Gender :='F';
  124.     GResident[2].InDate :=StrToDateTime('11/22/1984');
  125.     GResident[2].InTime :=StrToDateTime('13:30');
  126.     GResident[2].OutDate:=StrToDateTime('2/17/22');
  127.     GResident[2].OutTime:=StrToDateTime('15:50');
  128.  
  129.     GResident[3].Fname  :='Gal';
  130.     GResident[3].Lname  :='Gadot';
  131.     GResident[3].Age    :=37;
  132.     GResident[3].Billet :=1985;
  133.     GResident[3].Gender :='F';
  134.     GResident[3].InDate :=StrToDateTime('4/30/1985');
  135.     GResident[3].InTime :=StrToDateTime('13:30');
  136.     GResident[3].OutDate:=StrToDateTime('2/17/22');
  137.     GResident[3].OutTime:=StrToDateTime('15:50');
  138.  
  139.     {Recs :=3;
  140.     For recds:= 1 to Recs do
  141.     Begin
  142.       WriteLn(GResident[Recds].Fname,' ',GResident[Recds].Lname);
  143.       WriteLn(GResident[Recds].Age,'  ', GResident[Recds].Billet);
  144.       WriteLn(GResident[Recds].Gender);
  145.       WriteLn('This is InDate:  ',FormatDateTime('dd mmm yy',GResident[Recds].InDate));
  146.       WriteLn('This is InTime:  ',FormatDateTime('hh:nn',GResident[Recds].InTime));
  147.       WriteLn('This is OutDate: ',FormatDateTime('dd mmm yy',GResident[Recds].OutDate));
  148.       WriteLn('This is OutTime: ',FormatDateTime('hh:nn',GResident[Recds].OutTime));
  149.       WriteLn;
  150.     end;
  151.      }
  152.   end; {proc MakeNewfile}
  153.  
  154. begin
  155.  
  156.  
  157.  
  158.   MakeNewfile;
  159.   WriteLn('Press <Enter> To Quit');
  160.   ReadLn;
  161. end.
  162.  
  163.  
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9864
  • Debugger - SynEdit - and more
    • wiki
Re: Want to see something funny?
« Reply #6 on: January 24, 2023, 10:25:47 pm »
It is a bit inconvenient, that I cant copy and paste text from an image....

I guess you mean
Code: Pascal  [Select][+][-]
  1. writeln(now);
  2. writeln(DateToStr(now));
  3. writeln(StrToDate(DateToStr(now)));  // this does not work ???
  4.  

In what way does it not work? Does it give an error message, stop in the debugger?

---------
Btw on my PC it works, but I have diff locale settings from you it seems.

Code: Text  [Select][+][-]
  1.  4.4950931732893521E+004
  2. 24/01/2023
  3.  4.4950000000000000E+004

I don't know about the "-" as date separator. I would guess it is set somewhere in your OS locale settings.



OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #7 on: January 24, 2023, 10:28:07 pm »
Zwerg, There's ALOT more to the pic than that!!  I took a screenshot of the entire screen!
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #8 on: January 24, 2023, 10:31:24 pm »
It is a bit inconvenient, that I cant copy and paste text from an image....

I guess you mean
Code: Pascal  [Select][+][-]
  1. writeln(now);
  2. writeln(DateToStr(now));
  3. writeln(StrToDate(DateToStr(now)));  // this does not work ???
  4.  

In what way does it not work? Does it give an error message, stop in the debugger?

---------
Btw on my PC it works, but I have diff locale settings from you it seems.

Code: Text  [Select][+][-]
  1.  4.4950931732893521E+004
  2. 24/01/2023
  3.  4.4950000000000000E+004

I don't know about the "-" as date separator. I would guess it is set somewhere in your OS locale settings.

Yes, The first pic is what I mean.
How can it work for you?
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2056
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Want to see something funny?
« Reply #9 on: January 24, 2023, 10:33:11 pm »
I havent tried yet but the first thing I would do is to remove unit "crt" from "uses".
Since you use Windows, I suggest you also put this line somewhere at top of your code like
Code: Pascal  [Select][+][-]
  1. program Consoleprog;
  2. {$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF}

I investigate later what you do there  :D
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #10 on: January 24, 2023, 10:41:09 pm »
Really?  You can't see the screenshot in the OP?
I guess that doesn't work on my computer also!
I have a brand new MSI Katana GF76 11UD
I7 Intel processor
It's not like I'm on a piece of crap trying to play with the big boys!
But, even if the computer was a piece of crap, then the function should work on the same line of code, on the same computer!

I'm really not getting this!
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9864
  • Debugger - SynEdit - and more
    • wiki
Re: Want to see something funny?
« Reply #11 on: January 24, 2023, 10:41:27 pm »
Yes, The first pic is what I mean.
How can it work for you?

Different date separator. Your PC uses -  and mine use /

So I guess there is an issues parsing dates that have - as separator.
But I have not tested that.

Neither have I investigated, if that should work or not. (Though it seems that if it uses it for printing, one might expect it should).

Anyway for now: Good night.


---EDIT

It may also be because I get a 4 digit year, and you only get a 2 digit year
« Last Edit: January 24, 2023, 10:43:52 pm by Martin_fr »

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: Want to see something funny?
« Reply #12 on: January 24, 2023, 10:47:11 pm »
I havent tried yet but the first thing I would do is to remove unit "crt" from "uses".
Since you use Windows, I suggest you also put this line somewhere at top of your code like
Code: Pascal  [Select][+][-]
  1. program Consoleprog;
  2. {$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF}

I investigate later what you do there  :D

Thanks Zwerg.
PS: I'm pissed at how something so simple doesn't work in my computer and it works on someone else's computer. Mind Blown!
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2056
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Want to see something funny?
« Reply #13 on: January 24, 2023, 10:58:52 pm »
Test this please.
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF}
  3.  
  4. uses
  5.   SysUtils;
  6.  
  7. var
  8.   dat: TDate;
  9.   LYear, LMonth, LDay: Word;
  10. begin
  11.   dat := Now; // this is current date and time
  12.   DecodeDate(dat, LYear, LMonth, LDay); // split it up
  13.   dat := EncodeDate(LYear, LMonth, LDay); // put it together again
  14.   writeln(dat); // now really just the date value is printed
  15.   writeln(DateToStr(dat)); // show it however your system is configured to show it
  16.   writeln(StrToDate(DateToStr(dat))); // compare that to the writeln(dat);, it must be same now
  17.   ReadLn; // let console open until you press return
  18. end.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Want to see something funny?
« Reply #14 on: January 24, 2023, 11:04:46 pm »
OC DelGuy, please stop shouting at us by using these huge letters and the red color.

Your post is very confusing and it is not clear what the problem is. Why don't you simply write what you were expecting and what you got?

My guess is that you wonder why the line "WriteLn(StrToDate(DateToStr(Now))" does not print a date but a number.

First of all: dates and floating point numbers are the same in Pascal. The date is the number of days past Dec 30 1899. The conversion function DateToStr(some_date) converts this number to a string formatted like a date (depending on details in your FormatSettings record). And StrToDate does the opposite: it takes a date-formatted string and converts it back to the count of days since Dec 30 1899.

The instruction "WriteLn(StrToDate(DateToStr(Now))" consists of four parts which are executed from the inside to the outside:
/1/ Now: determines the current date (and time) - always rember: as number of days sincd Dec 30 1899. This, for today, the value 44951. (The fractional part, BTW, represents the time between 0:00 and 24:00 - I am ignoring it here).
/2/ DateToStr(...): converts that day count to a nicely formatted date string, in your case probably '01/24/2023'
/3/ StrToDate(...): takes that date string and converts it back to date - but remember: date is just a number! So, the result is 44951
/4/ WriteLn(...): Prints this number. OK, since it is a floating point value the standard WriteLn() prints it in exponential notation. Nothing mystic here!

The output of this sequence is absolutely correct.

 

TinyPortal © 2005-2018