Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: obtain text from a text file without losing white-

    Chris,

    To get your white space included, I think you must use the following :
    <pre> Line Input #intFile, str1</pre>

    That seems to work as Line Input reads a complete line of data as a single entity.

    Andrew

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: obtain text from a text file without losing white-

    Bingo Andrew! Thanks!

    Weird Help files is where I'll lay my blame today.

    I used to use "Line Input" in old Basics. This time around I went looking for "Input" and clicked on "See Also" and got not references to "Line Input"; gave it up as lost. Now I find that if I persist with "Line" I get there. Aaaaaaaaaaaaaaaaaaaaaaaaargh.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    obtain text from a text file without losing white-

    How can I obtain text from a text file without losing white-space?

    The block of text below is from an ASCII text file "Screenmanagement.bas" exported from Word97SR2VBA. I've inspected the file with List.com. Those are four genuine ASCII (020) codes that start the second line "Application.ScreenRefresh".

    <pre>Public Function ScreenPaint()
    Application.ScreenRefresh
    End Function
    Public Function boolSetScreen(boolTo) As Boolean
    boolSetScreen = Application.ScreenUpdating
    Application.ScreenUpdating = boolTo
    End Function
    Sub TESTboolSetScreen()
    MsgBox boolSetScreen(False)
    MsgBox boolSetScreen(True)
    MsgBox boolSetScreen(False)
    End Sub
    </pre>


    Below is my function to obtain successive lines of text. Each call to strGetFileLine delivers a line of text from the file above. The second call delivers me "Application.ScreenRefresh".

    <pre>Public Function strGetFileLine(intFile As Integer) As String
    Dim str1 As String
    Input #intFile, str1
    strGetFileLine = str1
    'Sub TESTstrGetFileLine()
    ' Dim intFile As Integer
    ' intFile = FreeFile
    ' Open "irocsex03.bas" For Input As #intFile
    ' If Not EOF(intFile) Then MsgBox strGetFileLine(intFile)
    ' If Not EOF(intFile) Then MsgBox strGetFileLine(intFile)
    ' If Not EOF(intFile) Then MsgBox strGetFileLine(intFile)
    ' If Not EOF(intFile) Then MsgBox strGetFileLine(intFile)
    ' If Not EOF(intFile) Then MsgBox strGetFileLine(intFile)
    ' If Not EOF(intFile) Then MsgBox strGetFileLine(intFile)
    ' Close #intFile
    'End Sub
    End Function
    </pre>


    Below you see the results of the Immediate Window with a breakpoint on the code line "strGetFileLine = str1". The length of str1 is 25 bytes, not 29 as I wanted. Those four leading spaces are gone. I'd like them not-gone, as I'd like to preserve the indenttaion for display.


    <pre>?str1
    Application.ScreenRefresh
    ?len(str1)
    25
    </pre>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •