Solved

fix "object required" error trying to createobject in vbscript in html

Posted on 2008-10-06
6
985 Views
Last Modified: 2012-06-27
I am getting the error "object required"  on the "server.createobject" statement when it is run in ie from the server.  I do not get the error if I put the script in a vbs file and run it in the server without an error.   I've written lots of scripts but I am just starting to put them in an html file.  I would like to use the filesystemobject to write links to documents in a folder. But I can't get past this error to do that.  From what I have read I should be able to do this.

 What is causing the error???  I hope this is an easy question because I am stumped.  Thanks!
<HTML>
<HEAD>
<TITLE>Test Create Object</TITLE>
</HEAD>
<BODY>
Start!<br>
 
<SCRIPT LANGUAGE="VBSCRIPT" runat="server">
on error resume next
dim fso
set fso = Server.CreateObject("Scripting.FileSystemObject")
msgbox "fso error - " & err.description
</SCRIPT>
 
End!<br>
</BODY>
</HTML>

Open in new window

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
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:Devario Johnson
ID: 22654473
Try this.  The msgbox in web based vbscript causes an issue, I have not tested this...but that line is where id start, also is this running on a windows box?  If so I can rewrite this as an ASP file and then i can format it the way you would need perfectly.

<HTML>
<HEAD>
<TITLE>Test Create Object</TITLE>
</HEAD>
<BODY>
Start!<br>
 
<SCRIPT LANGUAGE="VBSCRIPT" runat="server">
on error resume next
dim fso
set fso = Server.CreateObject("Scripting.FileSystemObject")
response.Write "fso error - " & err.description 'I think your error is here
</SCRIPT>
 
End!<br>
</BODY>
</HTML>
0
 

Author Comment

by:utahalee
ID: 22659325
Thanks for taking a look at my question.  Let me update my status.  This is running on a Windows server.  I am familiar with vbscript as".vbs" script files but not putting script in web pages.  I have mostly worked with developing windows apps with visual studio.  I am trying to add some dynamic code to a 'static web page' developed in Dreamweaver.  I have never used Dreamweaver.  It said I can use vbscript in it  so that sounded the right choice to me.  I am open to using asp if I can use it in Dreamweaver.  I'm not sure how to add it to Dreamweaver though.  I am working in a 1 person shop with  a network person.  I have been hired as part-time assistant and asked to do some programming.

I removed the message box like you suggested and replaced it with:
 "document.Write "fso error - " & err.description"
I got the same message "fso error - ActiveX component can't create object"

I can code the rest of the script to write my links to the documents if i can get the past the CreateObject error.

Would you verify that I should be able to do what I want in script.  With my limited web development I'm not sure what I can do or not do.  What I read said what I am trying to do should work.
Thanks
0
 
LVL 5

Expert Comment

by:Devario Johnson
ID: 22660800
no, not document.write.....

response.write.

This is what I want you to do.

Since you are on a windows server, you can make an .ASP file with VBScript as your language as choice.

You will be utilizing html as well but there is separation of what goes on.  Here is how you would do what you want to do.

1) open a new .asp file in dreamweaver.
2) Delete ALL contents of that file.
3) Add this code. (Below)


4) Place this file in your web directory and call it VIA an web Bowser.  Double Clicking on it will not work.  It must be called from a web browser and it must be housed in the web directory. eg. public_html/mysite/

5) Verify that the file was written

<%@Language = "VBScript"%>
<%OPTION EXPLICIT%>
 
<%
'Option Explicit means that you will get an error if you do not declare your variables
'This is a comment.  The IIS webserver will ignore all comments with a single quote.
'All items between the ASP delimieted tags will be read as ASP / VBScript as per your
'previous declaration at the top of the page.
 
'Declare your Variables
dim fs,fname
set fs = Server.CreateObject("Scripting.FileSystemObject")
set fname = fs.CreateTextFile("c:\test.txt",true)
fname.WriteLine("Hello World!")
fname.Close
set fname=nothing
set fs=nothing
 
'Based on the code above you just created a file in c:\ named test.txt that was written the text Hello World!
'All ASP/VBScript must be before HTML.
%>
<!-- Html Content Begins here -->
 
<html>
<head>My test ASP page</head>
<body>
Check C:\ to see if the file wrote successfully.
</body>
</html>

Open in new window

0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

Author Comment

by:utahalee
ID: 22661310
Thank you very much!!!  It did just what you said it would do.  You have helped tie some loose ends with Dreamweaver and scripting together that I wouldn't of figured out.  

 A couple of more questions though.

does changing the file extention from .html to .asp let me add vbscript code to a current existing static page as long as it is before the <html> tag?  I'm guessign that it will.  

I think I need to get an "ASP for Dummies book next to get me going.  

I'm familiar with asp.net and vb in visual studio and see that I can create a new asp.net vb page.  Do I have to have Visual Studio installed for that work?

I'm curious why my simple html and script example didn't work?  Do you have any idea?

I'll plan on closing  this question and give you the points after this.
Your help was invaluable to get me started now.  Thanks again!

0
 
LVL 5

Accepted Solution

by:
Devario Johnson earned 100 total points
ID: 22662189
does changing the file extention from .html to .asp let me add vbscript code to a current existing static page as long as it is before the <html> tag?  I'm guessign that it will.  

changing the extension will make it a page that the server will treat as dynamic scripting ready (server side) but that alone will now allow the VBScript code.  You MUST define in the header what language you are using.

<%@Language = "VBSCRIPT"%>
<%@Language = "JavaScript"%>
<%@Language = "XML"%>

You can use a plethora of languages and make them server side through ASP.  Now, you can also use these languages in the body of the code as well without declaring them as the default langugae.
--------------------

I'm familiar with asp.net and vb in visual studio and see that I can create a new asp.net vb page.  Do I have to have Visual Studio installed for that work?

No, you can make a VB.Net page with Dreamweaver no problem!

--------------------

I'm curious why my simple html and script example didn't work?  Do you have any idea?

Basically you were trying to call an error that was not there.  Your script was asking to output an error, when in reality there was no error.  If there was an IF statement that said IF Err <> "" then response.Write Err & ": This is my error"

Then you would have gotten either an error or a Blank page (as you didnt have any alternative content)

--------------------

One thing i want to correct you on though, you can use VScript throughout the HTML code, it just must be declared before you start using HTML.  u can move back into the asp while your in HTML by doing something like the following code snipplet.

<%@Language = VBScript%>
<%OPTION EXPLICIT%>
 
<%
'Business logic here
function ready
if date(day) = "Monday" then
response.Write "Hooray it's Monday!"
else
response.write "it's not monday :("
end if
end function
%>
 
<html>
<head>Sample ASP</head>
<body>
<b>This all of my html content</b>
<br/>
<%ready%>
<br/>
<b>I just called an ASP function!</b>
</body>
</html>
 
<!--The code may be a bit off, I typed this off of the top of my head, but you get the idea-->

Open in new window

0
 

Author Closing Comment

by:utahalee
ID: 31503476
You have been very helpful.  I was sure this sould be pretty simple to do but not having any experience with web development made it hard to get started.  I've ordered some ASP books and should be able to go from here.  Thanks again!
0

Featured Post

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

734 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