Menu
Index

ChronoScan Scripting Module – Added Scripting Capabilities to ChronoScan

 
Visit chronoscan.org for more information.
 
For advanced users that want to add custom processes to their data entry process we have added the ability to execute VBScripts when an event occurs on ChronoScan. The first version allows execution of a VBScript every time a field value is changed by the user or by one of the process modules (OCR, Barcode…). The advantages of using a VBScript are that you can do almost everything with the data inside ChronoScan. Some examples are:
 
 
The following example shows how to find a barcode on an external database, retrieve the data from the database and validate the item based on the existence or not of the barcode. On this example, you will be able to see how to enable VBScript for Barcode Data Fields and how to write the script:
 
To enable VBScripting right click on the Barcode Data Field and open the Field Properties on the Object Properties Panel, then click on the configuration icon on the OnValueChanged item, that will open the VBScript Editor Window:
 
Configuration icon for the Barcode Data Field on the Object Properties Panel.
 
The editor shows the available objects for scripting on the left, and the current script on the center. All the scripts start with a sample script.
 
Now a step by step guide showing how to write the script:
 
First you need to create a connection to the database using:
 
Dim SQLString Set MyDB = CreateObject("ADODB.Connection") MyDB.Open "ULISES_JOSE_DEV"
 
To create the connection to your database, open the ODBC driver manager on your Windows control panel:
ODBC Driver Manager Window.
 
Now construct your SQL using:
 
SQLString = "Select * from check_table where field_name = '" & <b>UserField_EXPEDICION.value</b> & "'"
 
This SQL is built by searching for the actual value in the field EXPEDICION. The fields are represented on VBScript as UserField_FIELDNAMEONCHRONOSCAN. Spaces and illegal VBScript symbols are replaced with “_”.
 
To access the properties under an object you must put a period (.) after the object name. Now you should be able to view the methods and properties available.
 
Now execute your query:
 
Set rsCustomers = MyDB.Execute(SQLString)
 
If Not rsCustomers.EOF Then
 
      ‘If the barcode exists on the remote database validate the field on ChronoScan and set the value of the field SCRIPTED to the database field “read_value”'
 
    UserField_SCRIPTED.value = rsCustomers.Fields("read_value")
 
    UserField_EXPEDICION.ValidateStatus = 1
 
Else
 
        'If the barcode doesn’t exist, then set the field SCRIPTED to “Not Found”, and the field status to error. You can also setup a error pop up window'
 
    UserField_SCRIPTED.value = “Not Found”
 
    UserField_EXPEDICION.ValidateStatus = 0 ‘ Not validated
 
    UserField_EXPEDICION.ValidateMessage = "BARCODE doesn't exist on the remote database "
 
End If
 
'Finally close the database'
 
MyDB.Close
 
 
 
You can test the script by clicking on the Play button. If there is an error the VBScript will show it.
 
This is the finalized script:
 
 
Dim SQLString
 
Set MyDB = CreateObject("ADODB.Connection")
 
MyDB.Open "ULISES_JOSE_DEV"
 
 
SQLString = "Select * from check_table where field_name = '" & UserField_EXPEDICION.value & "'"
 
Set rsCustomers = MyDB.Execute(SQLString)
 
 
If Not rsCustomers.EOF Then
 
    UserField_SCRIPTED.value = rsCustomers.Fields("read_value")
 
    UserField_EXPEDICION.ValidateStatus = 1
 
Else
 
    UserField_SCRIPTED.value = “Not Found”
 
    UserField_EXPEDICION.ValidateStatus = 0
 
    UserField_EXPEDICION.ValidateMessage = "BARCODE doesn't exist on the remote database"
 
End If
 
MyDB.Close
comments powered by Disqus