Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

"DateCreated" Script returning incorrect values

Posted on 2008-10-15
7
Medium Priority
?
370 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 100 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Assisted Solution

by:exx1976
exx1976 earned 100 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

704 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