|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
read whole file at onceHello,
Can anyone tell me how to read a file (text or otherwise) into a buffer so that the whole file ends up in the buffer, instead of reading it line by line? "Robert Dormer" <r.dor***@www.digdevinc.com> wrote in message Here's a snippet from one of my projects. You'll need to declare thenews:%234M6ej6vFHA.3452@TK2MSFTNGP14.phx.gbl... > Hello, > > Can anyone tell me how to read a file (text or otherwise) into a buffer so > that the whole file ends up in the buffer, instead of reading it line by > line? > > variable first. ' Open the file to be parsed. iFileNum = FreeFile Open strPath & strFileName For Binary As #iFileNum ' Get the file information. str = Space(LOF(iFileNum)) Get #iFileNum, , str ' Done with the file so close it. Close #iFileNum Jim Edgar > Can anyone tell me how to read a file (text or otherwise) into a buffer so These functions will read a file into a string or byte array respectively:> that the whole file ends up in the buffer, instead of reading it line by > line? '*** Private Function FileToString(ByRef inFile As String) As String Dim FNum As Integer FNum = FreeFile() Open inFile For Binary Access Read Lock Write As #FNum FileToString = Space$(LOF(FNum)) Get #FNum, , FileToString Close #FNum End Function Private Function FileToBuf(ByRef inFile As String, ByRef OutBuf() As Byte) As Long Dim FNum As Integer FNum = FreeFile() Open inFile For Binary Access Read Lock Write As #FNum FileToBuf = LOF(FNum) ReDim OutBuf(0 To FileToBuf - 1) As Byte Get #FNum, , OutBuf() Close #FNum End Function '*** The latter would be faster (and more appropriate for binary data), but it really depends on what you want to do with it. Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/
Personal function library
Normalizing data for quick extraction - ideas? Question about thread safety... Multiple exe instances by version HELP! Menu commands - Cut, Copy, Paste, & Find Winsock API callback events Autosizing ListView columns Properties Dialog box GONE MISSING Minimised Application Not Restoring or Maximising outlook-like application |
|||||||||||||||||||||||