VBA not respecting leading white space when reading text files

mdlueck

Sr. Application Developer
Local time
Today, 17:56
Joined
Jun 23, 2011
Messages
2,650
Greetings,

With Access 2007 on Windows XP, VBA is being over helpful it clearing leading white space from lines it reads from a text file. Basically I have the following code, only in a multi-method class file, so I am copying / pasting into an inline rendition here:

Code:
  'Obtain a FileNumber for this class instance
  FileNumber = FreeFile

Open FileName For Input As FileNumber

  'Make sure the read buffer is empty to start with
  strFileReadBuffer = ""

  'Read the entire file into memory
  Do While Not EOF(FileNumber)
    Input #FileNumber, strThisLine
    'Append this new data to the previos data, and append a CR/LF
    strFileReadBuffer = strFileReadBuffer & strThisLine & vbCrLf
  Loop

Close #FileNumber
I stepped through the FileRead function, and the value in the strThisLine has the leading white space stripped. Whitespace formatting is critical for data understandability!

Is there a way to instruct VBA not to be "so helpful"?
 
Last edited:
Try This:

Line Input #FileNumber, strThisLine
 
That solved the nasty space eating behavior! :)

Thank you, mdow!
 
i am new to access and would like to build small applications using vba. would like to know if there is a site to learn vba step by step from the basics moving up. a quick reply would be great.
 
vba step by step tutorial from basics moving up

Would be grateful if someone can suggest a site or send me a tutorial to learn vba from the basics moving up. Thanks
 

Users who are viewing this thread

Back
Top Bottom