|
-
July 26th, 2008, 03:49 PM
#16
Re: Finding strings in multiple files
Here's my very hastily thrown together solution - If you want anything explained, just asked. It only works for one file, but doubtless you can use the earlier advice to adapt it. It also will only work with the prototpye as you gave it in your last post. It isn't a very good solution over all (feel free to laugh at my attempt at error checking) but It should get the job done!
I copied your sample data into a text file, then tried this with:
Code:
Debug.Print Join(Form1.GetLinesAtLastTime("C:\text.txt"), vbNewLine)
As the debug window doesn't like arrays. It returned the correct data.
So, here we go!
Code:
Option Explicit
Private Type mTime
p1 As Integer
p2 As Integer
p3 As Integer
End Type
Private Function mTimeSame(ByRef mTime1 As mTime, ByRef mTime2 As mTime) As Boolean
mTimeSame = ((mTime1.p1 = mTime2.p1) And (mTime1.p2 = mTime2.p2) And (mTime1.p3 = mTime2.p3))
End Function
Private Function mTimeOneIsBigger(ByRef mTime1 As mTime, ByRef mTime2 As mTime) As Boolean
If mTime1.p1 > mTime2.p1 Then
mTimeOneIsBigger = True
ElseIf mTime1.p1 < mTime2.p1 Then
mTimeOneIsBigger = False
Else
If mTime1.p2 > mTime2.p2 Then
mTimeOneIsBigger = True
ElseIf mTime2.p2 < mTime2.p2 Then
mTimeOneIsBigger = False
Else
If mTime1.p3 > mTime2.p3 Then
mTimeOneIsBigger = True
ElseIf mTime1.p3 < mTime2.p1 Then
mTimeOneIsBigger = False
Else
mTimeOneIsBigger = False
End If
End If
End If
End Function
Public Function GetLinesAtLastTime(ByVal FileName As String) As String()
Dim mFile As Integer, Line As String
Dim Time As mTime, NewTime As mTime
Dim Parts() As String, Data As String
'Prototype: AAAAAA 1.1.1
mFile = freeFile
Open FileName For Input As #mFile
Do While Not EOF(mFile)
Line Input #mFile, Line
Parts() = Split(Line, " ")
If UBound(Parts) = 1 Then
Parts() = Split(Parts(1), ".")
If UBound(Parts) = 2 Then
NewTime.p1 = Parts(0)
NewTime.p2 = Parts(1)
NewTime.p3 = Parts(2)
Else
Err.Raise 1342, "Some Code", "ASGEGWRH!"
Else
Err.Raise 1342, "Some Code", "ASGEGWRH!"
End If
Parts = Split(Line, " ")
If mTimeSame(Time, NewTime) Then
Data = Data & ";" & Parts(0)
ElseIf mTimeOneIsBigger(NewTime, Time) Then
Time = NewTime
Data = Parts(0)
End If
Loop
Close #mFile
GetLinesAtLastTime = Split(Data, ";")
End Function
Hope that's of some help!
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
*Guarantee may not be honoured.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|