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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write details to a text file after replacing and updating 2

Status
Not open for further replies.

ems

Programmer
Mar 23, 2001
13
IE
Hi,

i am working with a text file which isn't delimited by zeros.I want to go and search for the correct record, and then replace a piece of the string with something.
I have the string being replaced but the details aren't getting written back to the text file.
here is my code. i know i'm missing something in the IF statement. Any ideas.
Thanks Ems

Open Reports For Input As #3


Do Until EOF(3)
Line Input #3, TotalDetails
nUserName = Mid(TotalDetails, 1, 15)
nUserName = Trim(nUserName)

If (nUserName = frmStudentLogin.UserName) Then
Mid(TotalDetails, 57, 2) = Val(Quiz1Counter)


End If
Loop
Close #3
 
You can't write anything to your Reports file, first of all, because you opened it "For Input". You could write to it if you opened it "For Binary", but you have to use Get and Put statements instead of Line Input.

Instead, what you should do it write out a second file containing the changed data. Make your code something like this:
Code:
    Open Reports For Input As #3
    Open ReportsOut For Output As #4        
   
    Do Until EOF(3)
        Line Input #3, TotalDetails
        nUserName = Mid(TotalDetails, 1, 15)
        nUserName = Trim(nUserName)
             
        If (nUserName = frmStudentLogin.UserName) Then
            Mid(TotalDetails, 57, 2) = Val(Quiz1Counter)
        End If
        Write #4, TotalDetails
    Loop

    Close #3
    Close #4
Rick Sprague
 
Thanks Rick.
This works well.
Ems
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top