Seiki Batch Script > Structure

A More Complex Script

Before we can get on to interrogating the status of a machine tool we need to lay a little groundwork. The first area is strings. Strings are what we call text. It is just a string of ASCII characters hung together in a line. We use ASCII, American Standard Code for Interchange of Information because that's what Windows uses. You have already seen that we specify a string by enclosing the characters we want within double quotation marks "like this" but we can do more.

A variable, on a computer, is a place to put things. It is normally given a name. We can create any number of variables to hold strings by just using a name that starts with a $ sign, followed by a letter and then any combination of letters and numbers. We like to pick names that convey the sense of the thing we are putting in the variable. The script line

$boss = "David Moody"

refers to a string variable called $boss and puts the string value "David Moody" into it. If everywhere else in the script from then on that I want to refer to my boss I use $boss it works for me and you only need make one change to one line to put your boss in and the program will work for you. Before that line of script the variable $boss probably was empty. That is it contained no characters but was still a valid string, just a very short one. After that script line has passed it has new contents. A variable can have many different values during a script. For example a variable $fault may normally be empty but may have different values depending on what is happening but once worked out can be included in eMail, faxes, pager messages and be printed in the logs without having to be worked out again every time.

Remember that the construction something = something_else is not telling you they are equal but it is taking the value contained in something_else and copying it into something.

Try this script

$boss = "David Moody"

message($boss+" is out today", $0)

This should display

Here we have used the + sign to add two strings together. $boss is unchanged but the function message( ) takes two parameters and the first is the text to display in the box and consists of the contents of the variable $boss and the text in quotes. Notice that we needed to specify the quoted sting to have a space at the start or we would get "David Moodyis out today". Script gives you just what you ask for.

The second parameter to message( ) comes after the comma and is the title to go at the top of the box. It is optional and if you omit the comma and omit the second parameter you just get a blank title line. We have used $0 as a special string that deserves some explanation.

If you run SBS with text after the file name eg:

sbs.exe boss.sbs item1 "item 2"

then the extra  stuff is available to the script in special variables. $1 would contain the string "item1" and $2 would contain "item 2". If item 2 was not contained within quotation marks there would be three special variables so use them for filenames and things that might contain spaces. $0 is a special case and is the full pathname of the script file itself. This is useful if you want to pop up a message box to report an error. To say something like "Script "+$0+" file not found" makes fixing the problem much easier than having somebody ask what a "file not found" error was and then having to work out which scripts have 'file not found' errors in them and then wondering which one it might be.

How long is a string?

We do set a maximum length for strings so we can handle them sensibly within the program. Up to the 23rd of March 2003 we thought that 511 characters was plenty but then we increased it to 2047.