Connecting Tech Pros Worldwide Forums | Help | Site Map

VB6 - Unable to read Text File

Rob Leyshon
Guest
 
Posts: n/a
#1: Nov 21 '05
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?


Phill. W
Guest
 
Posts: n/a
#2: Nov 21 '05

re: VB6 - Unable to read Text File


"Rob Leyshon" <rob@snoogans.plus.com> wrote in message
news:425e88c3$0$570$ed2619ec@ptn-nntp-reader03.plus.net...[color=blue]
> 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?[/color]

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.


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#3: Nov 21 '05

re: VB6 - Unable to read Text File


"Rob Leyshon" <rob@snoogans.plus.com> schrieb:[color=blue]
> 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?[/color]

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/>

M. Posseth
Guest
 
Posts: n/a
#4: Nov 21 '05

re: VB6 - Unable to read Text File


sorry Herrfried :-( ( i know it is the wrong place )

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


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 :- )



"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:d3m1lg$kbb$1@yarrow.open.ac.uk...[color=blue]
> "Rob Leyshon" <rob@snoogans.plus.com> wrote in message
> news:425e88c3$0$570$ed2619ec@ptn-nntp-reader03.plus.net...[color=green]
> > 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?[/color]
>
> 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.
>
>[/color]


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#5: Nov 21 '05

re: VB6 - Unable to read Text File


"M. Posseth" <michelp@nohausystems.nl> schrieb:[color=blue]
> sorry Herrfried :-( ( i know it is the wrong place )[/color]

No problem...
[color=blue]
> but i can`t agree on this
>[color=green]
>> because the FSO
>> just /isn't/ worth the overhead or hassle just to read a text file.[/color]
>
>
> FSO is superior in speed[/color]

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/>

Closed Thread