Home

Macros and Programming

 

CardboxForumsMacros and Programming > "Windows Scripting Host and Cardbox constants"

Windows Scripting Host and Cardbox constants

An alternative to explicitly copying the definitions of Cardbox constants when writing Windows Scripting Host scripts.

Current user: [none]
Register / Log In · Help

Posted By Post

cardboss

26-Apr-2005 17:35

The quick-and-easy way to write a WSH script is to write your VBScript and save it as a file of type .VBS:

  Set cbx=CreateObject("Cardbox.Application")
  Set win=cbx.Windows.OpenFile ("C:\My Documents\MJK.FIL")
  win.Print cbxPrintMainRecord,,,,"Adobe PDF"

Unfortunately this example won't work as it stands because 'cbxPrintMainRecord' is a built-in Cardbox constant and Windows won't know what value it is meant to have. The usual way round this is to include the appropriate constant definition explicitly (Help Point 762 gives you a full list):

  Const cbxPrintMainRecord = 1
  Set cbx=CreateObject("Cardbox.Application")
  Set win=cbx.Windows.OpenFile ("C:\My Documents\MJK.FIL")
  win.Print cbxPrintMainRecord,,,,"Adobe PDF"

If you have to do this for every script you write then this becomes cumbersome and rather error-prone, but there is an alternative. There is a different (and less known) format for Windows scripts that lets you tell WSH where to find the definition of the Cardbox constants. Here is the same example, in that format:

  <job id="MySampleScript">
  <reference guid="F06B7A85-66DD-1069-8FB7-AA0004004D05" version="3.0" />
  <script language="VBScript">
  Set cbx=CreateObject("Cardbox.Application")
  Set win=cbx.Windows.OpenFile ("C:\My Documents\MJK.FIL")
  win.Print cbxPrintMainRecord,,,,"Adobe PDF"
  </script>
  </job>

You need to save this kind of script in a file of type .WSF, so that WSH knows which format it is meant to be reading. Most of the additional lines here are pure bureaucracy, but the <reference> line tells WSH where to retrieve the definition of all Cardbox constants: thus we no longer need a 'const' definition for 'cbxMainRecord' because WSH has found it automatically.

Quick Reply

Please log in or register before trying to post a reply.

 
© 2010 Cardbox Software Limited   Home