Using JavaScript utilities
Two JavaScript utilities are available:
ActiveX Wrapper. Allows you to create an ActiveX object and use the associated ActiveX methods.
File Object. Allows you to create a file object to read from and write to a file.
You can write JavaScript using these utilities in the VWorks Advanced Settings area. For instructions on how to add the JavaScript task and display the Advanced Settings area, see Where to write JavaScript.
ActiveX Wrapper 
ActiveX controls are software components that allow different software products to interact. For example, if you want to use the VWorks software to control a device, you can use the device's ActiveX control to invoke the device's operations.
The ActiveX Wrapper utility in the VWorks software allows you to use another product's ActiveX control to invoke the product's operations. Make sure you install the product's ActiveX control software before you run the JavaScript.
To use the ActiveX utility, you need to:
1 Create an ActiveX object to reference the ActiveX control.
2 Call the associated ActiveX methods to invoke the ActiveX operations.
3 Use the Set and Get methods to access the ActiveX properties.
Create an ActiveX object
To create an ActiveX object:
In the Advanced Settings area, type the JavaScript code to create an ActiveX object.
For example, if the ActiveX control PROG_ID is PlateLocCtrl.2, you can create the object as follows:
var ocx
if(ocx==undefined){
ocx=new ActiveX("PLATELOC.PlateLocCtrl.2");
}
The var statement declares a JavaScript variable. In this example, the variable is ocx.
The if statement prevents the software from creating the ActiveX multiple times if the script is run repeatedly.
The ocx = new ActiveX statement passes the PlateLoc PROG_ID to the ActiveX object generator. Using the ID, the generator calls the CreateInstance API. The resulting ActiveX object is then wrapped in the scripting layer that translates arguments and returns values that are understood by both the PlateLoc Sealer and the VWorks software.
Calling the ActiveX methods
To call the ActiveX methods:
Call the methods using the following syntax:
objectname.method
For example, if you want to call the AboutBox() method, you can type the following:
ocx.AboutBox()
To list the available ActiveX methods, use the following JavaScript statements:
for(x in ocx.members)
print(x)
Accessing the ActiveX properties
To access the ActiveX properties:
Use the Set or Get method and the following syntax:
comm.set("property_name", value)
comm.get("property_name")
For example, if you want to access the ActiveConnection property of an ADO command object, you can type the following:
var db=new ActiveX("ADODB.Connection")
var comm=new ActiveX("ADODB.Command")
comm.set("ActiveConnection", db)
The first var statement creates an ADO object and assigns it to a variable named db.
The second var statement creates an ADO command object and assigns it to a variable named comm.
The comm.set statement sets the ActiveConnection property to the connection object in the db variable.
File Object 
The File Object utility allows you to create a file object so that you can read from and write to a file. The file can be in local file system storage or Shared Services storage (OLSS).
To use the File Object utility:
1 Create the file object.
2 Call the desired file object methods:
Open()
Close()
Read()
Write()
IsOpen()
Exists()
Delete()
Note: The Delete() and Write() methods are not available for files in OLSS storage.
 
*The JavaScript language is case-sensitive. Make sure you use the correct upper- and lower-case letters when calling the methods.
 
Creating a file object
To create a file object:
In the Advanced Settings area, type the following JavaScript code:
var fileobjectname
if(fileobjectname==undefined){
fileobjectname=new File()
}
Note: fileobjectname is the name of the file object you want to create.
Calling the Open() method
To call the Open() method:
Type the following JavaScript code:
fileobjectname.Open("filepath",0,0)
fileobjectname is the name of the file object you created.
filepath (the first argument) is the location of the file you are creating. For example, you can type c:\\fileobjectname.txt.
0 (the second argument) specifies how new information will be added to the file. 0 adds new information after the existing information. A non-zero value erases the existing file contents before adding the new information. If you do not specify this argument, the system will use the default value of 0.
0 (the third argument) specifies how the line endings in binary files will be translated. 0 translates line endings to a carriage return followed by a line feed. 1 does not translate the existing line ending. If you do not specify this argument, the system will use the default value of 0.
Calling the Close() method
To call the Close() method:
Type the following JavaScript code:
fileobjectname.Close()
fileobjectname is the name of the file object you created.
The Close method closes the file and releases any locks on the file so that other software can access it.
Calling the Read() method
To call the Read() method:
Type the following JavaScript code:
var result = fileobjectname.Read()
The Read() method returns the entire file contents as a string into the variable called result. Although line-by-line reading is not available, you can use built-in JavaScript string methods to parse the file.
If another process is concurrently adding information to the file, later calls to the Read method will read the newly added information.
Calling the Write() method
To call the Write() method:
Type the following JavaScript code:
fileobjectname.Write("writeoutput" + "\n")
fileobjectname is the name of the file object you created.
writeoutput is the string you want to add to the file.
\n adds a new line at the end of the string.
Calling the IsOpen() method
To call the IsOpen() method:
Type the following JavaScript code:
var open=fileobjectname.IsOpen()
The var statement checks to see if the file opening call was successful.
Calling the Exists() method
To call the Exists() method:
Type the following JavaScript code:
var exists=fileobjectname.Exists("filepath")
filepath is the location of the file you are checking.
The var statement checks to see if the file exists in the specified folder and returns true if the file is present.
Calling the Delete() method
To call the Delete() method:
Type the following JavaScript code:
fileobjectname.Delete("filepath")
filepath is the location of the file you are deleting. For example, you can type c:\\fileobjectname.txt.
Related information
 
For information about...
See...
JavaScript language
Using JavaScript in the VWorks software
Using script variables directly in task parameters
JavaScript task description
Startup and cleanup protocols
Setting protocol options