VB6 - Unable to read Text File

  • Thread starter Thread starter Rob Leyshon
  • Start date Start date
R

Rob Leyshon

For whatever reason I am unable to use FileSystemObject

e.g. using the code:
Dim fso As New FileSystemObject

Everytime my program hits this it gives the error:
"Compile error: User-defined type not defined"

Am I missing something?
 
Rob Leyshon said:
For whatever reason I am unable to use FileSystemObject
Dim fso As New FileSystemObject
"Compile error: User-defined type not defined"

Am I missing something?

Yes, but I'm not even going to tell you what, because the FSO
just /isn't/ worth the overhead or hassle just to read a text file.
Use VB's built-in file handling methods, as in

Dim iFile as Integer
iFile = FreeFile()
Open "file" for Input as #iFile
Dim sData as String
sData = Input$( LOF( iFile), #iFile )
Close #iFile

' sData now contains the entire file for you to play with, or

iFile = FreeFile()
Open "file" for Input as #iFile
Do While Not EOF( iFile )
Line Input sData, #iFile ' 1 line at a time
Loop
Close #iFile

HTH,
Phill W.
 
Rob Leyshon said:
For whatever reason I am unable to use FileSystemObject

e.g. using the code:
Dim fso As New FileSystemObject

Everytime my program hits this it gives the error:
"Compile error: User-defined type not defined"

Am I missing something?

You are missing a reference to "Microsoft Scripting Runtime".

BTW: This group is dedicated to Visual Basic .NET, for VB6-related
questions consider posting to one of the groups in the microsoft.public.vb.*
hierarchy.
 
sorry Herrfried :-( ( i know it is the wrong place )

but i can`t agree on this
because the FSO
just /isn't/ worth the overhead or hassle just to read a text file.


FSO is superior in speed

if you indeed need to read / write a file one time okay i would agree with
the overhead responce

however if you do multiple file operations ( for instance generating html
for the webbrowser control )
you sure see a hughe performance boost if you use the filesystem object

also generating unicode files can only be done with FSO ( needed to write
a Russian site generator for the webbrowser control in the past )

just my 2 dollar cents ( as they are less worth :- )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top