background image

51

Switch/Case

Sometimes you have more than one condition you want to check for. You can do this with several 
If/Then statements. The Switch/Case statement provides an easier way to make multiple comparisons:

Integer switch

String switch

switch (intvar) 

switch (stringvar)

case intval1

 

case "stringval1"

statementa statementa

statementb statementb

case intval2

case "stringval2"

statementc statementc

statementd statementd

default default

statemente statemente

statementf statementf

endswitch endswitch

You can use integer or string values with the Switch/Case statement.  Based on the value of the 
variable, the case block corresponding to that value is executed. Each case block can contain multiple 
statements but only one case block is executed.  

If the value of the switch variable does not match any of the cases, the default block is executed.   The 
default block is not required.  However, if a default block is used, it must be the last block.

Example of Switch

Lexmark MFPs have a job accounting capability.  When this feature is enabled, users must enter an 
account number before accessing a profile.  For this example, users enter a department number when 
using profiles.  This example script uses a Switch/Case statement to check the department number.

string CustomSubject

// Use the account number as an integer

int DeptNumber = original.useracct.AsInt()

switch (DeptNumber)

case 35

   CustomSubject = "Document from Human Resources"

case 41

   CustomSubject = "Document from Legal Department"

case 15

   CustomSubject = "Document from Shipping Department"

default

   CustomSubject = "Document from FooBar Company"

endswitch

with EmailSMTP

   .Server="mailserver.com"

   .To="[email protected]"

   .From="[email protected]"

   .Subject=CustomSubject

   .Message="Please read."

   .CharacterSet=LDD_SMTPCHARSET_US

   .Attachments=original.document

   .Go()

endwith

Содержание Document Distributor

Страница 1: ...www lexmark com Basic Script Writing April 2002 Document Distributor...

Страница 2: ...can purchase additional copies of publications related to this product by calling 1 800 553 9727 In the United Kingdom and Eire call 44 0 8704 440 044 In other countries contact your point of purchase...

Страница 3: ...ard to write your script 4 EmailSMTP 8 ConvertToDocument 12 FaxByPrinter 15 Compiling your new script 18 Creating a Profile 20 Using the MFP ProfileWizard 21 Summary 25 Chapter 2 Parts of a Script 26...

Страница 4: ...41 Add Actions Manually 45 Compilation Prompts 47 Summary 47 Chapter 4 Flow Control 48 Conditional Statements 48 If Then 48 Switch Case 51 Repetitive Statements 52 Loop 52 Repeat 53 Summary 54 Chapter...

Страница 5: ...es Both of these documents are located at Start Programs Lexmark Document Distributor Client Included in this book Chapter 1 Your First Script Planning and creating your first script Chapter 2 Parts o...

Страница 6: ...sers Once you ve decided that Document Distributor can improve your workflow process analyze the steps involved in the process Example of a work flow process The Human Resources Department must post j...

Страница 7: ...zard Route Documents Print Documents Store and Retrieve Documents EmailExchange PrintASCII DatabaseNotes EmailNotes PrintByAssoc FTPget EmailSMTP PrintByDriver FTPput FaxByPrinter PrintIP GWDiscuss GW...

Страница 8: ...te scripts to automate your workflow 1 Start the ScriptWizard by clicking the ScriptWizard icon 2 A Dialog box appears listing the steps to take to create a script Click Next 3 Choose which Document S...

Страница 9: ...kstation The name can be up to 15 characters long You may also provide a longer description to help identify this work flow process This description can be seen by end users who submit jobs from a wor...

Страница 10: ...s on page 2 the end user will scan the list of job openings or submit the list using Print N Send so select Yes a document is required for this job No user data is needed in this script To learn more...

Страница 11: ...u can also add the same Action several times For example add FaxByPrinter again if you want to fax the document twice The Actions are carried out in the order they are added to the script If you need...

Страница 12: ...operties Click on each of the following to specify the property Server To From Subject Message Attachments 1 Click the Server Property This property indicates the mail server that sends the e mail Sel...

Страница 13: ...ndicates to whom the e mail is sent Select Use value specified and type in the recipient of the e mail 3 Click the From property This property is the sender s e mail address Select Use value specified...

Страница 14: ...10 4 Click the Subject property This string is the subject of the e mail that is sent Select Use value specified and type in the subject...

Страница 15: ...e 6 Click the Attachments property This property indicates what documents to attach to the e mail Since this script e mails the original document received from the user click Use a variable or propert...

Страница 16: ...ed to be set Input Format Output 1 Click the Input property This is the document the action will operate on Click on Use a variable or property and choose original document from the list This is the d...

Страница 17: ...13 2 Click the Format property This property specifies the file format of the output from this Action Choose PostScript as the conversion format...

Страница 18: ...the output from this Action Click Create a new variable called in order to create a new document variable Type in PSDocument as the name of the new document This document can be used in subsequent Ac...

Страница 19: ...e following properties need to be specified Input IPAddress FaxNumber StationID 1 Click the Input property This is the document that will be faxed Click on Use a variable or property select the PostSc...

Страница 20: ...16 2 Click on the IPAddress property Provide the IP address or DNS name of the fax enabled Lexmark printer to be used for faxing...

Страница 21: ...er of the receiving fax machine Be sure to include any additional numbers such as prefixes to access an external phone line or an area or country code 4 Click the StationID property Enter a station ID...

Страница 22: ...e Primary Server to see the new script Notice the red square symbol on the script This indicates that the script needs to be compiled before it can be used Compiling turns your script into instruction...

Страница 23: ...rors and Warnings window below the script text 3 After the script has been compiled and any syntax errors corrected you need to upload the script to the Server so it can be used Click Save to Server o...

Страница 24: ...run Scan Settings so the MFP knows how to scan the document Server IP Address so the MFP knows which Server to send the scanned document to for processing To create a profile there must be an MFP in y...

Страница 25: ...rver Admin toolbar This opens the ProfileWizard 2 The opening dialog outlines the steps you ll take to create a profile Click Next 3 Select the Server where the script resides and then select the scri...

Страница 26: ...the MFP on which to create the profile Click Next 6 You can choose a shortcut to make it easier for your end users to access the profile For this example click Don t assign a shortcut for this profile...

Страница 27: ...ments that your end users will scan when using this profile These settings include content paper size orientation and duplex The duplex choice only appears if the selected MFP has a duplex option For...

Страница 28: ...ument is scanned Since the document is also faxed Black and White is a good choice for the Color setting Scan resolutions range from 150 600 dpi the higher the resolution the more details in the scann...

Страница 29: ...You have now written a script using the ScriptWizard It was created compiled and saved to the server At that point the script could be used from a workstation using Print N Send or Select N Send To u...

Страница 30: ...s reading a text file Properties and methods All objects contain properties and methods A property is a value that can be set that effects how the object operates A method is a function that operates...

Страница 31: ...the shortcut Example 1 EmailSMTP Server mail server com EmailSMTP To NewEmployee lexmark com EmailSMTP From LDDTrain lexmark com EmailSMTP Subject New Job Listings EmailSMTP Message Please post on the...

Страница 32: ...tter Must be unique within the script the names are not case sensitive so Name NAME and name are all considered the same variable name Cannot be a reserved word one that has a special meaning to the s...

Страница 33: ...iables and properties The results of integer mathematical operators are always integers For example the result of 11 5 is 2 Operators Description Example EQ Equals b1 b2 results in a value of FALSE NE...

Страница 34: ...le below uses the following string variables as an example string test 1 2 3 a bc EFG string check AbCdE Symbols Operators LT Less Than GT Greater Than LE Less Than or Equal To GE Greater Than or Equa...

Страница 35: ...FTPput and FaxByPrinter Some Actions also produce a document as output such as ConvertImageFormat and ConvertToDocument When an Action produces a document as output the document is not created until t...

Страница 36: ...ult values provided by the Action Actions also have methods that operate on documents Methods can have parameters If the method has parameters they follow the method name and are enclosed in parenthes...

Страница 37: ...from the profile and information about the user who sent the job when it s available The following information is provided about the user who submitted the job Property Description userip The IP addr...

Страница 38: ...document scanned 2 This statement sets the ConvertToDocument property of input to original document This tells the ConvertToDocument Action to act on the original document Many Actions have an input p...

Страница 39: ...e character as the separator The separator character is not contained in the substrings You can access each string in the array by number Each item in the array can be used just as a string data objec...

Страница 40: ...pened text file must be closed when you are finished using it Method Parameters bool Open string file bool bCreate string file Full path name of the file to open bool bCreate If TRUE the file will be...

Страница 41: ...ta int size tf Open c data txt FALSE size tf GetSize data tf Read size tf Close The string variable named data now contains the contents of the text file See the Script Reference for a complete list o...

Страница 42: ...cates where the output from its operation is stored Notice the following inputs and outputs in our sample script 1 ConvertToDocument Action uses the originally scanned document as its input 2 The outp...

Страница 43: ...the variables for you and provides error checking on the settings you specify But sometimes you need to add just one more Action or make some other change With the Script Editor in Document Server Adm...

Страница 44: ...the Save To Server function the changes to the script exist only on the local Server Admin computer Displays a dialog allowing you to specify whether this script needs an original document and modify...

Страница 45: ...12345678 StationID Mail Room WaitForCompletion FALSE Go endwith This script receives new orders as TIFF images converts them to PostScript and faxes them to the shipping department where the order is...

Страница 46: ...fore that Action For our example lets add the SaveToFile Action at the end of the script 2 Click in the text window below the last endwith statement at the bottom of the text The new Action will be ad...

Страница 47: ...nal scanned document not the converted PostScript document 8 Click the Path property Specify a location to save the file This is a drive on the Document Server system Be sure the specified directory a...

Страница 48: ...of the existing script 11 Use the Compile button to compile the script for the Document Server 12 Use the Save to Server button to send the updated instructions to the Document Server Once it has been...

Страница 49: ...Press the Return key When you press the Return key you are automatically indented on the next line ready to add your properties or methods 4 Type a period and the list of properties and methods for t...

Страница 50: ...termine whether this string contains the text Confidential For example 1 Declare the variables string DocContent bool isConfidential 2 Then when you type isConfidential DocContent Contains A window ap...

Страница 51: ...string copies prompt Enter number of copies PrintIP copies copies AsInt Compilation prompts are used in several of the example scripts included with the Document Server This allows you to enter inform...

Страница 52: ...execute the same blocks of statements multiple times Conditional Statements If Then The simplest form of flow control is to execute an Action when a condition is TRUE for example a document contains...

Страница 53: ...eturnReceipt FALSE MailImportance LDD_PRIORITY_NORMAL DeliveryPriority LDD_PRIORITY_NORMAL DeliveryReport LDD_DELIVERYREPORT_FAILURE MoodStamp LDD_MOODSTAMP_NORMAL Go endwith endif If Then Else Adding...

Страница 54: ...ame Length 0 then MailMessage This email was sent by original username else MailMessage This email was automatically generated by LDD endif with EmailSMTP Server mail server com To JoeSmith foobarcomp...

Страница 55: ...any of the cases the default block is executed The default block is not required However if a default block is used it must be the last block Example of Switch Lexmark MFPs have a job accounting capa...

Страница 56: ...dloop statement The loop begins with the counter variable being assigned the value indicated by istart With each execution of the loop the value of the counter is incremented by 1 This continues until...

Страница 57: ...cuments If the document is confidential it is not e mailed The scanned image is saved to a file and a warning message sent to the user who scanned the confidential document with ConvertToText input or...

Страница 58: ..._US Go endwith else with EmailSMTP Server mail server com To Receiver abcxyz com From Submitter Subject Scanned Document Message Here is the document you requested CharacterSet LDD_SMTPCHARSET_US Atta...

Страница 59: ...ave any way to communicate with the user User data is the way to gather additional information also called metadata from your users When you write the script you specify the questions to ask When acce...

Страница 60: ...ed from an MFP each question is presented individually For an MFP without a touch screen only questions with numeric answers should be used as there is no way to enter alphabetic input This dialog con...

Страница 61: ...57 Creating User Data in a Script When ScriptWizard starts decide whether you want to ask your users any questions Select Yes to define the questions you want to ask...

Страница 62: ...58 The Original and User Data dialog appears Click on Add for each question you want to ask your user...

Страница 63: ...able Name is the name used to access the user s answer in the script The Data Type is the type of data you can gather from your user Checkbox Yes no or true false questions Integer Type in a number wi...

Страница 64: ...question for your user For example Is this work billable Keep a copy of this fax Print the document in color The answer selected by the user is then used in your script as a Boolean variable You can c...

Страница 65: ...nt number The answer given by the user can then be used in your script as an integer value You can provide a default value as well as a minimum and maximum value When a minimum or maximum is provided...

Страница 66: ...ript as a string value You can provide a default value for the string A minimum length can be specified When no minimum is specified an empty string is acceptable as an answer A maximum value can also...

Страница 67: ...m entering incorrect answers To add items to your list Click the Add button Click the Delete button to remove items from the list Up and Down buttons allow you to arrange the items in the list Specify...

Страница 68: ...our script The Userdata object contains one property for each question that you prompted your user for For example In the example script on the next page there are three user data items These items ca...

Страница 69: ...Data EmailAdd Message LoanLength CharacterSet LDD_SMTPCHARSET_US Attachments original document Go endwith In this script the string value UserData LoanType is used to customize the subject and recipie...

Страница 70: ...xmark and Lexmark with diamond design are trademarks of Lexmark International Inc registered in the United States and or other countries 2002 Lexmark International Inc 740 West New Circle Road Lexingt...

Отзывы: