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

x
?
Solved

Need Code To Run App

Posted on 1999-07-28
8
Medium Priority
?
176 Views
Last Modified: 2008-02-26
Need code showing how to run an application at a certain day/time. Don't know too much about programming and am using visual basic 5.0 If someone has some working code that would maybe shell the calc.exe program at a certain date/time I would appreciate it.
Thanks A lot. I used up all my points trying to find some code that did this but no working examples. I have 17 points left. Sorry !
Thanks
ssi49
0
Comment
Question by:ssi49
[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
  • 4
8 Comments
 
LVL 12

Accepted Solution

by:
mark2150 earned 40 total points
ID: 1528048
Running an app at a specific time can be problematic. You can't set your timer value too tight (ie, expect 1S resolution) because your program may or may not execute fast enough to get it. You also generally want to have a recursion interlock so if you set your value loose, like 09xx then you don't want it to refire every iteration between 09:00:00 and 09:59:59.

Generally I keep a var (usually from the registry) that lets me know LASTRUNDATE If that date is today, don't even bother the check the time.

If the date is past then look for the time (use datediff) difference to be positive and this will tell you that it's past your time to run. Now it's up to you if you want to run, say, an 0900 scheduled event if the program is started at, say, 1700. Me, I generally feel that if it's an hour past the scheduled time we're too late to start the run and should wait until next day.

Once you determine that you need to run, feed the current date back into the registry and then simply shell the desired task.

I use a timer value of at least 60000 to give one minute resolution. If that's too often then use a STATIC var in the timer routine and pull a MOD on it's value to decide how often to run (every ten minutes, etc.).

If this isn't sufficient detail for you to code I can cobble something up easy enough. I've written a couple of these.

M

0
 

Author Comment

by:ssi49
ID: 1528049
mark2150-thank you for your quick response. You are way over my head though. I understand some of what you are suggesting but to code it at my level would really be funny ! I am really really up on your offer to "cobble something up" for me as I'm sure that your cobble would work as mine would take 20 days and still not work. Please send the cobble stones to me and thank you very much.
ssi49
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1528050
Will do.

Ok, to get you started. Create a form. Drop on two text boxes and a timer control. One text box will be the time AlarmTime, one will be the program name ProgName. Make their .Text property's, say, 09:00 and CALCULATOR.EXE.

Go into the timer control and set the timers .interval to 60000 (once a minute)

Double click on the timer control and you should flip to the code page in the timer1_Timer() event.

Place this inside the event:

dim delta as double
dim lastrun as string

lastrun = GetSetting(App.CompanyName & "-" & App.EXEName, "Main", "LastRunDate", date)

if datediff( "d", lastrun, date) < 1 then exit sub

delta = datediff( "n", AlarmTime.Text, time)
if delta > 0 and delta < 60 then

   shell( ProgName.Text )
   SaveSetting App.CompanyName & "-" & App.EXEName, "Main", "LastRunDate", date
end if

This will check to see if the last run date was today and exit if so (no running twice!)

It then checks the time and if we're within an hour of the set time, we launch the task and update the last run date to today. This is all kept in the registry so no file handling is needed.

Anyway, if you put Timer1.Enabled = True in the Form_Load event, this will start the clock as your program starts to run.

Naturally you can get as fancy as you want with how to spec the program name and time and such, but this should help you down the correct path.

M



0
Independent Software Vendors: 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!

 

Author Comment

by:ssi49
ID: 1528051
mark2150-I did everything as per your instructions, I checked and double checked to make sure that everything was exactly as you stated. I then compiled the Program and ran it. It doesn't seem to launch the Calculator.exe
If I check the Registry to make sure that the information is retained what would I type under "find" in the Registry per your code:
lastrun = GetSetting(App.CompanyName & "-" & App.EXEName, "Main",
     "LastRunDate", date)
Would I type in "Main" or "LastRunDate" ?
Am I supposed to change any of this to reflect my compiled program code that you offered such as the (App.CompanyName) or something to this effect ?
As you can see, I'm not to advanced in visual basic !
Thanks for the effort on your part for a few lousy points...
ssi49
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1528052
Ummm, the code was pieced together from stuff I had on hand (cobbled). It was *NOT* designed to be a compiled program, but rather to be a testbed for you to experiment with.

The program defaults to assuming that it ran *TODAY* and therefore will wait until *tomorrow* to run again. You can change this by replacing the initial:

lastrun = GetSetting(App.CompanyName & "-" & App.EXEName, "Main", "LastRunDate", date)

with:

lastrun = GetSetting(App.CompanyName & "-" & App.EXEName, "Main", "LastRunDate", date -1 )

(I think that will work...)

Set a breakpoint inside the routine and SINGLE STEP (<F8>) thru the code and watch the values.

The app.CompanyName is set as part of the project properties and you should always set that and the various copyright/trademark and other settings to identify your prorgam.

To search the registry look for either. You can also look for the name of your .exe file. It'll be down in the software area under the Visual Basic area.

One helpful enhancement would be to add an additional text field - call it PastRun

Add the lines:

  me.caption = now

Put this at the top of the Timer1_Timer routine. And:

  PastRun.Text = lastrun

Put this after the GetSetting statement.

Read the help on all of these commands. This code was written off the top of my head and may not be perfect but is *damn close*.

M

0
 

Author Comment

by:ssi49
ID: 1528053
mark2150-Thank You for taking the time to submit the above. I will study everything as you suggested and figure out how to get everything to work. I am giving you your much deserved points and do appreciate all of your help!
Thanks
ssi49
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1528054
Thank you! Drop by the web page & say "Hi" in the guestbook. I've got a lot of odds 'n ends - most with full source. www.cyberchute.com/rvbus/madmark

M

0
 

Author Comment

by:ssi49
ID: 1528055
mark2150-Thank You again and I will visit your site right now !!!
ssi49
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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 trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…
Suggested Courses

670 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