Solved

"DateCreated" Script returning incorrect values

Posted on 2008-10-15
7
364 Views
Last Modified: 2012-05-05
Basically I am having to write a "work-around" script for some Software an Insurance House has provided us with that is playing up. So while they work on a proper fix I have thought of a work around to the problem.

Basically what is happening is their print monitor is crashing, the best way to solve this is to close it and restart the program which then starts pushing the documents through. This print monitor stores the documents in the Doc & Settings/App Data/%username%/....... area.

I am writing a script so that when a file in that folder is over 2 minutes old it automatically kills the print processor and then restarts it. This is to make sure that the document does get forced through.

The problem I have is no matter what I do the attached code counts the amount of files in the folder even if they were JUST created, and not over 2 minutes old. I think I need a set of far more experienced eyes to see if I am doing anything wrong, I am very new to this so I may have mis-understood something or overlooked something simple for that I apologise if so.

Cheers.
Set colFiles = oFolder.Files
      nFiles = colFiles.Count
 
      For Each oFile In colFiles
         If DateDiff("s", oFile.DateCreated, Now()) >= 120000 Then   '-- ensure file is at least 2 minutes old
         nFiles = colFiles.Count - 1                     '-- to avoid COUNTING NEW FILES
         End If
      Next

Open in new window

0
Comment
Question by:ADT58
  • 4
  • 2
7 Comments
 
LVL 29

Expert Comment

by:Badotz
ID: 22721291
If the date created is greater than 120000, you subtract 1 crom the count of files. This is the problem. Try this:

If DateDiff("s", oFile.DateCreated, Now()) <= 120000 Then   '-- ensure file is at least 2 minutes old
0
 

Author Comment

by:ADT58
ID: 22721555
nope still counting files, that have JUST been created and not files that are over 2 minutes (120000 seconds) old. :( can't get my head around this.
0
 
LVL 29

Accepted Solution

by:
Badotz earned 25 total points
ID: 22721726
Do this:

If DateDiff("s", oFile.DateCreated, Now()) <= 120000 Then
    MsgBox oFile.DateCreated & vbCrLf & Now() & vbCrLf & DateDiff("s", oFile.DateCreated, Now())
    nFiles = colFiles.Count - 1
End If

See if you can determine anything from that.

Alternatively, you could step through the code with a debugger and examine things during run-time.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 18

Assisted Solution

by:exx1976
exx1976 earned 25 total points
ID: 22722023
This is an easy one.  :-)  Here's the solution:


Set colFiles = oFolder.Files
nFiles = 0
For Each oFile In colFiles
    If DateDiff("s", oFile.DateCreated, Now()) >= 120000 Then nFiles = nFiles + 1
Next
wscript.echo(nFiles)


The way it was written, it would ALWAYS return the number of files, minus one.  you weren't actually decrementing your counter, you were just always setting it to colfiles.count - 1


Give this a shot and let us know.  It should spit out the number of files older than 2 minutes.

-exx
0
 
LVL 29

Expert Comment

by:Badotz
ID: 22722115
Well, DUH on me ;-)
0
 

Author Comment

by:ADT58
ID: 22722164
Well at first thanks to Badotz I realised that I was trying to count the impossible with the DateDiff, I think because I was asking it to work out the Different Betwen xx/xx/xx xx:xx:xx and xx/xx/xx xx:xx:xx, I was asking it to work it all out by seconds (120000) instead I changed the "s" to "m" and worked it out by stating:

If DateDiff("m", oFile.DateCreated, Now()) >= 2

So Badotz made me realise something I was completely overlooking and then yours exx was a complete solution obvious on the fact I changed the "s" to "m" and the 120000 to 2 again and it works fine.

Cheers to you both, not only do I have a solution but I also learned something which was a win win.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 22722252
Strive to learn one new thing a day, I always say. Good job!

Oh, and no worries - glad to help.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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