Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reading one Char at a time

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

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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

636 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