?
Solved

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

Posted on 2003-03-29
4
Medium Priority
?
154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

770 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