Results 1 to 4 of 4

Thread: Can't craete Object

  1. #1

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    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.

  2. #2
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810
    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.

    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  3. #3

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    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.

  4. #4
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810
    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.
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width