Creating Text File

E

Erik

I'm using ASP 3.0. I'm taking form contents and dumping it into a text file
on the server.
My question is how to add the TIME to this statement. I create the text file
with the name of file, month, day and year.
I would like to add TIME to it.
 
E

Erik

I tried it already and the error I receive is that it is not part of the
mappath property.

Thanks.
 
D

dlbjr

Function GetFileStamp()
Dim ary1(5)
ary1(0) = Year(Date)
ary1(1) = Pad(Month(Date))
ary1(2) = Pad(Day(Date))
ary1(3) = Pad(Hour(Now()))
ary1(4) = Pad(Minute(Now()))
ary1(5) = Pad(Second(Now()))
GetFileStamp = Join(ary1,"")
End Function
Function Pad(strData)
Pad = Trim(strData)
If Len(Pad) = 1 Then
Pad = "0" & Pad
End If
End Function


dlbjr

Unambit from meager knowledge of inane others,
engender uncharted sagacity.
 
B

Boris Nikolaevich

The probable reason you get the error, and the reason dlbjr's code would
work, is that Time values include colons :)) which can't be used in a
Windows filename.

The other possible cause is that you typed something wrong, or put the Now()
function in the wrong part of your concatenation mess. In this case,
dlbjr's function still makes sense because 1) it makes your code easier to
read and 2) it makes your code easier to reuse.
 
M

McKirahan

Erik said:
I'm using ASP 3.0. I'm taking form contents and dumping it into a text file
on the server.
My question is how to add the TIME to this statement. I create the text file
with the name of file, month, day and year.
I would like to add TIME to it.
-------------------------------------------------------------
set fso = createobject("scripting.filesystemobject")

Set act = fso.CreateTextFile(server.mappath("/data/"&g_filename & "-"&
month(date())& day(date())& year(date()) &".htm"), true)


Here's how I create a timestamp VBScript:

'*
'* Generate Timestamp (ccyymmddhhnnss)
'*
Dim strNOW
strNOW = Now()
Dim arrNOW(5)
arrNOW(0) = DatePart("yyyy", strNOW)
arrNOW(1) = DatePart("m", strNOW)
arrNOW(2) = DatePart("d", strNOW)
arrNOW(3) = DatePart("h", strNOW)
arrNOW(4) = DatePart("n", strNOW)
arrNOW(5) = DatePart("s", strNOW)
Dim intNOW
strNOW = ""
For intNOW = 0 To UBound(arrNOW)
If (arrNOW(intNOW) <= 9) Then arrNOW(intNOW) = "0" & arrNOW(intNOW)
strNOW = strNOW & arrNOW(intNOW)
Next

Thus, you would use:

Set act = fso.CreateTextFile(server.mappath("/data/" & g_filename & "-" &
strNOW & ".htm"), true)

You had "mmddyy" but I prefer this format which allows multiple files to be
sorted chronologically.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,153
Messages
2,570,863
Members
47,400
Latest member
sgamema

Latest Threads

Top