Solved

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

Posted on 2008-09-30
7
984 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

707 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