Data Storage and Reproduction Cont.

: : There are several ways:
: : - a variable in a configuration file
: : - using the time as filename
: : - write a function which checks if a file exists.
:
: You could use the time idea with a date in front, so that it's practically impossible to EVER get a duplicate file.
: Think of a filename stored as:
: yymdhmms.xxx
: where:
: yy = 2 digit year
: m = 1-9,A-C (1-12)
: d = 1-9,A-W (1-31)
: h = 0-9,A-N (0-23)
: mm = 2 digit minute
: s = 0-9,A-V (0-30) *NOTE* This uses Second/2 ****
: xxx = your choice of extension
:
: This would be pretty easy to code and would only duplicate after 100 years or if the program was run 2 times in 2 seconds (both unlikely).
:
: Phat Nat
:
:

I like the date and time idea, but I cant see how I would make all the time variables (h, m, s, hs) fit into one single string variable which I could then call up as 'variable'.txt
variable:=(h, m, s, hs) doesnt work. Adding the date makes it even more coimplicated but then again, if you come up with an answer it will probably be obvious. I think Im starting to give up on programming :)


Comments

  • : : : There are several ways:
    : : : - a variable in a configuration file
    : : : - using the time as filename
    : : : - write a function which checks if a file exists.
    : :
    : : You could use the time idea with a date in front, so that it's practically impossible to EVER get a duplicate file.
    : : Think of a filename stored as:
    : : yymdhmms.xxx
    : : where:
    : : yy = 2 digit year
    : : m = 1-9,A-C (1-12)
    : : d = 1-9,A-W (1-31)
    : : h = 0-9,A-N (0-23)
    : : mm = 2 digit minute
    : : s = 0-9,A-V (0-30) *NOTE* This uses Second/2 ****
    : : xxx = your choice of extension
    : :
    : : This would be pretty easy to code and would only duplicate after 100 years or if the program was run 2 times in 2 seconds (both unlikely).
    : :
    : : Phat Nat
    : :
    : :
    :
    : I like the date and time idea, but I cant see how I would make all the time variables (h, m, s, hs) fit into one single string variable which I could then call up as 'variable'.txt
    : variable:=(h, m, s, hs) doesnt work. Adding the date makes it even more coimplicated but then again, if you come up with an answer it will probably be obvious. I think Im starting to give up on programming :)

    Don't give up. It takes alot of thought & trial and error. Don't think that we know anywhere near everything. I just wrote a post (Mouse Cursor) that made me realize that I have a very basic understanding and though I have ideas, I need to play around testing things too. My biggest project that I play around with on and off for the past 5? years is 3D graphics. Over the past couple of years I'v been trying to implement Textures onto the 3D objects. I'm no math genius, but that doesn't stop me from spending hours jotting on paper & coding.

    Anyways, back to the subject. I posted above how you could do it. Let me try to explain it clearer.
    First off, let me explain Hexadecimal. Like our number system (decimal) which is based on the number 10 (0-9, then repeats), hexadecimal is based on 16 (0-15, then repeats).
    Because we don't have a single digit for 10,11,12,13,14 or 15, we substitute letters. So, 0-9 is the same, but A=10,B=11,C=12,D=13,E=14,F=15. This gives us 0-15 in a single digit.
    So, 20h (or 20 hexadecimal) is equal to 32.
    [code]
    20h = 2*16 + 0 = 32 + 0 = 32 decimal
    21h = 2*16 + 1 = 32 + 1 = 33 decimal
    22h = 2*16 + 2 = 32 + 2 = 34 decimal
    [/code]

    Okay, so we can represent 0-15 with one character. Great!

    Well, if hexadecimal works that way, why can't we keep adding letters to allow us to have up to 36 numbers (0-9=10 numbers, A-Z=26 Numbers)

    Since we know that there is only 24 hours in one day, and we can use letters to represent any number greater than 9, we can save the hour data into one character. As well, we can do this with months (only 12) & days (only 31).

    Confused? Let's do some code to help out.
    [code]
    CONST
    Numbers : Array[0..35] Of Char =
    ('0','1','2','3','4','5','6','7','8','9','A','B',
    'C','D','E','F','G','H','I','J','K','L','M','N',
    'O','P','Q','R','S','T','U','V','W','X','Y','Z';
    [/code]

    We want our filename to look like this:
    YYMDhmms
    where:
    YY = year (2 digits)
    M = month (1 character)
    D = day (1 character)
    h = hour (1 character)
    mm = minute (2 digits)
    s = second (1 character)

    Okay, now let's say that it is September 7, 2005 7:15.0 am.
    We would want our file to look like this:
    YYMDhmms
    05977150

    No problem. But what if the time was 7:15.0 pm.
    Well, 7pm = 19 in 24-hour clock (12+7=19)
    Now thought, 19 won't fit into 1 space. So let's use our CONST from above:
    [code]
    Begin
    WriteLn(Numbers[19]);
    End.
    [/code]
    If you run this, it will write "[b]J[/b]".
    This is because in our [b]Numbers[/b] system, 19=J
    So now our file would look like this:
    YYMDhmms
    0597J150

    We can use this for the Month & Day as well, because they are both less than 37. The only one that is going to give us problems is the seconds, because they go up to 59. But because they aren't all that important, we can just divide the seconds in half and that will give us a number from 0-29, which we can use in our [b]Numbers[/b] system.

    Okay, you may want to re-read this a couple of times. Let me bang out some code below to help out. Notice that the only time you will get a duplicate filename is if the years are 100 apart or if you enter a 1 second difference (eg. 12 seconds & 13 seconds):
    [code]
    USES Crt, Dos;
    CONST
    Numbers : Array[0..35] Of Char =
    ('0','1','2','3','4','5','6','7','8','9','A','B',
    'C','D','E','F','G','H','I','J','K','L','M','N',
    'O','P','Q','R','S','T','U','V','W','X','Y','Z');

    VAR
    Year : Word;
    Month : Byte;
    Day : Byte;
    Hour : Byte;
    Minute : Byte;
    Second : Byte;
    TempS : String;
    FileName : String;

    Begin
    ClrScr;
    GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    GotoXY(1,5);Write('Enter Year : '); ReadLn(Year);
    Str(Year MOD 100,TempS);
    If Length(TempS) < 2 Then TempS := '0'+TempS;
    FileName := TempS;

    GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    GotoXY(1,6);Write('Enter Month : '); ReadLn(Month);
    FileName := FileName + Numbers[Month];

    GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    GotoXY(1,7);Write('Enter Day : '); ReadLn(Day);
    FileName := FileName + Numbers[Day];

    GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    GotoXY(1,8);Write('Enter Hour : '); ReadLn(Hour);
    FileName := FileName + Numbers[Hour];

    GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    GotoXY(1,9);Write('Enter Minute : '); ReadLn(Minute);
    Str(Minute,TempS);
    If Length(TempS) < 2 Then TempS := '0'+TempS;
    FileName := FileName + TempS;

    GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    GotoXY(1,10);Write('Enter Second : '); ReadLn(Second);
    FileName := FileName + Numbers[Second DIV 2];

    GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    Readkey;
    End.
    [/code]

    Hope this isn't too confusing.

    Phat Nat

  • [b][red]This message was edited by NinthAngle at 2005-9-8 10:54:10[/red][/b][hr]
    [b][red]This message was edited by NinthAngle at 2005-9-8 10:53:19[/red][/b][hr]
    : : : : There are several ways:
    : : : : - a variable in a configuration file
    : : : : - using the time as filename
    : : : : - write a function which checks if a file exists.
    : : :
    : : : You could use the time idea with a date in front, so that it's practically impossible to EVER get a duplicate file.
    : : : Think of a filename stored as:
    : : : yymdhmms.xxx
    : : : where:
    : : : yy = 2 digit year
    : : : m = 1-9,A-C (1-12)
    : : : d = 1-9,A-W (1-31)
    : : : h = 0-9,A-N (0-23)
    : : : mm = 2 digit minute
    : : : s = 0-9,A-V (0-30) *NOTE* This uses Second/2 ****
    : : : xxx = your choice of extension
    : : :
    : : : This would be pretty easy to code and would only duplicate after 100 years or if the program was run 2 times in 2 seconds (both unlikely).
    : : :
    : : : Phat Nat
    : : :
    : : :
    : :
    : : I like the date and time idea, but I cant see how I would make all the time variables (h, m, s, hs) fit into one single string variable which I could then call up as 'variable'.txt
    : : variable:=(h, m, s, hs) doesnt work. Adding the date makes it even more coimplicated but then again, if you come up with an answer it will probably be obvious. I think Im starting to give up on programming :)
    :
    : Don't give up. It takes alot of thought & trial and error. Don't think that we know anywhere near everything. I just wrote a post (Mouse Cursor) that made me realize that I have a very basic understanding and though I have ideas, I need to play around testing things too. My biggest project that I play around with on and off for the past 5? years is 3D graphics. Over the past couple of years I'v been trying to implement Textures onto the 3D objects. I'm no math genius, but that doesn't stop me from spending hours jotting on paper & coding.
    :
    : Anyways, back to the subject. I posted above how you could do it. Let me try to explain it clearer.
    : First off, let me explain Hexadecimal. Like our number system (decimal) which is based on the number 10 (0-9, then repeats), hexadecimal is based on 16 (0-15, then repeats).
    : Because we don't have a single digit for 10,11,12,13,14 or 15, we substitute letters. So, 0-9 is the same, but A=10,B=11,C=12,D=13,E=14,F=15. This gives us 0-15 in a single digit.
    : So, 20h (or 20 hexadecimal) is equal to 32.
    : [code]
    : 20h = 2*16 + 0 = 32 + 0 = 32 decimal
    : 21h = 2*16 + 1 = 32 + 1 = 33 decimal
    : 22h = 2*16 + 2 = 32 + 2 = 34 decimal
    : [/code]
    :
    : Okay, so we can represent 0-15 with one character. Great!
    :
    : Well, if hexadecimal works that way, why can't we keep adding letters to allow us to have up to 36 numbers (0-9=10 numbers, A-Z=26 Numbers)
    :
    : Since we know that there is only 24 hours in one day, and we can use letters to represent any number greater than 9, we can save the hour data into one character. As well, we can do this with months (only 12) & days (only 31).
    :
    : Confused? Let's do some code to help out.
    : [code]
    : CONST
    : Numbers : Array[0..35] Of Char =
    : ('0','1','2','3','4','5','6','7','8','9','A','B',
    : 'C','D','E','F','G','H','I','J','K','L','M','N',
    : 'O','P','Q','R','S','T','U','V','W','X','Y','Z';
    : [/code]
    :
    : We want our filename to look like this:
    : YYMDhmms
    : where:
    : YY = year (2 digits)
    : M = month (1 character)
    : D = day (1 character)
    : h = hour (1 character)
    : mm = minute (2 digits)
    : s = second (1 character)
    :
    : Okay, now let's say that it is September 7, 2005 7:15.0 am.
    : We would want our file to look like this:
    : YYMDhmms
    : 05977150
    :
    : No problem. But what if the time was 7:15.0 pm.
    : Well, 7pm = 19 in 24-hour clock (12+7=19)
    : Now thought, 19 won't fit into 1 space. So let's use our CONST from above:
    : [code]
    : Begin
    : WriteLn(Numbers[19]);
    : End.
    : [/code]
    : If you run this, it will write "[b]J[/b]".
    : This is because in our [b]Numbers[/b] system, 19=J
    : So now our file would look like this:
    : YYMDhmms
    : 0597J150
    :
    : We can use this for the Month & Day as well, because they are both less than 37. The only one that is going to give us problems is the seconds, because they go up to 59. But because they aren't all that important, we can just divide the seconds in half and that will give us a number from 0-29, which we can use in our [b]Numbers[/b] system.
    :
    : Okay, you may want to re-read this a couple of times. Let me bang out some code below to help out. Notice that the only time you will get a duplicate filename is if the years are 100 apart or if you enter a 1 second difference (eg. 12 seconds & 13 seconds):
    : [code]
    : USES Crt, Dos;
    : CONST
    : Numbers : Array[0..35] Of Char =
    : ('0','1','2','3','4','5','6','7','8','9','A','B',
    : 'C','D','E','F','G','H','I','J','K','L','M','N',
    : 'O','P','Q','R','S','T','U','V','W','X','Y','Z');
    :
    : VAR
    : Year : Word;
    : Month : Byte;
    : Day : Byte;
    : Hour : Byte;
    : Minute : Byte;
    : Second : Byte;
    : TempS : String;
    : FileName : String;
    :
    : Begin
    : ClrScr;
    : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : GotoXY(1,5);Write('Enter Year : '); ReadLn(Year);
    : Str(Year MOD 100,TempS);
    : If Length(TempS) < 2 Then TempS := '0'+TempS;
    : FileName := TempS;
    :
    : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : GotoXY(1,6);Write('Enter Month : '); ReadLn(Month);
    : FileName := FileName + Numbers[Month];
    :
    : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : GotoXY(1,7);Write('Enter Day : '); ReadLn(Day);
    : FileName := FileName + Numbers[Day];
    :
    : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : GotoXY(1,8);Write('Enter Hour : '); ReadLn(Hour);
    : FileName := FileName + Numbers[Hour];
    :
    : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : GotoXY(1,9);Write('Enter Minute : '); ReadLn(Minute);
    : Str(Minute,TempS);
    : If Length(TempS) < 2 Then TempS := '0'+TempS;
    : FileName := FileName + TempS;
    :
    : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : GotoXY(1,10);Write('Enter Second : '); ReadLn(Second);
    : FileName := FileName + Numbers[Second DIV 2];
    :
    : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : Readkey;
    : End.
    : [/code]
    :
    : Hope this isn't too confusing.
    :
    : Phat Nat
    :
    :

    Alright, a few things Im not to clear about...

    I think what you say about hexadecimals and creating a numerical system using all the letters of our alphabet is fairly straightforward. I had, however, difficulty translating some of your ideas into code simply because I dont understand some basic commands:

    [code]
    Str(Year MOD 100,TempS);
    [/code]

    I know what Str does, but MOD 100 doesnt mean much to me. The help system didnt help simply because it has verious subdefinitions of mod and i didnt know which one too look up.
    Consequently, Im also not too sure what your using TempS for.

    Also, is there any way to perhaps get the answers to your questions, ie (time, date) from the computer instead of having to manually tip them in?

    Finally, where in you program would i find space for ASSIGN(F, Filename.TXT).. How would I even use progper code to tell TP that Filename is the name of my TXT file.

    thanks soo much!
    NinthAngle




  • : [b][red]This message was edited by NinthAngle at 2005-9-8 10:54:10[/red][/b][hr]
    : [b][red]This message was edited by NinthAngle at 2005-9-8 10:53:19[/red][/b][hr]
    : : : : : There are several ways:
    : : : : : - a variable in a configuration file
    : : : : : - using the time as filename
    : : : : : - write a function which checks if a file exists.
    : : : :
    : : : : You could use the time idea with a date in front, so that it's practically impossible to EVER get a duplicate file.
    : : : : Think of a filename stored as:
    : : : : yymdhmms.xxx
    : : : : where:
    : : : : yy = 2 digit year
    : : : : m = 1-9,A-C (1-12)
    : : : : d = 1-9,A-W (1-31)
    : : : : h = 0-9,A-N (0-23)
    : : : : mm = 2 digit minute
    : : : : s = 0-9,A-V (0-30) *NOTE* This uses Second/2 ****
    : : : : xxx = your choice of extension
    : : : :
    : : : : This would be pretty easy to code and would only duplicate after 100 years or if the program was run 2 times in 2 seconds (both unlikely).
    : : : :
    : : : : Phat Nat
    : : : :
    : : : :
    : : :
    : : : I like the date and time idea, but I cant see how I would make all the time variables (h, m, s, hs) fit into one single string variable which I could then call up as 'variable'.txt
    : : : variable:=(h, m, s, hs) doesnt work. Adding the date makes it even more coimplicated but then again, if you come up with an answer it will probably be obvious. I think Im starting to give up on programming :)
    : :
    : : Don't give up. It takes alot of thought & trial and error. Don't think that we know anywhere near everything. I just wrote a post (Mouse Cursor) that made me realize that I have a very basic understanding and though I have ideas, I need to play around testing things too. My biggest project that I play around with on and off for the past 5? years is 3D graphics. Over the past couple of years I'v been trying to implement Textures onto the 3D objects. I'm no math genius, but that doesn't stop me from spending hours jotting on paper & coding.
    : :
    : : Anyways, back to the subject. I posted above how you could do it. Let me try to explain it clearer.
    : : First off, let me explain Hexadecimal. Like our number system (decimal) which is based on the number 10 (0-9, then repeats), hexadecimal is based on 16 (0-15, then repeats).
    : : Because we don't have a single digit for 10,11,12,13,14 or 15, we substitute letters. So, 0-9 is the same, but A=10,B=11,C=12,D=13,E=14,F=15. This gives us 0-15 in a single digit.
    : : So, 20h (or 20 hexadecimal) is equal to 32.
    : : [code]
    : : 20h = 2*16 + 0 = 32 + 0 = 32 decimal
    : : 21h = 2*16 + 1 = 32 + 1 = 33 decimal
    : : 22h = 2*16 + 2 = 32 + 2 = 34 decimal
    : : [/code]
    : :
    : : Okay, so we can represent 0-15 with one character. Great!
    : :
    : : Well, if hexadecimal works that way, why can't we keep adding letters to allow us to have up to 36 numbers (0-9=10 numbers, A-Z=26 Numbers)
    : :
    : : Since we know that there is only 24 hours in one day, and we can use letters to represent any number greater than 9, we can save the hour data into one character. As well, we can do this with months (only 12) & days (only 31).
    : :
    : : Confused? Let's do some code to help out.
    : : [code]
    : : CONST
    : : Numbers : Array[0..35] Of Char =
    : : ('0','1','2','3','4','5','6','7','8','9','A','B',
    : : 'C','D','E','F','G','H','I','J','K','L','M','N',
    : : 'O','P','Q','R','S','T','U','V','W','X','Y','Z';
    : : [/code]
    : :
    : : We want our filename to look like this:
    : : YYMDhmms
    : : where:
    : : YY = year (2 digits)
    : : M = month (1 character)
    : : D = day (1 character)
    : : h = hour (1 character)
    : : mm = minute (2 digits)
    : : s = second (1 character)
    : :
    : : Okay, now let's say that it is September 7, 2005 7:15.0 am.
    : : We would want our file to look like this:
    : : YYMDhmms
    : : 05977150
    : :
    : : No problem. But what if the time was 7:15.0 pm.
    : : Well, 7pm = 19 in 24-hour clock (12+7=19)
    : : Now thought, 19 won't fit into 1 space. So let's use our CONST from above:
    : : [code]
    : : Begin
    : : WriteLn(Numbers[19]);
    : : End.
    : : [/code]
    : : If you run this, it will write "[b]J[/b]".
    : : This is because in our [b]Numbers[/b] system, 19=J
    : : So now our file would look like this:
    : : YYMDhmms
    : : 0597J150
    : :
    : : We can use this for the Month & Day as well, because they are both less than 37. The only one that is going to give us problems is the seconds, because they go up to 59. But because they aren't all that important, we can just divide the seconds in half and that will give us a number from 0-29, which we can use in our [b]Numbers[/b] system.
    : :
    : : Okay, you may want to re-read this a couple of times. Let me bang out some code below to help out. Notice that the only time you will get a duplicate filename is if the years are 100 apart or if you enter a 1 second difference (eg. 12 seconds & 13 seconds):
    : : [code]
    : : USES Crt, Dos;
    : : CONST
    : : Numbers : Array[0..35] Of Char =
    : : ('0','1','2','3','4','5','6','7','8','9','A','B',
    : : 'C','D','E','F','G','H','I','J','K','L','M','N',
    : : 'O','P','Q','R','S','T','U','V','W','X','Y','Z');
    : :
    : : VAR
    : : Year : Word;
    : : Month : Byte;
    : : Day : Byte;
    : : Hour : Byte;
    : : Minute : Byte;
    : : Second : Byte;
    : : TempS : String;
    : : FileName : String;
    : :
    : : Begin
    : : ClrScr;
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : GotoXY(1,5);Write('Enter Year : '); ReadLn(Year);
    : : Str(Year MOD 100,TempS);
    : : If Length(TempS) < 2 Then TempS := '0'+TempS;
    : : FileName := TempS;
    : :
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : GotoXY(1,6);Write('Enter Month : '); ReadLn(Month);
    : : FileName := FileName + Numbers[Month];
    : :
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : GotoXY(1,7);Write('Enter Day : '); ReadLn(Day);
    : : FileName := FileName + Numbers[Day];
    : :
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : GotoXY(1,8);Write('Enter Hour : '); ReadLn(Hour);
    : : FileName := FileName + Numbers[Hour];
    : :
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : GotoXY(1,9);Write('Enter Minute : '); ReadLn(Minute);
    : : Str(Minute,TempS);
    : : If Length(TempS) < 2 Then TempS := '0'+TempS;
    : : FileName := FileName + TempS;
    : :
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : GotoXY(1,10);Write('Enter Second : '); ReadLn(Second);
    : : FileName := FileName + Numbers[Second DIV 2];
    : :
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : Readkey;
    : : End.
    : : [/code]
    : :
    : : Hope this isn't too confusing.
    : :
    : : Phat Nat
    : :
    : :
    :
    : Alright, a few things Im not to clear about...
    :
    : I think what you say about hexadecimals and creating a numerical system using all the letters of our alphabet is fairly straightforward. I had, however, difficulty translating some of your ideas into code simply because I dont understand some basic commands:
    :
    : [code]
    : Str(Year MOD 100,TempS);
    : [/code]
    :
    : I know what Str does, but MOD 100 doesnt mean much to me. The help system didnt help simply because it has verious subdefinitions of mod and i didnt know which one too look up.
    : Consequently, Im also not too sure what your using TempS for.
    :
    : Also, is there any way to perhaps get the answers to your questions, ie (time, date) from the computer instead of having to manually tip them in?
    :
    : Finally, where in you program would i find space for ASSIGN(F, Filename.TXT).. How would I even use progper code to tell TP that Filename is the name of my TXT file.
    :
    : thanks soo much!
    : NinthAngle
    :
    :
    :
    :
    :
    MOD means modulo, and calculates the remainder of a division. For example:
    [code]
    254 mod 100 = 54
    [/code]
    The companion operator of MOD is DIV, which divides the integer and rounds the number down. Example:
    [code]
    254 div 100 = 2
    [/code]

    As for the time and date use the GetTime() and GetDate() procedures.

    Assign(File, Filename) will assign the filename to the file variable. Any read(), readln(), write(), and writeln() with that file variable as parameter will operate on the file specified by filename. In all cases Filename can be a hard-coded filename or a string variable holding the filename. Example:
    [code]
    Assign(f, 'somefile.txt');
    [/code]
    [code]
    Filename := 'somefile.txt';
    Assign(f, Filename);
    [/code]
    are both the same. Thus you can either ask a user for a filename, create one using the date/time, random characters, or any other means; and still Assign() it to a file.
  • : : [code]
    : : USES Crt, Dos;
    : : CONST
    : : Numbers : Array[0..35] Of Char =
    : : ('0','1','2','3','4','5','6','7','8','9','A','B',
    : : 'C','D','E','F','G','H','I','J','K','L','M','N',
    : : 'O','P','Q','R','S','T','U','V','W','X','Y','Z');
    : :
    : : VAR
    : : Year : Word;
    : : Month : Byte;
    : : Day : Byte;
    : : Hour : Byte;
    : : Minute : Byte;
    : : Second : Byte;
    : : TempS : String;
    : : FileName : String;
    : :
    : : Begin
    : : ClrScr;
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : GotoXY(1,5);Write('Enter Year : '); ReadLn(Year);
    : : Str(Year MOD 100,TempS);
    : : If Length(TempS) < 2 Then TempS := '0'+TempS;
    : : FileName := TempS;
    : :
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : GotoXY(1,6);Write('Enter Month : '); ReadLn(Month);
    : : FileName := FileName + Numbers[Month];
    : :
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : GotoXY(1,7);Write('Enter Day : '); ReadLn(Day);
    : : FileName := FileName + Numbers[Day];
    : :
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : GotoXY(1,8);Write('Enter Hour : '); ReadLn(Hour);
    : : FileName := FileName + Numbers[Hour];
    : :
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : GotoXY(1,9);Write('Enter Minute : '); ReadLn(Minute);
    : : Str(Minute,TempS);
    : : If Length(TempS) < 2 Then TempS := '0'+TempS;
    : : FileName := FileName + TempS;
    : :
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : GotoXY(1,10);Write('Enter Second : '); ReadLn(Second);
    : : FileName := FileName + Numbers[Second DIV 2];
    : :
    : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : Readkey;
    : : End.
    : : [/code]
    : :
    : : Hope this isn't too confusing.
    : : Phat Nat
    :
    : Alright, a few things Im not to clear about...
    :
    : I think what you say about hexadecimals and creating a numerical system using all the letters of our alphabet is fairly straightforward. I had, however, difficulty translating some of your ideas into code simply because I dont understand some basic commands:
    :
    : [code]
    : Str(Year MOD 100,TempS);
    : [/code]
    :
    : I know what Str does, but MOD 100 doesnt mean much to me. The help system didnt help simply because it has verious subdefinitions of mod and i didnt know which one too look up.
    : Consequently, Im also not too sure what your using TempS for.
    :
    : Also, is there any way to perhaps get the answers to your questions, ie (time, date) from the computer instead of having to manually tip them in?
    :
    : Finally, where in you program would i find space for ASSIGN(F, Filename.TXT).. How would I even use progper code to tell TP that Filename is the name of my TXT file.
    :
    : thanks soo much!
    : NinthAngle

    Hey. The reason I'm using the MOD function is because I want a 2-digit year, not a four digit year. So, If I use YEAR MOD 100, it will only give me the part of the year that's under 100. As Zibadian said it's the modulas. Take 235 for example. If you divide 235 by 50, you get 4.7
    So the whole part (4) is what DIV would give you. 4*50 = 200, so MOD would give you 235-200 = 35.

    The TempS is used because if I did:
    [code]
    Str(Minute,FileName);
    [/code]
    It would erase everything that's already in the Filename string. This way I can just add the TempS onto the end of the FileName string.
    *NOTE* I didn't really need to use the TempS for the Year variable, I just did it for conformity.

    As for getting the date & time from the system, you already learned how to get the time and the date is the same, but with the GetDate() function. The filename would just need to be opened using the FILENAME string that we created.

    Phat Nat

  • : : [b][red]This message was edited by NinthAngle at 2005-9-8 10:54:10[/red][/b][hr]
    : : [b][red]This message was edited by NinthAngle at 2005-9-8 10:53:19[/red][/b][hr]
    : : : : : : There are several ways:
    : : : : : : - a variable in a configuration file
    : : : : : : - using the time as filename
    : : : : : : - write a function which checks if a file exists.
    : : : : :
    : : : : : You could use the time idea with a date in front, so that it's practically impossible to EVER get a duplicate file.
    : : : : : Think of a filename stored as:
    : : : : : yymdhmms.xxx
    : : : : : where:
    : : : : : yy = 2 digit year
    : : : : : m = 1-9,A-C (1-12)
    : : : : : d = 1-9,A-W (1-31)
    : : : : : h = 0-9,A-N (0-23)
    : : : : : mm = 2 digit minute
    : : : : : s = 0-9,A-V (0-30) *NOTE* This uses Second/2 ****
    : : : : : xxx = your choice of extension
    : : : : :
    : : : : : This would be pretty easy to code and would only duplicate after 100 years or if the program was run 2 times in 2 seconds (both unlikely).
    : : : : :
    : : : : : Phat Nat
    : : : : :
    : : : : :
    : : : :
    : : : : I like the date and time idea, but I cant see how I would make all the time variables (h, m, s, hs) fit into one single string variable which I could then call up as 'variable'.txt
    : : : : variable:=(h, m, s, hs) doesnt work. Adding the date makes it even more coimplicated but then again, if you come up with an answer it will probably be obvious. I think Im starting to give up on programming :)
    : : :
    : : : Don't give up. It takes alot of thought & trial and error. Don't think that we know anywhere near everything. I just wrote a post (Mouse Cursor) that made me realize that I have a very basic understanding and though I have ideas, I need to play around testing things too. My biggest project that I play around with on and off for the past 5? years is 3D graphics. Over the past couple of years I'v been trying to implement Textures onto the 3D objects. I'm no math genius, but that doesn't stop me from spending hours jotting on paper & coding.
    : : :
    : : : Anyways, back to the subject. I posted above how you could do it. Let me try to explain it clearer.
    : : : First off, let me explain Hexadecimal. Like our number system (decimal) which is based on the number 10 (0-9, then repeats), hexadecimal is based on 16 (0-15, then repeats).
    : : : Because we don't have a single digit for 10,11,12,13,14 or 15, we substitute letters. So, 0-9 is the same, but A=10,B=11,C=12,D=13,E=14,F=15. This gives us 0-15 in a single digit.
    : : : So, 20h (or 20 hexadecimal) is equal to 32.
    : : : [code]
    : : : 20h = 2*16 + 0 = 32 + 0 = 32 decimal
    : : : 21h = 2*16 + 1 = 32 + 1 = 33 decimal
    : : : 22h = 2*16 + 2 = 32 + 2 = 34 decimal
    : : : [/code]
    : : :
    : : : Okay, so we can represent 0-15 with one character. Great!
    : : :
    : : : Well, if hexadecimal works that way, why can't we keep adding letters to allow us to have up to 36 numbers (0-9=10 numbers, A-Z=26 Numbers)
    : : :
    : : : Since we know that there is only 24 hours in one day, and we can use letters to represent any number greater than 9, we can save the hour data into one character. As well, we can do this with months (only 12) & days (only 31).
    : : :
    : : : Confused? Let's do some code to help out.
    : : : [code]
    : : : CONST
    : : : Numbers : Array[0..35] Of Char =
    : : : ('0','1','2','3','4','5','6','7','8','9','A','B',
    : : : 'C','D','E','F','G','H','I','J','K','L','M','N',
    : : : 'O','P','Q','R','S','T','U','V','W','X','Y','Z';
    : : : [/code]
    : : :
    : : : We want our filename to look like this:
    : : : YYMDhmms
    : : : where:
    : : : YY = year (2 digits)
    : : : M = month (1 character)
    : : : D = day (1 character)
    : : : h = hour (1 character)
    : : : mm = minute (2 digits)
    : : : s = second (1 character)
    : : :
    : : : Okay, now let's say that it is September 7, 2005 7:15.0 am.
    : : : We would want our file to look like this:
    : : : YYMDhmms
    : : : 05977150
    : : :
    : : : No problem. But what if the time was 7:15.0 pm.
    : : : Well, 7pm = 19 in 24-hour clock (12+7=19)
    : : : Now thought, 19 won't fit into 1 space. So let's use our CONST from above:
    : : : [code]
    : : : Begin
    : : : WriteLn(Numbers[19]);
    : : : End.
    : : : [/code]
    : : : If you run this, it will write "[b]J[/b]".
    : : : This is because in our [b]Numbers[/b] system, 19=J
    : : : So now our file would look like this:
    : : : YYMDhmms
    : : : 0597J150
    : : :
    : : : We can use this for the Month & Day as well, because they are both less than 37. The only one that is going to give us problems is the seconds, because they go up to 59. But because they aren't all that important, we can just divide the seconds in half and that will give us a number from 0-29, which we can use in our [b]Numbers[/b] system.
    : : :
    : : : Okay, you may want to re-read this a couple of times. Let me bang out some code below to help out. Notice that the only time you will get a duplicate filename is if the years are 100 apart or if you enter a 1 second difference (eg. 12 seconds & 13 seconds):
    : : : [code]
    : : : USES Crt, Dos;
    : : : CONST
    : : : Numbers : Array[0..35] Of Char =
    : : : ('0','1','2','3','4','5','6','7','8','9','A','B',
    : : : 'C','D','E','F','G','H','I','J','K','L','M','N',
    : : : 'O','P','Q','R','S','T','U','V','W','X','Y','Z');
    : : :
    : : : VAR
    : : : Year : Word;
    : : : Month : Byte;
    : : : Day : Byte;
    : : : Hour : Byte;
    : : : Minute : Byte;
    : : : Second : Byte;
    : : : TempS : String;
    : : : FileName : String;
    : : :
    : : : Begin
    : : : ClrScr;
    : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : GotoXY(1,5);Write('Enter Year : '); ReadLn(Year);
    : : : Str(Year MOD 100,TempS);
    : : : If Length(TempS) < 2 Then TempS := '0'+TempS;
    : : : FileName := TempS;
    : : :
    : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : GotoXY(1,6);Write('Enter Month : '); ReadLn(Month);
    : : : FileName := FileName + Numbers[Month];
    : : :
    : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : GotoXY(1,7);Write('Enter Day : '); ReadLn(Day);
    : : : FileName := FileName + Numbers[Day];
    : : :
    : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : GotoXY(1,8);Write('Enter Hour : '); ReadLn(Hour);
    : : : FileName := FileName + Numbers[Hour];
    : : :
    : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : GotoXY(1,9);Write('Enter Minute : '); ReadLn(Minute);
    : : : Str(Minute,TempS);
    : : : If Length(TempS) < 2 Then TempS := '0'+TempS;
    : : : FileName := FileName + TempS;
    : : :
    : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : GotoXY(1,10);Write('Enter Second : '); ReadLn(Second);
    : : : FileName := FileName + Numbers[Second DIV 2];
    : : :
    : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : Readkey;
    : : : End.
    : : : [/code]
    : : :
    : : : Hope this isn't too confusing.
    : : :
    : : : Phat Nat
    : : :
    : : :
    : :
    : : Alright, a few things Im not to clear about...
    : :
    : : I think what you say about hexadecimals and creating a numerical system using all the letters of our alphabet is fairly straightforward. I had, however, difficulty translating some of your ideas into code simply because I dont understand some basic commands:
    : :
    : : [code]
    : : Str(Year MOD 100,TempS);
    : : [/code]
    : :
    : : I know what Str does, but MOD 100 doesnt mean much to me. The help system didnt help simply because it has verious subdefinitions of mod and i didnt know which one too look up.
    : : Consequently, Im also not too sure what your using TempS for.
    : :
    : : Also, is there any way to perhaps get the answers to your questions, ie (time, date) from the computer instead of having to manually tip them in?
    : :
    : : Finally, where in you program would i find space for ASSIGN(F, Filename.TXT).. How would I even use progper code to tell TP that Filename is the name of my TXT file.
    : :
    : : thanks soo much!
    : : NinthAngle
    : :
    : :
    : :
    : :
    : :
    : MOD means modulo, and calculates the remainder of a division. For example:
    : [code]
    : 254 mod 100 = 54
    : [/code]
    : The companion operator of MOD is DIV, which divides the integer and rounds the number down. Example:
    : [code]
    : 254 div 100 = 2
    : [/code]
    :
    : As for the time and date use the GetTime() and GetDate() procedures.
    :
    : Assign(File, Filename) will assign the filename to the file variable. Any read(), readln(), write(), and writeln() with that file variable as parameter will operate on the file specified by filename. In all cases Filename can be a hard-coded filename or a string variable holding the filename. Example:
    : [code]
    : Assign(f, 'somefile.txt');
    : [/code]
    : [code]
    : Filename := 'somefile.txt';
    : Assign(f, Filename);
    : [/code]
    : are both the same. Thus you can either ask a user for a filename, create one using the date/time, random characters, or any other means; and still Assign() it to a file.
    :

    I still dont see how
    [Code]
    Filename := 'somefile.txt';
    Assign(f, Filename);
    [/Code]
    will let me assign the generated date and time as the filename.
    If I defined (useing ':=') "Filename" as 'somefile.txt' this makes Filename no less of a "variable" (ie something that changes) than If I simply went along and used the
    [code] Assign(f, 'somefile.txt') [/code] version.

    If I code
    [code]
    Assign(F, Filename) {Where Filename is the generated date and time}
    Append(F)
    [/code]

    The compiler says 'Error 2: File not Found"

    ???
  • : : : [b][red]This message was edited by NinthAngle at 2005-9-8 10:54:10[/red][/b][hr]
    : : : [b][red]This message was edited by NinthAngle at 2005-9-8 10:53:19[/red][/b][hr]
    : : : : : : : There are several ways:
    : : : : : : : - a variable in a configuration file
    : : : : : : : - using the time as filename
    : : : : : : : - write a function which checks if a file exists.
    : : : : : :
    : : : : : : You could use the time idea with a date in front, so that it's practically impossible to EVER get a duplicate file.
    : : : : : : Think of a filename stored as:
    : : : : : : yymdhmms.xxx
    : : : : : : where:
    : : : : : : yy = 2 digit year
    : : : : : : m = 1-9,A-C (1-12)
    : : : : : : d = 1-9,A-W (1-31)
    : : : : : : h = 0-9,A-N (0-23)
    : : : : : : mm = 2 digit minute
    : : : : : : s = 0-9,A-V (0-30) *NOTE* This uses Second/2 ****
    : : : : : : xxx = your choice of extension
    : : : : : :
    : : : : : : This would be pretty easy to code and would only duplicate after 100 years or if the program was run 2 times in 2 seconds (both unlikely).
    : : : : : :
    : : : : : : Phat Nat
    : : : : : :
    : : : : : :
    : : : : :
    : : : : : I like the date and time idea, but I cant see how I would make all the time variables (h, m, s, hs) fit into one single string variable which I could then call up as 'variable'.txt
    : : : : : variable:=(h, m, s, hs) doesnt work. Adding the date makes it even more coimplicated but then again, if you come up with an answer it will probably be obvious. I think Im starting to give up on programming :)
    : : : :
    : : : : Don't give up. It takes alot of thought & trial and error. Don't think that we know anywhere near everything. I just wrote a post (Mouse Cursor) that made me realize that I have a very basic understanding and though I have ideas, I need to play around testing things too. My biggest project that I play around with on and off for the past 5? years is 3D graphics. Over the past couple of years I'v been trying to implement Textures onto the 3D objects. I'm no math genius, but that doesn't stop me from spending hours jotting on paper & coding.
    : : : :
    : : : : Anyways, back to the subject. I posted above how you could do it. Let me try to explain it clearer.
    : : : : First off, let me explain Hexadecimal. Like our number system (decimal) which is based on the number 10 (0-9, then repeats), hexadecimal is based on 16 (0-15, then repeats).
    : : : : Because we don't have a single digit for 10,11,12,13,14 or 15, we substitute letters. So, 0-9 is the same, but A=10,B=11,C=12,D=13,E=14,F=15. This gives us 0-15 in a single digit.
    : : : : So, 20h (or 20 hexadecimal) is equal to 32.
    : : : : [code]
    : : : : 20h = 2*16 + 0 = 32 + 0 = 32 decimal
    : : : : 21h = 2*16 + 1 = 32 + 1 = 33 decimal
    : : : : 22h = 2*16 + 2 = 32 + 2 = 34 decimal
    : : : : [/code]
    : : : :
    : : : : Okay, so we can represent 0-15 with one character. Great!
    : : : :
    : : : : Well, if hexadecimal works that way, why can't we keep adding letters to allow us to have up to 36 numbers (0-9=10 numbers, A-Z=26 Numbers)
    : : : :
    : : : : Since we know that there is only 24 hours in one day, and we can use letters to represent any number greater than 9, we can save the hour data into one character. As well, we can do this with months (only 12) & days (only 31).
    : : : :
    : : : : Confused? Let's do some code to help out.
    : : : : [code]
    : : : : CONST
    : : : : Numbers : Array[0..35] Of Char =
    : : : : ('0','1','2','3','4','5','6','7','8','9','A','B',
    : : : : 'C','D','E','F','G','H','I','J','K','L','M','N',
    : : : : 'O','P','Q','R','S','T','U','V','W','X','Y','Z';
    : : : : [/code]
    : : : :
    : : : : We want our filename to look like this:
    : : : : YYMDhmms
    : : : : where:
    : : : : YY = year (2 digits)
    : : : : M = month (1 character)
    : : : : D = day (1 character)
    : : : : h = hour (1 character)
    : : : : mm = minute (2 digits)
    : : : : s = second (1 character)
    : : : :
    : : : : Okay, now let's say that it is September 7, 2005 7:15.0 am.
    : : : : We would want our file to look like this:
    : : : : YYMDhmms
    : : : : 05977150
    : : : :
    : : : : No problem. But what if the time was 7:15.0 pm.
    : : : : Well, 7pm = 19 in 24-hour clock (12+7=19)
    : : : : Now thought, 19 won't fit into 1 space. So let's use our CONST from above:
    : : : : [code]
    : : : : Begin
    : : : : WriteLn(Numbers[19]);
    : : : : End.
    : : : : [/code]
    : : : : If you run this, it will write "[b]J[/b]".
    : : : : This is because in our [b]Numbers[/b] system, 19=J
    : : : : So now our file would look like this:
    : : : : YYMDhmms
    : : : : 0597J150
    : : : :
    : : : : We can use this for the Month & Day as well, because they are both less than 37. The only one that is going to give us problems is the seconds, because they go up to 59. But because they aren't all that important, we can just divide the seconds in half and that will give us a number from 0-29, which we can use in our [b]Numbers[/b] system.
    : : : :
    : : : : Okay, you may want to re-read this a couple of times. Let me bang out some code below to help out. Notice that the only time you will get a duplicate filename is if the years are 100 apart or if you enter a 1 second difference (eg. 12 seconds & 13 seconds):
    : : : : [code]
    : : : : USES Crt, Dos;
    : : : : CONST
    : : : : Numbers : Array[0..35] Of Char =
    : : : : ('0','1','2','3','4','5','6','7','8','9','A','B',
    : : : : 'C','D','E','F','G','H','I','J','K','L','M','N',
    : : : : 'O','P','Q','R','S','T','U','V','W','X','Y','Z');
    : : : :
    : : : : VAR
    : : : : Year : Word;
    : : : : Month : Byte;
    : : : : Day : Byte;
    : : : : Hour : Byte;
    : : : : Minute : Byte;
    : : : : Second : Byte;
    : : : : TempS : String;
    : : : : FileName : String;
    : : : :
    : : : : Begin
    : : : : ClrScr;
    : : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : : GotoXY(1,5);Write('Enter Year : '); ReadLn(Year);
    : : : : Str(Year MOD 100,TempS);
    : : : : If Length(TempS) < 2 Then TempS := '0'+TempS;
    : : : : FileName := TempS;
    : : : :
    : : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : : GotoXY(1,6);Write('Enter Month : '); ReadLn(Month);
    : : : : FileName := FileName + Numbers[Month];
    : : : :
    : : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : : GotoXY(1,7);Write('Enter Day : '); ReadLn(Day);
    : : : : FileName := FileName + Numbers[Day];
    : : : :
    : : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : : GotoXY(1,8);Write('Enter Hour : '); ReadLn(Hour);
    : : : : FileName := FileName + Numbers[Hour];
    : : : :
    : : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : : GotoXY(1,9);Write('Enter Minute : '); ReadLn(Minute);
    : : : : Str(Minute,TempS);
    : : : : If Length(TempS) < 2 Then TempS := '0'+TempS;
    : : : : FileName := FileName + TempS;
    : : : :
    : : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : : GotoXY(1,10);Write('Enter Second : '); ReadLn(Second);
    : : : : FileName := FileName + Numbers[Second DIV 2];
    : : : :
    : : : : GotoXY(1,1); WriteLn('Filename = "',FileName,'.DAT"');
    : : : : Readkey;
    : : : : End.
    : : : : [/code]
    : : : :
    : : : : Hope this isn't too confusing.
    : : : :
    : : : : Phat Nat
    : : : :
    : : : :
    : : :
    : : : Alright, a few things Im not to clear about...
    : : :
    : : : I think what you say about hexadecimals and creating a numerical system using all the letters of our alphabet is fairly straightforward. I had, however, difficulty translating some of your ideas into code simply because I dont understand some basic commands:
    : : :
    : : : [code]
    : : : Str(Year MOD 100,TempS);
    : : : [/code]
    : : :
    : : : I know what Str does, but MOD 100 doesnt mean much to me. The help system didnt help simply because it has verious subdefinitions of mod and i didnt know which one too look up.
    : : : Consequently, Im also not too sure what your using TempS for.
    : : :
    : : : Also, is there any way to perhaps get the answers to your questions, ie (time, date) from the computer instead of having to manually tip them in?
    : : :
    : : : Finally, where in you program would i find space for ASSIGN(F, Filename.TXT).. How would I even use progper code to tell TP that Filename is the name of my TXT file.
    : : :
    : : : thanks soo much!
    : : : NinthAngle
    : : :
    : : :
    : : :
    : : :
    : : :
    : : MOD means modulo, and calculates the remainder of a division. For example:
    : : [code]
    : : 254 mod 100 = 54
    : : [/code]
    : : The companion operator of MOD is DIV, which divides the integer and rounds the number down. Example:
    : : [code]
    : : 254 div 100 = 2
    : : [/code]
    : :
    : : As for the time and date use the GetTime() and GetDate() procedures.
    : :
    : : Assign(File, Filename) will assign the filename to the file variable. Any read(), readln(), write(), and writeln() with that file variable as parameter will operate on the file specified by filename. In all cases Filename can be a hard-coded filename or a string variable holding the filename. Example:
    : : [code]
    : : Assign(f, 'somefile.txt');
    : : [/code]
    : : [code]
    : : Filename := 'somefile.txt';
    : : Assign(f, Filename);
    : : [/code]
    : : are both the same. Thus you can either ask a user for a filename, create one using the date/time, random characters, or any other means; and still Assign() it to a file.
    : :
    :
    : I still dont see how
    : [Code]
    : Filename := 'somefile.txt';
    : Assign(f, Filename);
    : [/Code]
    : will let me assign the generated date and time as the filename.
    : If I defined (useing ':=') "Filename" as 'somefile.txt' this makes Filename no less of a "variable" (ie something that changes) than If I simply went along and used the
    : [code] Assign(f, 'somefile.txt') [/code] version.
    :
    : If I code
    : [code]
    : Assign(F, Filename) {Where Filename is the generated date and time}
    : Append(F)
    : [/code]
    :
    : The compiler says 'Error 2: File not Found"
    :
    : ???
    :
    A variable is a piece of memory to store a certain value in, and is defined by using the "var" reserved word. There is a large difference in storing values in variables or hard-coding them. A hard-coded value can only be changed by recompiling the program, while a value stored in a variable can be changed while the program is running. Here is a better example of a variable (=changing) filename variable:
    [code]
    write('Enter filename: ');
    readln(Filename);
    Assign(f, Filename);
    Rewrite(f);
    Close(f);
    [/code]
    This example asks the user for a filename and creates an empty file with that name.

    The Append() statement tries to open an existing file to add more text to it. If you generate a filename based on date/time then the file will probably not exist. To create a new file you need to use Rewrite() instead of Append().
  • : I still dont see how
    : [Code]
    : Filename := 'somefile.txt';
    : Assign(f, Filename);
    : [/Code]
    : will let me assign the generated date and time as the filename.
    : If I defined (useing ':=') "Filename" as 'somefile.txt' this makes Filename no less of a "variable" (ie something that changes) than If I simply went along and used the
    : [code] Assign(f, 'somefile.txt') [/code] version.
    :
    : If I code
    : [code]
    : Assign(F, Filename) {Where Filename is the generated date and time}
    : Append(F)
    : [/code]
    :
    : The compiler says 'Error 2: File not Found"

    You're right, but since the file is non-existant, that's where you get your error. The file HAS to exist to use Append();
    This is a safer way that should always be used:
    [code]
    Assign(F,FileName);
    {$I-} { Return Error Code instead of Halting program }
    Append(F);
    IF IOResult <> 0 Then { If there was an error, like File Not found...}
    Rewrite(F); { ...then create the file. }
    {$I+} { I like to do this, but you can just compile }
    { whole program in the $I- state. }
    [/code]

    Phat Nat

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories