Solved

Reading one Char at a time

Posted on 2003-12-11
4
376 Views
Last Modified: 2010-05-01
Is threre any function or any way to read one char at a time from a text file rather than
"Line Input # Statement" which reads one line?
0
Comment
Question by:fh2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 9923297
you cant
but if you want

you can read in the string and then parse it

Mid(StrFile,5,1) this gets the 5th character

so you can loop through it also

for i = o to len(strfile) -1
      debug.print "Character " & i  & " = " & mid(strfile,i,1)
next

0
 
LVL 3

Accepted Solution

by:
Egore earned 100 total points
ID: 9923377
Use:

Dim C As String
C = Input(1, #FileNum)

The VB6 help file gives this example:

Dim MyChar
Open "TESTFILE" For Input As #1   ' Open file.
Do While Not EOF(1)   ' Loop until end of file.
   MyChar = Input(1, #1)   ' Get one character.
   Debug.Print MyChar   ' Print to the Immediate window.
Loop
Close #1   ' Close file.
0
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 9923922
Be aware that reading a file character by character is probably about the slowest way possible to read a file, by a large margin. If your file is even moderately sized, you are better reading it line by line, or by block or something, and then in your program reading the individual characters.

Zaphod.
0
 
LVL 3

Expert Comment

by:Egore
ID: 9924050
fh2,

Thanks for the prompt attention to the question!  I'm glad to have helped.

Z_Beeblebrox makes a very good point, though.  Using:

MyString = Input(LOF(FileNum), #FileNum)

to read in the whole file, and then parsing it like Mikal613 suggested is typically a much faster way.  But I don't know your requirements and reading it one character at a time may be the best solution for you (so that you don't have to read in the whole file before you can process it).

Best of luck to you.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now