Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is the txt free to write....

Status
Not open for further replies.

2009luca

Programmer
Jul 27, 2013
222
IT
A Host procedure save a "big" txt file in C:\mydir\test.txt

I need to "loop" around the txt file, and check if the save operation is complete.

Possible?

In effect check whe i can read and write into the txt file.
 
Have the writer open the file with exclusive access.

Code:
Option Explicit

Private F As Integer
Private I As Long

Private Sub Form_Load()
    On Error Resume Next
    Kill "file.txt"
    On Error GoTo 0
    F = FreeFile(0)
    Open "file.txt" For Output Lock Read Write As #F
    Timer1.Interval = 100
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    I = I + 1
    Print #F, I
    If I >= 100 Then
        Timer1.Enabled = False
        Close #F
        Unload Me
    End If
End Sub

Code:
Option Explicit

Private Sub Form_Load()
    Timer1.Interval = 500
    Timer1.Enabled = True
End Sub

Private Sub Form_Resize()
    If WindowState <> vbMinimized Then
        'Text1 is a multiline TextBox:
        Text1.Move 0, 0, ScaleWidth, ScaleHeight
    End If
End Sub

Private Sub Timer1_Timer()
    Dim F As Integer
    Dim I As Long
    
    F = FreeFile(0)
    On Error Resume Next
    Open "file.txt" For Input As #F
    If Err Then
        Text1.SelStart = &H7FFF
        Text1.SelText = "Poll" & vbNewLine
    Else
        On Error GoTo 0
        Timer1.Enabled = False
        Do Until EOF(F)
            Input #F, I
            Text1.SelStart = &H7FFF
            Text1.SelText = CStr(I) & vbNewLine
        Loop
        Close #F
        Text1.SelStart = &H7FFF
        Text1.SelText = "Complete"
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top