Solved

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

Posted on 2008-09-30
7
964 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

785 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