Topic Options
#1376 - 07/16/03 02:19 PM Chapter 01 – Hello World!
Luke Tomasello Administrator Offline
Member

Registered: 09/17/00
Posts: 740
Loc: San Jose, CA., USA
Welcome to the TaskGhost Tutorial.

In this first chapter of the Tutorial, we will present the quintessential ‘Hello World’ program.

When talking about TaskGhost ‘programs’, we are actually talking about scripts, or jobs.

Go to the TaskGhost\Scripts directory and create a file called HelloWorld.vbs.
Be sure to use a TEXT editor like notepad. A word processor like WORD may put formatting characters in the file which will cause the script to fail.

This file should look the following:

Code:
Sub main(args)
    TGCtrl.Print "Hello World!"
End Sub
Now launch TaskGhost if it isn’t already running.
Press the Stop button.

You should see a screen similar to this one:


In this screen you should see something like the following:
Ready.
AutoRun started at 7/16/2003 2:51:58 PM
AutoRun exiting
Tick 6:03:10 PM


This output by TaskGhost simply means:
Ready. – TaskGhost is ready to start execution
AutoRun started at 7/16/2003 2:51:58 PM – AutoRun.vbs started
AutoRun exiting – AutoRun.vbs finished
Tick 6:03:10 PM – Main scheduling program is running

Now, simply use the Load Button to load and run your script.
You should see a screen similar to this one:


That’s it. That’s how easy it is to write a TaskGhost script!
In PART 2 of this chapter, we will see how to add HelloWorld.vbs to our main scheduler.
_________________________
Regards,
Luke Tomasello

Top
#1377 - 07/16/03 02:52 PM Re: Chapter 01 – Hello World!
Luke Tomasello Administrator Offline
Member

Registered: 09/17/00
Posts: 740
Loc: San Jose, CA., USA
Chapter 01 - Hello World, Part II

In Part I of this chapter, we learned how to create, load, and run a simple script. In this second Part, we will learn how to add a job (our HelloWorld.vbs) to our main scheduler.

1. Launch TaskGhost if it is not already running, and hit the Stop button to make sure we’re not running any jobs.
2. Open the Schedule.vbs file in the TaskGhost\Scripts directory—not the Sample Scripts directory—in your favorite TEXT editor, I use notepad.exe. This is your main schedule and contains the statements to schedule and launch all your various jobs.
3. Locate the table of triggers, they start with “If TGCtrl.CheckTime (…”
Add a single line to this section that looks like this:
If TGCtrl.CheckTime (2, tc, "* * * * * * * *") = true Then TGCtrl.Run 0, "HelloWorld.vbs", vbNullString
The above statement should all appear on a single line within your script.

Now, before we try out our scheduled HelloWorld job, let’s make a quick check of our schedule to see if the job identifier we’re using (2) is unique. That is, that it’s not being used by any other jobs.
The job identifier is shown here in bold:
If TGCtrl.CheckTime (2, tc, "* * * * * * * *") = true Then TGCtrl.Run 0, "HelloWorld.vbs", vbNullString

If the job identifier is being used by another job, select another numeric value. It’s not really important what the value is, just that it’s unique.

1. Okay, save your Schedule.vbs.
2. Use the Load button and navigate to the TaskGhost\Scripts directory.
3. Select the Schedule.vbs file (once selected, it will run.)

You should see a screen similar to this one:


If all went according to plan, you should see “Hello World!” being printed once a second to the TaskGhost console.

Okay, now press the Stop button.

You should see a screen similar to this one:


In Part III of this first chapter we will discuss the How’s and Why’s of what we’ve seen so far.
_________________________
Regards,
Luke Tomasello

Top
#1378 - 07/16/03 03:31 PM Re: Chapter 01 – Hello World!
Luke Tomasello Administrator Offline
Member

Registered: 09/17/00
Posts: 740
Loc: San Jose, CA., USA
Chapter 01 - Hello World, Part III

In Part II of this chapter we learned how to add a job (our HelloWorld.vbs) to our main scheduler. Now lets answer some questions about what we’ve seen so far.

Q. When we ran the HelloWorld job, both from the TaskGhost user interface and from the schedule, we never specified the function to run. What if my job is made up of many functions and subs, how will TaskGhost know which one to run?

A. All jobs must have a main function. When TaskGhost loads a script it looks for main and begins executing there.

Q. I think I understand most of the BASIC statement we wrote into the schedule, but what was that vbNullString thing. What was it for?

A. The main function—which is a part of all jobs—must take one parameter, this is the TaskGhost convention.
If you remember the HelloWorld job we just wrote, it too had this requisite parameter, we just never used it.
Code:
Sub main(args)
    TGCtrl.Print "Hello World!"
End Sub
Our convention is to use the VBScript ‘string constant’ vbNullString to represent the NULL parameter. I.e., a parameter we are not using.
Because our scheduler didn’t need to pass a parameter to the HelloWorld script, it just passed vbNullString.

Here’s an experiment for you to try:

Change the HelloWorld.vbs to print the parameter instead of the hard-coded string “Hello World!”
Code:
Sub main(args)
    TGCtrl.Print args
End Sub
Now, save this file and update the Schedule.vbs to pass a string to HelloWorld.vbs instead of the vbNullString we’re currently passing.

What do you think will happen?
_________________________
Regards,
Luke Tomasello

Top


Moderator:  Luke Tomasello