?
Solved

Reading one Char at a time

Posted on 2003-12-11
4
Medium Priority
?
393 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
[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 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 300 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses

762 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