FileSearch

bjackson

Registered User.
Local time
Today, 09:00
Joined
Jan 3, 2003
Messages
404
i am trying to open a file to which has some cnc machine data
in it,but cant seem to crack why or what i am doing wrong

i need to open this file and search for data that confirms that the
machine has actually performed its task.

i have 2 questions

1.what is the most efficient way to search the data in the file

2. how do you open the file for reading the data

here is the code i am using to open the file which does have
data in it.The code opens the file but seems to think thats its empty.Any help greatly appreciated


On Error GoTo HandleErr:
Dim Folderspec As String
Dim Mychar
Folderspec = DLookup("[ProjectPath]", "ProjectPath", "[id] =" & 10)

With Application.FileSearch
.NewSearch
.LookIn = Folderspec
.SearchSubFolders = True
.FileName = "C14200.r41"
.MatchTextExactly = True
If .Execute > 0 Then
Open .FileName For Output Shared As #1
Do While Not EOF(1) ' Loop until end of file.
Input #1, Mychar
Debug.Print Mychar
Loop

Close #1

End With
ExitHere:
Exit Sub

HandleErr:
If err.Number = 53 Then
JobFound = False
Resume ExitHere:
Else
MsgBox err.Description & err.Number
Resume ExitHere:
End If
 
Why are you opening the file for output if you are trying to read it?
Is this a text file (no binary data).
 
i am trying to read the file, i have tried output,input,random
, i may have forgot to change output the last time, it just doesnt
seem to make a difference, when you step through the code
it finds the file,opens it then jumps to eof and closes the file
i am not sure of the difference between binary and text.To read it without using code you have to select to open it in notepad

the file contains data
eg.
1st line
[stk1]
2nd line
plabel=1
3rd line
rc14200
it contains maybe 1000 lines of numerous text and characters
i need to search the file to find plabel=1 to know that the
piece of laminate has been cut.

i need a way to search the file as effeciantly as possible as
there may be 50 files with up to 2000 lines to search



thank you for your interest,have you any suggestions
 
Well since you did not specify a datatype on MyChar, I beleive it defaults to variant. However maybe you would better off using Line Input and parsing the line instead. input would look for either the length of the receving variable or a comma to read from the input. Try:
Open .FileName For Input Shared As #1
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, Mychar

See if that helps any.
 
line input does the job, i can at least open the file and read it,
thanks for the help

now i get to question 2

do you have to read every line to find plabel=1 or is their a function that can be used to search the file.In notepad you can use find and its very quick,in access reading every line is very slow
 

Users who are viewing this thread

Back
Top Bottom