Solved

Can I read data from a text file using vbscript in a html file?

Posted on 2008-09-30
7
978 Views
Last Modified: 2012-05-05
I have done a lot of windows apps programs and vbscript files, but not web apps, hence my confusion.  Can I read a text file using the filesystemobject in a vbscript in an html file?  I just need to read some data from the text file.  I don't want to use a database and a table if I can read the data in a text file.  

the html file runs fine on my pc but I get the error when I move the html to the server and try to run it in a browser on my pc.

Here is my html
<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
Start <br>

<SCRIPT LANGUAGE="VBSCRIPT" runat="server">
on error resume next
dim fso
set fso = CreateObject("Scripting.FileSystemObject")      '''error occurs here
msgbox "fso error - " & err.description
</script>

End <br>
</BODY>
</HTML>
-------------------
the msbox displays "fso error - Activex component can't create object".

I can move the script to a.vbs file and run in on the server without the error.  It can create the filesystemobject in a vbs script file on the server,  but the script in the html file gets an error trying to create the filesystemobject on the server.

This seems like a simple thing to do but I'm just getting started with web apps and not sure what works or doesn't.  Can I do what I want???

Thanks





0
Comment
Question by:utahalee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 22612142
Try changing this line:
set fso = CreateObject("Scripting.FileSystemObject")

to this
Set fso = Server.CreateObject("Scripting.FileSystemObject")

Regards,

Rob.
0
 

Author Comment

by:utahalee
ID: 22613954
Thanks for the answering the question.
I now get an "object required" error instead of the "Activex component can't create object" error.
Any other suggestions?  



0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22619325
Which line gives you that error? There is no other line in the above code that uses that fso object.

You might have something like:

<SCRIPT LANGUAGE="VBSCRIPT" runat="server">
on error resume next
dim fso
set fso = CreateObject("Scripting.FileSystemObject")
Set objFile = fso.CreateTextFile("NewFile.txt", True)
objFile.Write "Something"
objFile.Close
</script>


note that because you have used
Set FSO = CreateObject("Scripting.FileSystemObject")

you must call the methods of the filesystemobject using the FSO object name, such as
fso.CreateTextFile

If you were to try
fso2.CreateTextFile

you'd get "Object Required"

Regards,

Rob.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:utahalee
ID: 22624809
I changed my line to Set fso = Server.CreateObject("Scripting.FileSystemObject") as you suggested.

I get the "Object Required"  error on that line now instead of the Activex component can't create object that I got before I added "Server." to the createobject.

I can't use error the FileSystemObject methods becasue of the error I get when I try to create the FSO object.

The script works fine outside of the html.  Should I be able to use the FileSystemObject in vbscript in an html file to check if a  text file exists on the server?  If it exists I would use the filesystemobject to read the  textfile and format in a table on the web page.  I haven't done much with scripts in web pages so I hope this can work.

Thanks for all your help so far.

0
 
LVL 65

Accepted Solution

by:
RobSampson earned 100 total points
ID: 22628655
Hmmm, yes that should work:
http://www.eggheadcafe.com/articles/20030627b.asp

I'm really not sure.  You do need to be running the page on a Windows server though, but I'm not sure if other operating systems support it....I think you can get VBScript for Unix, but I can't remember.

Regards,

Rob.
0
 

Author Closing Comment

by:utahalee
ID: 31501546
Thanks for your help and verifying that what I want to do should work.  I am running on a windows server.  Further investigation of the error message is leading me down the path that the problem is with the server and something needs to be changed or fixed on it.  Thanks.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22639269
No problem. Thanks for the grade.

Perhaps you need to look into re-installing or repairing the VBScript engine...

Regards,

Rob.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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