Solved

How to get a VB Script Do Until Loop to end at a time.

Posted on 2009-05-07
7
1,006 Views
Last Modified: 2013-12-26
I am new to using any script and I am trying to set up a VB script in IBM Client Access to run a script that could be started at any time in the morning but I will want it to run until 7:45 am the next morning. We have an update that runs at 8:00 and the script needs to stop running before then. Below is what I have been trying. The problem is that it does not stop and my logic will not work because of the fact that the loop will be started one morning and then ending the next. The starting time will already be greater than the ene time. Help
Dim StartTime
Dim CurrTime
Dim EndTime
 
StartTime=Time()
EndTime="07:45:00"
 
Do
 
Any coding in loop
 
   CurrTime=Time()
 
Loop until (CurrTime>=EndTime)

Open in new window

0
Comment
Question by:maddencoman
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 9

Expert Comment

by:CCongdon
ID: 24327659
Will this do what you need?

Dim StartTime
Dim StartDate
Dim CurrTime
Dim CurrDate
Dim EndTime
 
StartTime=Time()
StartDate=Date()
EndTime="07:45:00"
 
Do
 
Any coding in loop
 
   CurrTime=Time()
   CurrDate=Date()
 
Loop until (CurrDate > StartDate AND CurrTime>=EndTime)

Open in new window

0
 

Author Comment

by:maddencoman
ID: 24328229
I made a minor adjustment to try to test it with a few minutes ahead of the current time, but I still can't get the script to end. I have attached the entire script to see if I am missing anything. I apoligize, I am very new to scripts with no background or training except for some research on the internet on my own. I am sure I am probably missing something very basic, but I can't figure it out. Basically this is a short script to sign on to a 5250 emulation session, start a program and refresh the screen every 30 seconds until I want it to end. Thanks
[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)
 
REM This line calls the macro subroutine
subSub1_
 
sub subSub1_()
   autECLSession.autECLOIA.WaitForAppAvailable
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "u002mark"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[field+]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "mark"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[field+]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.WaitForAttrib 1,1,"20","3c",3,10000
 
   autECLSession.autECLPS.Wait 1500 
 
   autECLSession.autECLOIA.WaitForAppAvailable
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.WaitForAttrib 5,1,"00","3c",3,10000
 
   autECLSession.autECLPS.WaitForCursor 5,2,10000
 
   autECLSession.autECLOIA.WaitForAppAvailable
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "1"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.WaitForAttrib 7,2,"00","3c",3,10000
 
   autECLSession.autECLPS.Wait 3000 
 
Dim StartTime
Dim StartDate
Dim CurrTime
Dim CurrDate
Dim EndTime
 
StartTime=Time()
StartDate=Date()
EndTime="12:19:00"
 
Do
 
   autECLSession.autECLOIA.WaitForAppAvailable
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[pf5]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.WaitForAttrib 7,2,"00","3c",3,10000
  
   autECLSession.autECLPS.wait  30000
 
   CurrTime=Time()
   CurrDate=Date()
 
 
Loop until (CurrDate = StartDate AND CurrTime>=EndTime)
 
end sub

Open in new window

0
 
LVL 9

Accepted Solution

by:
CCongdon earned 250 total points
ID: 24328647
Your code differs in one important respect from mine...

You put:
Loop until (CurrDate = StartDate AND CurrTime>=EndTime)
 
Should be:
Loop until (CurrDate > StartDate AND CurrTime>=EndTime)

Open in new window

0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 3

Assisted Solution

by:EverLearningCodeMonkey
EverLearningCodeMonkey earned 250 total points
ID: 24329040
Hi maddencoman,

Something that should be considered is the format of your date/time variables.

Date() and Time(), I believe, return date and time variables, whereas EndTime is defined as a string.  You should probably put CDate() around the string for EndTime to ensure that it's treated properly.

Either that or use the # as delimiters, this should define it as a Date subtype instead of a string.

You may want to look at putting your script/application to sleep by leveraging kernel32 as per this article: http://www.developerfusion.com/code/119/put-your-vb-application-into-deep-sleep/

I know it works for applications, not sure about scripts, but it's worth checking out - that way your script isn't constantly checking date & time as fast as it can go, but rather runs, checks date & time, sleeps for a bit, wakes up and repeats until completion.

StartTime=Time()
StartDate=Date()
EndTime = CDate("07:45:00")
 
' Or Define EndTime this way
EndTime = #07:45:00#

Open in new window

0
 

Author Comment

by:maddencoman
ID: 24329053
I made the change to test it only. I was trying to put an end time of about five minutes after I started the script to test it. Shouldn't have that of worked for a test?
0
 

Author Closing Comment

by:maddencoman
ID: 31579081
Your help was greatly appreciated. Thanks again.
0
 
LVL 3

Expert Comment

by:EverLearningCodeMonkey
ID: 24329376
No problem,

Glad to be of help.

ELCM
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

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…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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
Course of the Month8 days, 11 hours left to enroll

617 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