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

x
?
Solved

Loop within a loop

Posted on 2008-09-29
1
Medium Priority
?
302 Views
Last Modified: 2013-11-25
I have the following script that checks a folder every 10 minutes and then emails us if the folder has more than 500 files.

What I want to do is embed another loop that checks again to see if there are less that 200 files.

The idea being, it sends us an email if there are more than 500 files, but then won't send us any more emails until the file count has dropped below 200 and then raised back above 500 again.

Can anyone help me?


Andrew
strComputer = "lang-apps"
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
Do While True
    Set colFileList = objWMIService.ExecQuery _
        ("ASSOCIATORS OF {Win32_Directory.Name='D:\Mandata\WebInterface\Exports'} Where " _
            & "ResultClass = CIM_DataFile")
 
    		If colFileList.Count >= 500 Then
 
			Set objEmail = CreateObject("CDO.Message")
			objEmail.From = "WEB_INTERFACE"
			objEmail.To = "it@xxxx.co.uk"
			objEmail.Subject = "WEB INTERFACE"
			objEmail.Textbody = "There are " & colFileList.Count & " items in the Exports folder on Lang-Apps!       \\lang-apps\Mandata\WebInterface\Exports"
			objEmail.Configuration.Fields.Item _
			 ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
			objEmail.Configuration.Fields.Item _
			 ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
			"192.168.73.112"
			objEmail.Configuration.Fields.Item _
			 ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
			objEmail.Configuration.Fields.Update
			objEmail.Send
 
    		End If
 
    Wscript.Sleep 600000
 
Loop

Open in new window

0
Comment
Question by:spen_lang
[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
1 Comment
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 1000 total points
ID: 22596085
Not so difficult. Simply control the state of the sent email via a switch variable. The switch represents if an e-mail has sent, and logically initializes to False. When reached the 500 files, the e-mail is sent and the switch switches to true. If in another loop iteration there are 500 or more files yet, it don't send the e-mail because the switch variable is set to True. The switch only will become false when there are 200 or less files.
strComputer = "lang-apps"
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
bSwitchEmail = False 
Do While True
    Set colFileList = objWMIService.ExecQuery _
        ("ASSOCIATORS OF {Win32_Directory.Name='D:\Mandata\WebInterface\Exports'} Where " _
            & "ResultClass = CIM_DataFile")
                If (colFileList.Count < 200) And (bSwitchEmail = True) Then
                        bSwitchEmail = False
                ElseIf colFileList.Count >= 500 Then
                        If bSwitchEmail = False Then
                                Set objEmail = CreateObject("CDO.Message")
                                objEmail.From = "WEB_INTERFACE"
                                objEmail.To = "it@xxxx.co.uk"
                                objEmail.Subject = "WEB INTERFACE"
                                objEmail.Textbody = "There are " & colFileList.Count & " items in the Exports folder on Lang-Apps!       \\lang-apps\Mandata\WebInterface\Exports"
                                objEmail.Configuration.Fields.Item _
                                 ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
                                objEmail.Configuration.Fields.Item _
                                 ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
                                "192.168.73.112"
                                objEmail.Configuration.Fields.Item _
                                 ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
                                objEmail.Configuration.Fields.Update
                                objEmail.Send
                                bSwitchEmail = True
                        End If
                End If
 
    Wscript.Sleep 600000
 
Loop

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

705 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