Solved

File naming from a DB field

Posted on 2000-02-17
16
139 Views
Last Modified: 2010-04-04
I have a Db of shows, each has upto 5 dates, I need to create a file for each date that has a name relating to that date. i.e. some kind of date-to-string function. And then how do i assign this name to the file in an onclick event?
0
Comment
Question by:SRP
  • 8
  • 5
  • 2
  • +1
16 Comments
 
LVL 6

Expert Comment

by:edey
Comment Utility
you can use this:

DateTimeToString converts a variable to a string using the specified Format.

procedure DateTimeToString(var NewString: string; const Format:
  string; DateTime: TDateTime);

Description

DateTimeToString converts the date and time value given by DateTime using the format string given by Format into the string variable given by NewString. For Formats supported, refer to the description of the FormatDateTime function.


to convert the date to a string, then use:

Unit

System
AssignFile associates the name of an external file with a file variable.

procedure AssignFile(var F; FileName: string);

and reset/rewrite to create/edit a file with that particular name.


Gl
Mike
0
 
LVL 1

Expert Comment

by:AttarSoftware
Comment Utility
But of course, you will have to replace the / in the dates...

something like:

  for c := 1 to length( s ) do
    if( s[ c ] = '/' ) then s[ c ] := '_' ;

Should do it :O)

Good luck

Tim.
0
 
LVL 6

Expert Comment

by:edey
Comment Utility
Actually the format string param lets you (far more flexibly) specify the format of the returned string.

or, you could simply try:

file_name := intToStr(trunc(some_date_time);



GL
Mike
0
 
LVL 1

Expert Comment

by:Phoenix_s
Comment Utility
This is D4 code

for making a name out of a date-time string... it's kinda windy in the effect there's a lotta **** plunked in one filename, but so far as the date/time seperators go, there's a clue on how to make it pretty and easy.

Yah... it should be a function, but it ain't right now... sue me ;)  hehehehehe
----------------------------------

procedure tform1.genoutputname;
var tempdateseparator : char;
    temptimeseparator : char;
begin
  //copy original date/time seperators into temp file
  //replace with "_" char
  tempdateseparator := dateseparator;
  dateseparator := '_';
  temptimeseparator := timeseparator;
  timeseparator := '_';
  outputname := '';
  outputname := outputname + 'c:\my documents\';
  outputname := outputname + 'aging_to_';
  outputname := outputname + datetostr(runtodate);
  outputname := outputname + '_run_on_'+datetostr(date)+'_'+timetostr(time)+'.xls';
  //revert the date time seperator to the "/"
  dateseparator := tempdateseparator;
  timeseparator := temptimeseparator;
end;
0
 
LVL 6

Expert Comment

by:edey
Comment Utility
It is not generally considered polite to rephrase previous comments as an answer.  Do you have anything new/different/better then the previous sugestions?


GL
Mike
0
 
LVL 1

Expert Comment

by:Phoenix_s
Comment Utility
edey:

k fine... it's a comment now   you can smooth your fur back down.

I gave a complete working example which, I might add, I had not seen yet as a comment or answer...
0
 

Author Comment

by:SRP
Comment Utility
All of the 'comments', seem to answer bits of my problem, but I can't seem to see what will do the job the best.

the dates are in fields and the file needs creating when the button is pressed.

is there an easy way i can just take the date and take out the / (easily), and put it in as the file name. most of the comments seem a bit messy?!!
0
 
LVL 6

Accepted Solution

by:
edey earned 50 total points
Comment Utility
var
 fileName : string;
begin
//option one
 fileName := intToStr(trunc(date));
//option two
 DateTimeToString(fileName,'dd-mm-yy',date);
//then
 assignFile(some_file_var,fileName);
//use reset/rewrite & write to file here
 closeFile(some_file_var);
end;



GL
Mike
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:SRP
Comment Utility
Thats the simple sort of thing I was looking for. (It should work well, yeah?)

I may comment and up the points again if i have trouble with it.

Cheers
SAM

p.s appologies for the late response I am on holiday and have limited access to the internet!!

0
 
LVL 6

Expert Comment

by:edey
Comment Utility
No problem, glad to be of service


GL
Mike
0
 

Author Comment

by:SRP
Comment Utility
edey- one thing i couldn't sort out from this was how to get the date from the edit box, can i assign date:=editbox1.text;
to get the date that needs to be the file name from this editbox?
0
 
LVL 6

Expert Comment

by:edey
Comment Utility
"I have a Db of shows, each has upto 5 dates, I need to create a file for each date that has a name relating to that date. i.e. some kind of date-to-string function. And then how do i assign this name to the file in an onclick event?"

Do you not already have the dates in the db?



GL
Mike
0
 

Author Comment

by:SRP
Comment Utility
The way it works is i have an entry form and the user fills in all the fields in the table, in editboxes. then posts these in the table.
When the date field is filled in the user can click on a button which creates a file the name being that date.

For instance editbox holds: 27/02/00
button click creates file: 270200.dat

Does that make it a bit clearer?

Cheers
SAM

i can reask this question to give more points if you like!?
0
 
LVL 6

Expert Comment

by:edey
Comment Utility
You do have a couple of options here:

1)replace the edit with a db aware TDateTimePicker, then the field will always contain a TDateTime (a number) and the above suggestion will work, you can try these:
http://www.torry.webnorth.com/vcl/database/ardcale.zip
http://www.torry.webnorth.com/vcl/shared/calend.zip


2)use a TMaskEdit to ensure the user input will always have the form ##/##/## and use this:
  fileName := date[0]+date[1]+date[3]+date[4]+date[6]+date[7]+'.dat';
Note you could also use an edit, put the above in a try/except block, and give the user an error/warning if they didn't give acceptable input

GL
Mike
0
 

Author Comment

by:SRP
Comment Utility
Thanks again for that. Very helpful.
I used this method
fileName := date[0]+date[1]+date[3]+date[4]+date[6]+date[7]+'.dat';
as the field had validation on it anyway, without needing maskedit.

Cheers
SAM
0
 
LVL 6

Expert Comment

by:edey
Comment Utility
Excellent

Gl
Mike
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now