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

This routine work only with a small file !?

Status
Not open for further replies.

desprits

Programmer
Feb 14, 2004
40
CA
This routine does not work when I fact with a big file (the routine is only once executed and goes out at once of Do While) but with a smaller file that works. Why?

Private Sub cmdTriTemps_Click()
Dim TextLine
Dim LoginUtilisation As String
Dim IpInfoUtilisation As String
Dim DateUtilisation As String
Dim HresDebutUtilisation As String
Dim HresFinUtilisation As String
Dim TempsUtilisation As String

Open "c:\temps" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, TextLine ' Read line into variable.
LoginUtilisation = Mid(TextLine, 1, 18)
LoginUtilisation = Replace(LoginUtilisation, " ", "")
IpInfoUtilisation = Mid(TextLine, 19, 20)
DateUtilisation = Mid(TextLine, 45, 10)
HresDebutUtilisation = Mid(TextLine, 56, 5)
HresFinUtilisation = Mid(TextLine, 64, 5)
TempsUtilisation = Mid(TextLine, 72, 5)
If Mid(DateUtilisation, 10, 1) = "7" Then
If HresFinUtilisation = "still" Then ' Cela signifie que l'usager
' est encore en mode connection
Else
adoTriTemps.Recordset.AddNew
adoTriTemps.Recordset!LoginUtilisation = LoginUtilisation
adoTriTemps.Recordset!IpInfoUtilisation = IpInfoUtilisation
adoTriTemps.Recordset!DateUtilisation = DateUtilisation
adoTriTemps.Recordset!HresDebutUtilisation = HresDebutUtilisation
adoTriTemps.Recordset!HresFinUtilisation = HresFinUtilisation
adoTriTemps.Recordset!TempsUtilisation = TempsUtilisation
adoTriTemps.Recordset.Update
adoTriTemps.Recordset.Requery
adoTriTemps.Refresh
End If
End If
Loop
test = EOF(1)
Close #1 ' Close file.
End Sub
 
Maybe you have an error, you dont seem to have an error handler rtn. Add 'On error goto ErrorRtn' at the start, then show any errors in the rtn.

Another thought is it a standard text file - has each line has cr/lf terminator ?
 
I do not see any issue in the code which would cause an early exit, so the problem must be in the data.

I did 'simplify' the procedure by replacing the assignments of variables to the recordset with their string parse equivalets, and save some typing (future reference to other code) by use of hte With / End With structure. A minor issue with the file handle in the use of a 'literal' value was changed to the more common approach of getting an available handle through the intrinsic function "FreeFile". The overall procedure process should not have changed with these modifications, however you might want to review it as an illustration of some easier approaches to writting procedures which could save some (typing) time and -perhaps- make your code easier to read.


Code:
Private Sub cmdTriTemps_Click()

    Dim TextLine As String
    Dim MyFil As Integer

    MyFil = FreeFile

    Open "c:\temps" For Input As #MyFil                 ' Open file.

    Do While Not EOF(MyFil)                             ' Loop until end of file.

        Line Input #MyFil, TextLine                     ' Read line into variable.

        If (Mid(TextLine, 51, 1) = "7") Then

          If (Mid(TextLine, 64, 5) <> &quot;still&quot;) Then     ' Cela signifie que l'usager
                                                        ' est encore en mode connection

              With adoTriTemps.Recordset
                .AddNew
                    !LoginUtilisation = Replace(Mid(TextLine, 1, 18), &quot; &quot;, &quot;&quot;)
                    !IpInfoUtilisation = Mid(TextLine, 19, 20)
                    !DateUtilisation = Mid(TextLine, 45, 10)
                    !HresDebutUtilisation = Mid(TextLine, 56, 5)
                    !HresFinUtilisation = Mid(TextLine, 64, 5)
                    !TempsUtilisation = Mid(TextLine, 72, 5)
                .Update
                .Requery            'Take this out of the loop
                .Refresh            'And this one also
              End With

            End If

        End If

    Loop

    test = EOF(MyFil)       'Unless 'test' is a module level or global variable, _
                             this is useless.

    Close #MyFil    ' Close file.

End Sub






MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top