Home All Groups Group Topic Archive Search About

VB6 - Unable to read Text File

Author
14 Apr 2005 3:17 PM
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?

Author
14 Apr 2005 3:25 PM
Phill. W
"Rob Leyshon" <r**@snoogans.plus.com> wrote in message
news:425e88c3$0$570$ed2619ec@ptn-nntp-reader03.plus.net...
> 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.
Author
14 Apr 2005 4:20 PM
M. Posseth
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 :- )



Show quoteHide quote
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:d3m1lg$kbb$1@yarrow.open.ac.uk...
> "Rob Leyshon" <r**@snoogans.plus.com> wrote in message
> news:425e88c3$0$570$ed2619ec@ptn-nntp-reader03.plus.net...
> > 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.
>
>
Author
14 Apr 2005 5:21 PM
Herfried K. Wagner [MVP]
"M. Posseth" <mich***@nohausystems.nl> schrieb:
> sorry Herrfried :-(     ( i know it is the wrong place  )

No problem...

> 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

The problem with the FSO is that some admins block the FSO for security
reasons and thus applications which rely on the FSO cannot be used in every
corporate environment.  However, I agree with you that the FSO is superior
to VB's intrinsic file access functions in some aspects.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
14 Apr 2005 4:02 PM
Herfried K. Wagner [MVP]
"Rob Leyshon" <r**@snoogans.plus.com> schrieb:
> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>