Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I read from a file through using a class module?

Posted on 2003-03-29
4
Medium Priority
?
157 Views
Last Modified: 2010-05-01
Hi,

Can someone explain how I can read information from a text file when I am in a class module? I can read the information in fine when I use my code in the form, but when I try to use a class to do the same thing it won't work. The error I get is run-time error 54 "bad file mode". I can also write to the file in a class, but I can't read from it.

I have tried the following ways, but they won't work when I am in a class:
 
intfile = freefile
 While Not EOF(1)
 Line Input #1, temp
 wend

 temp = Input(LOF(intFile), intFile)

Thanks
0
Comment
Question by:Claypious
  • 2
4 Comments
 
LVL 1

Expert Comment

by:hazgod
ID: 8232250
open "filename" for input as #1
While Not EOF(1)
Line Input #1, temp
Wend
close #1

temp = Input(LOF(intFile), intFile)
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 150 total points
ID: 8232991
Actually right but the #1 should be replaced with the freefile reference to be safe:

' Read line by line
intfile = freefile()
open "filename" for input as #intfile
While Not EOF(intfile)
Line Input #intfile, temp
wend
close #intfile

' or read the entire contents at once
intfile = freefile()
open "filename" for input as #intfile
While Not EOF(intfile)
temp = intput$(lof(intfile),intfile)
wend
close #intfile

--
Both of these should have no problems in a class as long as the file exists.
0
 

Expert Comment

by:CleanupPing
ID: 8531351
Hi Claypious,
This old question (QID 20567605) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 8543550
Actually, I think the points should have gone to hazgod since mine was only a minor expansion of that answer, so I created a points-Q for you:

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20619103.html
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question