×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

is the txt free to write....

is the txt free to write....

is the txt free to write....

(OP)
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.

RE: is the txt free to write....

Have the writer open the file with exclusive access.

CODE --> Project1

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 --> Project2

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close