Solved

Input #1 won't bring in the entire line

Posted on 2003-12-10
9
660 Views
Last Modified: 2010-05-01
I have a simple, but LARGE text file that I'd like to weed through automatically (using VB).
Basically, it's a log listing of certain files on my servers.
What I'd like to do is step through the log and check two lines, keeping them both in another file, if line 2 meets certain criteria.

Sample of my log:
------------------------------------------------------
Directory of \\FileServer5\Marketing\Photos\

04/09/1999  11:42 AM            32,768 OurTrip.jpg
--------------------------------------------------------

Now, if OurTrip.jpg exceeds 100,000,000, I want to make note of that in another file.

The problems I have are:
1> My log isn't consistent.  Sometimes, I'll have the first line, but not the second (for whatever reason, my script didn't pull the file info, I suppose).  So, if the second line (acutally the 3rd, cause there is a blank space between each line), is empty, I want to discard that entry and move on.

2> I've tried to pull the file in using the following code:
   Open "C:\files.log" For Input As #1
      Do While Not EOF(1)
        Input #1, mystring
        If Left(Trim(mystring), 15) = "Directory of \\" Then dirRoutine (mystring)
'****
      Loop
   Close #1
End Sub

The comment line '**** is where I'd like to check the size, but after the first loop, it only reads in "4" for that second line.  If I add a second variable to the input line, it will also pull in 11 from that second field, but I can't get it to pull in the entire line into one string - why not??

Can what I want to do, be done?
Should I go about it another way?

TIA!
~sirbounty
0
Comment
Question by:sirbounty
  • 5
  • 4
9 Comments
 
LVL 14

Expert Comment

by:aelatik
ID: 9913777
Line Input #1, mystring

instead of

Input #1, mystring
0
 
LVL 14

Expert Comment

by:aelatik
ID: 9913816
This would be the whole picture :

Open "C:\files.log" For Input As #1
      Do While Not EOF(1)
       Line Input #1, mystring
        If Left(Trim(mystring), 15) = "Directory of \\" Then dirRoutine (mystring)
'****
      Loop
   Close #1
End Sub
0
 
LVL 67

Author Comment

by:sirbounty
ID: 9913825
That works much better - thanx.
Is there a for me to break down line 2 so that I can assign a variable to the date (the 1st part), time (2nd), size (3rd) and filename (which may include spaces...)
0
 
LVL 14

Expert Comment

by:aelatik
ID: 9914126
What exactly is the contruction of you log file. What do you use as seperators ?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Accepted Solution

by:
aelatik earned 350 total points
ID: 9914204
This will work on the sample log you posted, but if other logs have different formats it won't work

Private Sub Form_Load()
Dim vDate, vTime, vSize, vFile, buffer
Open "C:\files.log" For Input As #1
      Do While Not EOF(1)
       Line Input #1, MyString
        buffer = Split(MyString, "            ")
        If UBound(buffer) = 1 Then
            vDate = DateValue(buffer(0))
            vTime = TimeValue(buffer(0))
            vSize = Split(buffer(1), " ")(0)
            vFile = Split(buffer(1), " ")(1)
            MsgBox vDate
            MsgBox vTime
            MsgBox vSize
            MsgBox vFile
        End If
      Loop
   Close #1
End Sub
0
 
LVL 67

Author Comment

by:sirbounty
ID: 9914252
It's just the one log file.  Format should be the same.  I should be able to get it from here.  I'll let you know shortly.
Thanx for the help!!!
0
 
LVL 67

Author Comment

by:sirbounty
ID: 9914832
aelatik, this is perfect!
Can you perhaps give me a brief description of split and buffer? (or a web ref).
I'm taking my 3rd course in VB, but I've taken so much time over the holidays (and then some) away from it, that I think I've lost a bit.  Although, I don't recall these commands, but we're mostly working with ADO stuff. . .

Thanx again!
0
 
LVL 14

Expert Comment

by:aelatik
ID: 9915844
First of all, buffer doesnt mean a thing. Its a simple variable declaration.

The Split() function will split a given string to an array, you can set the delimeter yourself.

Example :

S = "1;2;3;4;5"
F = Split(S,";")

The results are as following :

F(0) = 1
F(1) = 2
F(2) = 3
F(3) = 4
F(4) = 5

example : msgbox F(0)

or a for each loop

For each X in F
 msgbox X
next
0
 
LVL 67

Author Comment

by:sirbounty
ID: 9916919
So it creates an array - great.  Thanx again!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 113
Excel VBA, find a string in a column, update a cell 7 64
Visual Studio 2005 text editor 10 33
TT Auto Dashboard 13 79
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now