Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileSystemObject Problem

Status
Not open for further replies.

Ablecken

Programmer
Jun 5, 2001
130
US
I am having troble opening a text file for TextStream:
Private Function OpenFile(What As String)
Dim fso As New FileSystemObject, fil1 As File, ts As TextStream
Set fil1 = fso.GetFile(What)
' Read the contents of the file.
Set ts = fil1.OpenAsTextStream(ForReading)
s = ts.ReadLine
MsgBox s
ts.Close
End Function

This is basically a little bit of the code for what im doing. The problem im having is User Defined type not found. What am I doing wrong?
Thanks
Able
P.S. - What can I do if I want to read a specific line?
 
If you are just trying to read a file try:

Dim lFilenum as string
dim MyFilePath as String
Dim sCurrentLine as string
lFileNum = FreeFile

Open MyFilePath For Input As #lFileNum

Do Until EOF(lFileNum)
Line Input #lFileNum, sCurrentLine

s = sCurrentLine
Loop

Close #lFileNum
 
Hi Ableken,
You need to check if you have set a reference to the required library.
To user the FileSystemObject you need to set a reference to "Windows Scripting Host library". Once you do that you will not face the error.

I assumed that you are getting this as a Compiler error.
And accordingly I have given this solution.

regards
Atul
 
How do I use this Windows Scripting library? Is it a component, cause if it is it's not there. Thanks a lot guys.
Able
 
It's not a component. It's a reference to the scripting runtime library (scrrun.dll)
 
In Access you need to open the form in design mode, select code then go to tools,references, then select the proper library.
 
In Microsoft VB 6
- click on the "Project" menu
- select "References"
- tick the item you want to reference
- Click OK

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top