PDA

Click to See Complete Forum and Search --> : reading one character from a file at a time


aussiejoe
Jan 24th, 2000, 04:02 PM
i wish to open a file in binary mode (so i can read each character at a time, including EOF, CR, LF etc) using a Do Until EOF loop.
i think i am supposed to use GET but i am not sure how to read a single character, i can read the whole file at once, but this is not what i want to do. thanks in advance

DiGiTaIErRoR
Jan 24th, 2000, 05:22 PM
Reading the whole file then using a string function would be faster i.e.

'LoadFile here
TheFileContents = 'What's in the file
For x = 1 to len(TheFileContent)
TheChr = mid$(TheFileContent,x,1)
'Things you want to do with this character
Next x

Hope I helped,


------------------
DiGiTaIErRoR
VB, QBasic, Iptscrae, HTML
Quote: There are no stupid questions, just stupid people.

aussiejoe
Jan 24th, 2000, 05:57 PM
sorry, i didnt explain why i cant do that, i have to do it one byte at a time.. because i will be reading large files (ie > 50 MB) and these will not all fit into one string, they may fit in a variant but i am not willing to use all the ram that way ;)

Jan 25th, 2000, 04:12 AM
You could declare a user defined type of one string character

Type OneChar
OneByte As String * 1
End Type


Then you could open the file for random and access it one character at a time:

Dim iChar As OneChar
Dim iFileNum As Integer
Dim iRecLength As Long
Dim iLastRec As Long

iRecLength = Len(iChar)
iFileNum = FreeFile
Open "yourfile.txt" For Random As iFileNum Len = iRecLength
iLastRec = FileLen("yourfile.txt") / iRecLength



Then you loop through the records(actually characters) using the Get Statement.


For x = 1 To iLastRec
Get #iFleNum, x, iChar
Next x


Hope that works..

------------------
Boothman
There is a war out there and it is about who controls the information, it's all about the information.

[This message has been edited by Boothman_7 (edited 01-25-2000).]

aussiejoe
Jan 25th, 2000, 06:04 AM
will that method work with binary access? because if i open it with random i will not be able to read EOF, of which there will be several scattered through the file.

aussiejoe
Jan 26th, 2000, 03:38 PM
tried to do a
Dim MyVar as OneByte
didnt work ;P