|
-
Feb 8th, 2001, 01:57 AM
#1
Thread Starter
PowerPoster
When I try to run the below code, I get some error.
File name is test.html
Code:
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<P><INPUT id=button1 name=button1 type=button value=Button></P>
<SCRIPT LANGUAGE=vbscript>
<!--
sub Button1_OnClick
Dim fso, MyFile, RdData
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.OpenTextFile ("MyData.txt",ForReading )
RdData = MyFile.Readall
Msgbox RdData
MyFile.Close
end sub
-->
</SCRIPT>
</BODY>
</HTML>
The error message is :
An exxeption of typee "Microsoft VBScript runtime error: ActiveX component can't create object: "Scripting.FileSystemObject" was not handle.
-
Feb 8th, 2001, 04:38 AM
#2
Fanatic Member
Chris,
Try the following:
Code:
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<P><INPUT id=button1 name=button1 type=button value=Button></P>
<SCRIPT LANGUAGE=vbscript>
<!--
Sub Button1_OnClick
Msgbox GetFileText("C:\Crap\MyData.txt")
End sub
Function GetFileText(FileSpec)
dim fso
dim stream
set fso = createobject("Scripting.FileSystemObject")
set stream = fso.opentextfile(FileSpec)
GetFileText = stream.ReadAll()
set stream = Nothing
set fso = Nothing
End Function
-->
</SCRIPT>
</BODY>
</HTML>
Note that I have used a full path for your MyData.txt file, as the FSO will require this.
-
Feb 8th, 2001, 04:43 AM
#3
Thread Starter
PowerPoster
Jerry Grant, that work great. Thx.
! more Q, If i wish to put all the read data into a HTML page instead of message box. then how can I do it.
Or read the data and add it into a combobox/listbox.
-
Feb 8th, 2001, 05:56 AM
#4
Fanatic Member
This will put the contents into a TEXTAREA:
Code:
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>Load text dynamically</TITLE>
<SCRIPT LANGUAGE=vbscript>
<!--
Sub ShowText(FileSpec)
oForm.oText.InnerText = GetFileText(FileSpec)
End sub
Function GetFileText(FileSpec)
dim fso
dim stream
set fso = createobject("Scripting.FileSystemObject")
set stream = fso.opentextfile(FileSpec)
GetFileText = stream.ReadAll()
set stream = Nothing
set fso = Nothing
End Function
-->
</SCRIPT>
</HEAD>
<BODY onload=ShowText("C:\Crap\MyData.txt")>
<form name="oForm">
<textarea rows="5" cols="30" name="oText">
</textarea>
</form>
</BODY>
</HTML>
If you want to put the data into a list/combo box then it would be a lot easier with ASP, is your site using ASP? If so then read the file with the ReadLine method of the stream. You can also put the data straight into a DIV block i beleive, though not done it myself.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|