Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i write to a text file using ASP & VBScript? 2

Status
Not open for further replies.

mijulie

Programmer
Jun 21, 2001
36
0
0
IE
This below is my ASP page. Does anybody know what lines i need to write to a file? All suggestions welcome, thanks in advance, J

<%@ LANGUAGE=VBScript %>
<%
strTitle = Request.Form(&quot;Title&quot;)
strBinary = Request.Form(&quot;Binary&quot;)
strBuild = Request.Form(&quot;Build&quot;)
strTest = Request.Form(&quot;Test&quot;)
strDate = Request.Form(&quot;Date&quot;)
strLandLine = Request.Form(&quot;LandLine&quot;)
strMobile = Request.Form(&quot;Mobile&quot;)
str1_3_9Challenge = Request.Form(&quot;1_3_9Challenge&quot;)
strBlocks = Request.Form(&quot;Blocks&quot;)
strChallenge = Request.Form(&quot;Challenge&quot;)
strIRDBDownload = Request.Form(&quot;IRDBDownload&quot;)
striIRDBDownload = Request.Form(&quot;iIRDBDownload&quot;)
strReprogramming = Request.Form(&quot;Reprogramming&quot;)
strStatus = Request.Form(&quot;Status&quot;)
strComment = Request.Form(&quot;Comment&quot;)
strDebugs = Request.Form(&quot;Debugs&quot;)

%>

<B>Binary: </B><%=strBinary %><BR>
<B>Build: </B><%=strBuild %><BR>
<B>Test A/C: </B><%=strTest %><BR>
<B>Date: </B><%=strDate %><BR><BR>


<B><U>Test Results</U></B><BR><BR>

<B>1_1_15 LandLine:</B> <%If strLandLine = &quot;Tekelec&quot; Then %>
Tekelec: Yes
<% Else %> <U>Tekelec - No</U>
<% End If %>
<% If strLandLine = &quot;D&D&quot; Then %>
D & D: Yes
<% Else %> <B> , </B> <U>D & D - No</U>
<% End If %>
<% If strLandLine = &quot;BearerData&quot; Then %>
Bearer Data: Yes
<% Else %> <B> , </B> <U>Bearer Data - No</U>
<% End If %>
<% If strLandLine = &quot;SoftShelf&quot; Then %>
SoftShelf: Yes
<% Else %> <B> , </B> <U>SoftShelf - No</U>
<% End If %><BR><BR>
 
Use
filesysobj=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
file=filesysobj.CreateTextFile(FilePath&Name)
file.WriteLine(textline)
file.ReadLine(textline)
file.Close
 
I put those lines in and now i get an error saying, &quot;Object Required: &quot;Server&quot;&quot; and in the debugger it points to the following line;
filesysobj=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
 
I think i'm better off keeping it as simple as possible just using HTML scripts
 
Then use some like that
Use
filesysobj=CreateObject(&quot;Scripting.FileSystemObject&quot;)
file=filesysobj.CreateTextFile(FilePath&Name)
file.WriteLine(textline)
file.ReadLine(textline)
file.Close

without Server because this is used when you write in ASP pages
 
It seems to be one error after another. i now have an error saying,
&quot;ActiveX component can't create object:'Scripting.FileSystemObject'&quot; when i insert the following code,

filesysobj=CreateObject(&quot;Scripting.FileSystemObject&quot;)
file=filesysobj.CreateTextFile(&quot;C:\new.txt&quot;)
file.WriteLine(&quot;Hello&quot;)
file.ReadLine(&quot;Hello&quot;)
file.Close

Any ideas????
 
Try this may work
dim filesysobj,file1
set filesysobj=CreateObject(&quot;Scripting.FileSystemObject&quot;)
set file1=filesysobj.CreateTextFile(&quot;C:\new.txt&quot;)
file1.WriteLine(&quot;Hello&quot;)
file1.ReadLine(&quot;Hello&quot;)
file1.Close

 
Unfortunately, no joy! I got the same error as the last one!

 
These methods aren't going to work in a regular HTML page, as indicated above. They are ASP methods, and as such, will only work in a server environment that supports ASP.

Hence, the object required &quot;server&quot; error message.
penny.gif
penny.gif
 
see
faq333-504

anyhow -
instead of createobject,
try
set filesysobj = Server.CreateObject(&quot;scripting.filesystemobject&quot;)

I read that using Server.CreateObject as opposed to CreateObject is more efficient.

good luck
leo
 
U have just sayed u write tha code in HTML not IN ASP....
In ASP MUST BE SERVER.CREATEOBJECT
in HTML is:
<HTML>
<BODY>
<script language=vbscript>
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
sub b1_onclick
set f1=fso.CreateTextFile(&quot;c:\new.txt&quot;,true)
f1.WriteLine(&quot;the darn text line&quot;)
f1.close
end sub
</script>
<INPUT type=&quot;button&quot; value=&quot;Button&quot; id=b1 name=b1>
</BODY>
</HTML>
 
I hope this should work because it is from a project i wrote specialy for this...
 
Yes!!! That worked, thank you so much! It seems so simple when you see it. Now I can make some progress thanks to you!

Mijulie.
 
Since you were able to solve my problem I was wondering if you could tell me how, in relation to HTML forms, i pass a value stored as, say, &quot;Build No. :&quot; to the text file.
This is the information i'm trying to pass;
<B>Binary: </B><INPUT NAME=&quot;Binary&quot; SIZE=&quot;12&quot;>

I have this much, but how do i pass in the value for it without giving it a specific number?
f1.WriteLine(&quot;Binary:&quot;)................

Any suggestions?
 
U can use just the name or id u have used...
<input name=&quot;Binary&quot; id=&quot;Binary&quot; size=&quot;12&quot;>
f1.WriteLine(document.Binary.value)
or
f1.WriteLine(Binary.value)




 
Thanks for the solution but i figured it out, you might be able to help me with something else though!
I want to pass in the name of the textfile based on the Binary followed by the Build No. , it looks like this;

Set filetxt = filesys.CreateTextFile(&quot;F:\Corktest\Sit\&TheBinary&TheBuild&.txt&quot;, ForWriting, True)

I get an error saying i need a closing bracket after txt&quot;
I know it's probably the inverted commas or something. It should create a file called something like, tpota163.txt

Can u help me???
 
try:

Set filetxt = filesys.CreateTextFile(&quot;F:\Corktest\Sit\ TheBinary & TheBuild & &quot;.txt&quot;, ForWriting, True)

might have just been a typo, but you never know.

 
Did u leave out a closing inverted comma, there's only 3 of them. I tried putting a second one after &quot;.txt&quot; but an error generates saying i need a closing bracket. Without it it says i need a closing &quot;. I haven't a clue what to do!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top