Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Use StreamReader in VBScript

$
0
0
I know that VBScript loves the File System Object, and I've used it numerous times to read/write files. But now I have the need to open a file using the StreamReader object instead. I need to pass the object to a canned function that expects the object to be an instance of StreamReader. (The function reads from the file using StreamReader syntax.) I've searched online for days now and can't find any mention of employing it. I have tried each of the Set statements below that have already been commented out:

Dim Rec
Dim Output
Dim objSR
'Set objSR = CreateObject("SystemIO.StreamReader")
'Set objSR = CreateObject("System.IO.StreamReader")
'Set objSR = CreateObject("StreamReader")
'Set objSR = CreateObject("System_IO.StreamReader")
'Set objSR = CreateObject("dotNET.System_IO.StreamReader")
'Set objSR = CreateObject("dotNET.System.IO.StreamReader")
'Set objSR = CreateObject("dotNET.SystemIO.StreamReader")
Dim objSIO
Set objSIO = CreateObject("System.IO")
Set objSR = objSIO.StreamReader("C:\what\StreamReader\TestRead.txt")

MsgBox("so far so good")

'objSR.Open("C:\what\StreamReader\TestRead.txt")
Output = ""
While Not objSR.EndOfStream
	Rec = objSR.ReadLine
	Output = Output & Rec & vbNewLine
Wend
objSR.Close()
Set objSR = Nothing
MsgBox(Output)



My TestRead.txt file is a simple text file containing 3 short lines in it to test the file access:

This is line 1.
This is line 2.
This is line 3.

The error message I get always mentions the attempt I have defined in the CreateObject("whatever") in the various attempts listed above. The error I get is always: "ActiveX component can't create object: 'whatever' Code: 800A01AD


It irks me that I can use the file system object in Visual Studio projects, but I can't use StreamReader in VBScript files...? Is that fair?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>