: : : 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
: : : - 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