-
Hi I need to check that the number of lines produced in a .dat file is the same as the number of records in a access db table.
I just want to open the .dat file and count the lines. I tried this but it got stuck in a loop. Why ?
what did I do wrong.
Private Sub Command1_Click()
Dim filenum As Integer
Dim num As Long
filenum = FreeFile
num = 0
Open "c:\store\imascons.dat" For Input As #filenum
Do Until EOF(filenum)
num = num + 1
MsgBox num
Loop
Close filenum
MsgBox num
End Sub
This didnt work , anyone ?
Thx locutus
-
Looks like you need to read the file in order to get the pointer to move through it. Otherwise it will just count forever.
-
Don't know...
Try this....
Code:
filenum = FreeFile
num = 0
strVar = ""
Open "c:\store\imascons.dat" For Input As #filenum
Do While Not EOF(filenum)
LineInput #1,strVar
num = num + 1
MsgBox num
Loop
Close filenum
MsgBox num
Just a shot.
-
Count Lines
This will work definatly
Dim FileNumber As Integer
Dim FilePath As String
Dim LineCount As Integer
Dim Data As String
' Initialisation
LineCount = 0
FilePath = "C:\Filename"
FileNumber = FreeFile
' Open the file
Open FilePath For Input Access Read As #FileNumber
' Parse the file
Do Until EOF(FileNumber)
Line Input #FileNumber, Data
LineCount = LineCount + 1
Loop
Close #FileNumber