: This message was edited by NinthAngle at 2005-9-8 10:54:10
: This message was edited by NinthAngle at 2005-9-8 10:53:19
: : : : : 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 <useless> 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.
: :
: :
: : 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.
: :
: :
: : 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:
: :
: : If you run this, it will write "J".
: : This is because in our Numbers 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 Numbers 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):
: :
: :
: : 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:
:
:
:
: 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:
The companion operator of MOD is DIV, which divides the integer and rounds the number down. Example:
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:
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.
: This message was edited by NinthAngle at 2005-9-8 10:53:19
: : : : : 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 <useless> 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.
: :
: : 20h = 2*16 + 0 = 32 + 0 = 32 decimal : : 21h = 2*16 + 1 = 32 + 1 = 33 decimal : : 22h = 2*16 + 2 = 32 + 2 = 34 decimal : :
: :
: : 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.
: :
: : 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'; : :
: :
: : 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:
: :
: : Begin : : WriteLn(Numbers[19]); : : End. : :
: : If you run this, it will write "J".
: : This is because in our Numbers 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 Numbers 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):
: :
: : 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. : :
: :
: : 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:
:
:
: Str(Year MOD 100,TempS); :
:
: 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:
254 mod 100 = 54
The companion operator of MOD is DIV, which divides the integer and rounds the number down. Example:
254 div 100 = 2
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:
Assign(f, 'somefile.txt');
Filename := 'somefile.txt'; Assign(f, Filename);
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.