Problem to open file

HuaMin Chen
HuaMin Chen used Ask the Experts™
on
Hi,
I get this problem
tt514.pngdue to last 2nd line below
    If Dir(File0) = "" Then
        Set f = fs.createtextfile(File0)
    Else
        Set f = fs.OpenTextFile(File0, 3, TristateFalse)
    End If

Open in new window

Why?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
Try with:
    ForAppending = 8
    TristateFalse = 0
    If Dir(File0) = "" Then
        Set f = fs.createtextfile(File0)
    Else
        Set f = fs.OpenTextFile(File0, ForAppending, TristateFalse)
    End If

Open in new window

/gustav
HuaMin ChenProblem resolver

Author

Commented:
Many thanks.
I want to further read all the lines, from the text file. Any example?
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
Oh, numerous - just bing/google on that.

/gustav
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

HuaMin ChenProblem resolver

Author

Commented:
Using these

    Dim fs, f
    Set fs = CreateObject("Scripting.FileSystemObject")
    File0 = ActiveWorkbook.Path & "\MonthStatus.txt"
    
    Dim iFile As Integer: iFile = FreeFile
    Open File0 For Input As #iFile
    Do Until EOF(1)
        Line Input #1, TextLine
        
        MsgBox TextLine
        If Trim(TextLine) <> "" Then
            ...
        End If
    Loop

Open in new window

I cannot read the lines inside the file. Why?
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
A little more precision is needed:
    Dim fs, File0, TextLine
    Set fs = CreateObject("Scripting.FileSystemObject")
    File0 = ActiveWorkbook.Path & "\MonthStatus.txt"
    
    Dim iFile As Integer: iFile = FreeFile
    Open File0 For Input As #iFile
    Do Until EOF(iFile)
        Line Input #iFile, TextLine
        
        MsgBox TextLine
        If Trim(TextLine) <> "" Then
        '    ...
        End If
    Loop

Open in new window

/gustav
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
Grade B? What was missing, please?

/gustav
Grade B? What was missing, please?

Again! The answer is NOT the problem!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial