Cam 350 Scripting

34
BASIC Commands Most of the following commands operate as standard BASIC commands. However, some have been added, modified, or expanded in order to suit the needs of the software. They use a BASIC Keyword, along with one or more of the following expressions: Numeric/Mathematical - An expression which evaluates to a number Boolean - Expressions which to evaluate a condition as either true or false. (See the IF/THEN/ELSE Statement for more information.) Strings - An expression which evaluates text. Anything placed in brackets [ ] is optional. Macro Commands Database Queries Forms ABS Function Returns the absolute value of a numeric expression. Example: n = -6 y = ABS(n) y = 6 ASC Function Returns a numeric value that is the ASCII code for the first character in a string expression. Example: n$ = "April" y = ASC(n$) y = 65 ATN Function Returns the arctangent of a numeric expression (the angle whose tangent is equal to the numeric expression). Page 1 of 34 Basic Commands 10/11/2011 mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

description

cam350 macro scripting

Transcript of Cam 350 Scripting

Page 1: Cam 350 Scripting

BASIC Commands

Most of the following commands operate as standard BASIC commands. However, some have been added, modified, or expanded in order to suit the needs of the software. They use a BASIC Keyword, along with one or more of the following expressions:

Numeric/Mathematical - An expression which evaluates to a number

Boolean - Expressions which to evaluate a condition as either true or false. (See the IF/THEN/ELSE Statement for more information.)

Strings - An expression which evaluates text.

Anything placed in brackets [ ] is optional.

Macro Commands

Database Queries

Forms

ABS Function

Returns the absolute value of a numeric expression.

Example:

n = -6 y = ABS(n) y = 6

ASC Function

Returns a numeric value that is the ASCII code for the first character in a string expression.

Example:

n$ = "April" y = ASC(n$) y = 65

ATN Function

Returns the arctangent of a numeric expression (the angle whose tangent is equal to the numeric expression).

Page 1 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 2: Cam 350 Scripting

Example:

n% = 30 PRINT ATN (n%)

Output: 1.537475

BREAK Command

Pauses a macro at the point the command is present in the program. To be used only in conjunction with the Macro Debugger to determine problems in the execution of a macro script.

Syntax:

BREAK

Example:

X% = Y% BREAK 'pause after variable definition

CHR$ Function

Returns a one-character string of the ASCII code used.

Example:

PRINT CHR$(65)

Output is "A"

CLOSE Statement

Concludes I/O to a file or device.

Example:

CLOSE 'close all open files CLOSE #1 'close file #1

CLOSE_MSG Statement

Page 2 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 3: Cam 350 Scripting

Removes a message box.

Example:

FOR n = 1 to 10 PRINT_MSG "Number is",n DELAY 500 CLOSE_MSG

COS Function

Returns the cosine of an angle given in radians.

Example:

n% = 30 PRINT COS (n%)

Output: 0.154251

DEFtype Statements

Sets the default data type for variables. DEFINT sets the data type as an Integer (%), DEFREAL sets it as a Real number (#), and DEFSTRING sets it as a String ($).

Syntax:

DEFINT <letter range[,letter range]> DEFREAL <letter range[,letter range]> DEFSTRING <letter range[,letter range]>

Example:

DEFINT a-b,e a = 34 b = 100 eagle = 10 PRINT eagle, a + b

Output: 10 134

DEFREAL q quest = 3.45 quarry = 78.31 PRINT quest + quarry

Output: 81.76

DEFSTRING r-v roger = "wilco, " r = "and "

Page 3 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 4: Cam 350 Scripting

s = "out" type = "over " voice = "Roger, " PRINT voice + roger + type + r + s

Output: Roger, wilco, over and out

DELAY Statement

The delay is used to slow down the playback of a macro. For example, you may want to display a message for a set period of time. This function is independent of computer speed.

Syntax:

DELAY <n>

n is the delay in milliseconds (1/1000 of a second).

Example:

FOR n = 1 to 10 PRINT_MSG "Number is",n DELAY 500 'half second delay) CLOSE_MSG

DIM Statement

Allocates space for an n dimensional array. The maximum number of dimensions is currently 20. The type of the array is determined by the type of variable used.

Example:

DIM C%(10)

Dimensions an array of 11 integers (0-10) named C.

Examples of DIM Statements using multidimensional arrays, as well as arrays from one index to another:

DIM a%(10) DIM b#(-10 to 0) DIM c$(5) DIM d%(10,10)

DO/LOOP Statements

Repeats a block of statements while a condition is true, or until a condition becomes true.

Page 4 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 5: Cam 350 Scripting

Example:

DO INPUT "Enter a number less than 10",i LOOP UNTIL i >= 10 PRINT "End of do test" END

END Statement

Ends a BASIC program, procedure, or block.

Example:

DO INPUT "Enter a number less than 10",i LOOP UNTIL i >= 10 PRINT "End of do test" END

EOF Function

Tests for the end-of-file condition (returns 1 if end of file is reached).

Syntax:

EOF (File#)

Example:

OPEN "Test.dat" FOR OUTPUT as #1 FOR i = 1 to 10 WRITE #1, i, 2 * i, 5 * i NEXT CLOSE #1 OPEN "Test.dat" FOR INPUT as #1 DO LINE INPUT #1, a$ PRINT a$ LOOP UNTIL EOF (1) = 1

EXIT MACRO Statement

Ends the macro while leaving the command processor in its current state (even in the middle of a command).

Syntax:

Page 5 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 6: Cam 350 Scripting

EXIT MACRO

Example:

edit_aperture@ 10,1,10.0000,10.0000,0,"" update_dcodebar@ add_line@ axy@ 0.0000,0.0000 axy@ 125.0000,-125.0000 axy@ 250.0000,0.0000 view_redraw@ EXIT MACRO

EXP Function

Calculates the exponential function.

Example:

x = 10 PRINT EXP (x) Output: 22026.465795

FILE EXISTS Statement

Determines if a file exists in a given directory. Returns a 1 if file exists; 0 if not.

Syntax:

FILEEXISTS(File$)

File$ is the full filepath of the file being checked.

Example:

if FileExists("d:\temp\test.doc") = 1 then OK_Cancel "There is already a file of that name in the directory. Overwrite file?", OK end if

FMTUSING$ Statement

Returns a string which is formatted as if PRINT USING was used.

Syntax:

FMTUSING$(formatstring$,expressionlist)

Page 6 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 7: Cam 350 Scripting

formatstring$ is a character string which contains formatting characters. The syntax of this string is the same as for PRINT USING.

expressionlist is one or more expressions separated by commas.

Characters that format a numeric expression

# Digit position

. Decimal point position

, Placed left of the decimal point, prints a comma every third digit

+ Position of number sign

- Placed after digit, prints trailing sign for negative numbers

$$ Prints leading $.

** Fills leading spaces with *

**$ Combines ** and $$

Characters used to format a string expression

& Prints entire string

! Prints only the first character of the string

\ \ Prints first n characters, where n is the number of blanks between slashes + 2

Characters used to print literal characters

_ Prints the following formatting character as a literal

Any character not in this table is printed as a literal.

Example:

s$ = FMTUSING$(" ###.##",x,y,z)

FOR/NEXT Statement

Repeats the statements enclosed in the loop a definite number of times, counting from a starting value to an ending value by increasing or decreasing the loop counter. As long as the loop counter has not reached the ending value, the loop continues to execute. Note that when playing a macro that has For/Next statements, the system checks for "suspect logic." Specifically, if there is more than one Next for a For statement, an error is reported.

Page 7 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 8: Cam 350 Scripting

In a FOR...NEXT loop, the counter variable initially has the value of the expression start. After each repetition of the loop, the value of counter is adjusted. If you leave off the optional STEP keyword, the default value for this adjustment is one (one is added to counter each time the loop executes).

If you use STEP, then counter is adjusted by the stepsize amount. The stepsize argument can be any numeric value; if it is negative, the loop counts down from start to end. After the counter is increased or decreased, its value is compared with end. At this point, if either of the following is true, the loop is completed:

The loop is counting up (stepsize is positive) and counter is greater then end.

The loop is counting down (stepsize is negative) and counter is less then end.

Syntax:

FOR <counter> = <start value> TO <end value> [STEP stepsize] [statementblock-1] [EXIT FOR] [statementblock-2] NEXT

Example:

FOR a# = 1 to 10 step .5 PRINT_MSG "a# = ",a# DELAY 10 NEXT PRINT "a# = ",a# END

GETOPENFILENAME Statement

Functions similarly to the Windows "Open" file dialog box: obtains a filename from the user by displaying a Windows-style drop down list (see the Forms topic). The returned filename can be used for file input/output purposes.

Syntax:

GetOpenFilename filename$, filter$, filter_desc$, FLAG

filename$ is the variable which will return the retrieved filename. Returns the full filepath of the file.

filter$ is a file filter to limit which file types are displayed (such as *.txt). More than one file type can be indicated by separating them with semi-colons ( "*.gbr;*.lgr"). If omitted, the default will be *.*.

filter_desc$ describes filter$ (e.g. "Gerber files").

FLAG is any one of the following:

NoFileMustExist Does not verify if the file exists or not.

Page 8 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 9: Cam 350 Scripting

NoPathMustExist Does not verify if the path exists or not.

NoChangeDir Will not allow the user to change the current working directory.

Multiple FLAGS are permitted, separated by commas. If none of the above FLAGS are used, then their opposite, default functions will be used.

Example:

getopenfilename Read$, "*.txt","Text Files", NoFileMustExist

GETSAVEFILENAME Statement

Functions similarly to the Windows "Save As" file dialog box: obtains a filename from the user by displaying a Windows-style drop down list (see the Forms topic). The returned filename can be used for file input/output purposes.

Syntax:

GetSaveFilename filename$, default_ext$, filter$, filter_desc$, FLAG

filename$ is the variable which will return the retrieved filename. Returns the full filepath of the file.

default_ext$ is the default extension of the file being saved. It is a three character string with no period (e.g. "txt").

filter$ is a file filter to limit which files are displayed (such as "*.txt"). If omitted, will be "*.*".

filter_desc$ describes filter$ (e.g. "Text files").

FLAG is any one of the following:

NoOverWritePrompt If the filename already exists, it does not prompt the user to verify before overwriting it.

PathMustExist Requires the saved file's path to already exist.

NoChangeDir Will not allow the user to change the current working directory.

Multiple FLAGS are permitted, separated by commas. If none of the above FLAGS are used, then the opposite, default functions will be used.

Example:

getsavefilename Save$, "gbr","*.gbr","Gerber Files", PathMustExist

GOSUB/RETURN Statements

Transfers control to, and returns from, a subroutine. The target, or return, for a gosub may be

Page 9 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 10: Cam 350 Scripting

a number or alphanumeric notation. The label may be on the same line as a command or it may be on its own line. Note that labels which are not numeric must be ended in a colon.

Example:

This macro draws a box around any coordinate.

50 INPUT "The size of the box in inches",boxsize half = (boxsize * 1000)/2 INPUT "The center X coordinate in inches",x INPUT "The center Y coordinate in inches",y x = x * 1000 y = y * 1000 GOSUB 100 OK_CANCEL "Continue?",OK IF OK = 1 THEN GOTO 50 END ' Box drawing subroutine 100 startx = x - half starty = y - half endx = x + half endy = y + half Add_rectangle@ axy@ startx,starty axy@ endx,endy RETURN

Use a subroutine whenever a task must be repeated. Note also that all variables are "global," meaning that a variable has the same value in a subroutine as in the main program.

GOTO Statement

Branches unconditionally to the specified line. A goto is a way to control the macro flow. The target, or label, for a goto may be a number or alphanumeric notation. The label may be on the same line as a command or it may be on its own line. Note that Labels which are not numeric must be ended in a colon

Example:

GOTO 100 100 PRINT "this is a numeric label" GOTO label1 label1: PRINT "this is an alphanumeric label"

HEX$ Function

Returns a hexadecimal string representation of a number.

Example:

Page 10 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 11: Cam 350 Scripting

x = 10 PRINT HEX$ (x) Output: A

HTMLHELP Statement

Allows the programmer to open an individual HTML document from a compressed HTML help file (*.chm).

Note: This command is recommended for advanced macro programmers.

Syntax:

HtmlHelp htmlhelpfile$, htmlhelppage$

htmlhelpfile$ = the filename for the HTML Help format file (e.g. help.chm)

htmlhelppage$ = the specific HTML topic file within that help file (e.g. TOC.html)

Example:

Htmlhelp "help.chm","basic_commands.html"

IF/THEN/ELSE Statements

Allows conditional execution, based on the evaluation of a Boolean expression. This statement may be a single line, or a block

Single Line Syntax:

IF <Boolean expression> [AND <Boolean expression> ]THEN <expression> [ELSE Statement]

Block Syntax:

IF <Boolean expression> [AND <Boolean expression> ]THEN <Block statements> [ELSEIF <boolean expression> THEN <Block statements>] [ELSE <Block statements>] END IF

If the expression is true then the statement is executed. Strings can also be compared using the If/Then statement.

Example:

IF taxes > 10000 AND taxes <100000 THEN GOTO 500 IF X = 14 THEN Time = Time + 1

Page 11 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 12: Cam 350 Scripting

!INCLUDE Statement

!INCLUDE functions like the MACRO_PLAY Statement, except for the following differences.

!INCLUDE can see variables which are used in the macro program calling the !INCLUDE statement, whereas MACRO_PLAY cannot.

When the subprogram called by MACRO_PLAY comes to an END statement, the calling macro continues on the next line. If an END statement is encountered in a macro called by !INCLUDE, then the main macro is also ended.

Unlike MACRO_PLAY, you cannot use a variable for the filename parameter of the command. (The full filename path for the macro to be included must be entered in the parameter).

See also the MACRO_PLAY and MACRO_LINK statements.

Syntax:

!INCLUDE Filename

Example:

if Add% = 1 then !INCLUDE "d:\temp\testscript.scr"

end if

INPUT Statement

The input command opens a dialog box, displays a string, and waits for the user to enter a value and press OK. Adding CR! to your message inputs a carriage line feed. This allows you to have multiple lines in the dialog box, and control where the line breaks.

Example:

INPUT "Enter your name", name$

INPUT# Statement

Page 12 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 13: Cam 350 Scripting

Reads data items from a sequential device or file and assigns them to variables.

Example:

OPEN "Price.dat" FOR INPUT AS #1 INPUT "Display all items below what level"; Reorder DO UNTIL EOF (1) INPUT #1, Company$, Styles$, Sizes$, Clr$,

INSTR Statement

Determines if a string exists within another string. It returns a numeric value for the position the substring begins, relative to the beginning of the string.

Syntax:

INSTR(position,string,substring)

where:

position = character position in the string to begin the search (optional - defaults to first char. in string)

string = the string expression to be searched

substring = the string expression to be searched for

Example:

Test% = instr(1,"where is mary jane?","mary")

KILL Statement

Deletes a file from disk.

Example:

KILL "c:\Act_Inc\Scripts\testing1.scr"

LCASE$ Function

Returns a string expression with all letters in lower-case.

Example:

Test$ = "THE string" PRINT Test$

Page 13 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 14: Cam 350 Scripting

PRINT LCASE$(Test$); " in lowercase"

LCLOSE Statement

Closes the printer and sends any unprinted characters to the printer.

Example:

FOR i = 32 to 127 s$ = s$ + chr$(i) NEXT FOR i = 1 to 190 LPRINT s$; NEXT LCLOSE END

LEFT$ Function

Returns a string consisting of the leftmost n characters of a string.

Example:

a$ = "Microsoft Qbasic" PRINT LEFT$(a$, 5)

Output is "Micro"

LEN Statement

Returns the number of characters in a string, or the number of bytes required by a variable.

Example:

Temp$ = "1234567" PRINT LEN (Temp$)

Output: "7"

LINE INPUT Statement

Inputs an entire line (up to 255 characters) to a string variable, without the use of delimiters.

Syntax:

Page 14 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 15: Cam 350 Scripting

LINE INPUT[;][ "prompt string"] string variable

Example:

LINE INPUT "Enter three values separated by commas: ", D$ PRINT "D$ = " D$

LINE INPUT# Statement

Reads an entire line, without delimiters, from a sequential file to a string variable.

Example:

Creates sample file:

OPEN "List" FOR OUTPUT as #1 DO INPUT " NAME: ", Name$ INPUT " AGE: ", Age$ WRITE #1, Name$, Age$ INPUT "Add another entry? Y or N", R$ LOOP WHILE UCASE$(R$) = "Y" CLOSE #1

Reads the file:

OPEN "List" FOR INPUT as #1 PRINT "Entries in file:": PRINT DO WHILE NOT EOF (1) =1 LINE INPUT #1, REC$ PRINT REC$ LOOP CLOSE #1

LOG Function

Returns the natural logarithm of a numeric expression.

Example:

x = 10 PRINT LOG (x)

Output: 2.302585

LPRINT, LPRINT USING Statements

LPRINT prints data to the default printer (as defined by the printer settings under Macro >

Page 15 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 16: Cam 350 Scripting

Setup Printer). LPRINT USING prints the data in a specified format. These statements function exactly the same as PRINT and PRINT USING, but instead of the output going to the screen it goes to a printer

See also the File > Print macro commands.

Characters that format a numeric expression

# Digit position

. Decimal point position

, Placed left of the decimal point, prints a comma every third digit

+ Position of number sign

^^^^ Prints in exponential format

- Placed after digit, prints trailing sign for negative numbers

$$ Prints leading $.

**Fills leading spaces with *

**$ Combines ** and $$

Characters used to format a string expression

& Prints entire string

! Prints only the first character of the string

\ \ Prints first n characters, where n is the number of blanks between slashes + 2

Characters used to print literal characters

_ Prints the following formatting character as a literal

Any character not in this table is printed as a literal.

Example:

FOR i = 32 to 127 s$ = s$ + chr$(i) NEXT FOR i = 1 to 190 LPRINT s$; NEXT LCLOSE END

Example:

x# = 1441.2318

Page 16 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 17: Cam 350 Scripting

LPRINT USING "No Decimal ####";x#

Output would be: 1441

LPRINT USING "The number with 3 decimal places ####.###";x#

Output would be: 1441.232

LPRINT USING "The number with a dollar sign and 2 decimals $$##.##";x#

Output would be: $1441.23

LPRINT USING "Number with plus signs +###.#### "; x#

Output would be: +1441.2318

LPRINT USING "The number with a comma ##,.##";x#

Output would be: 1,441.23

b$ = "ABCDEFG" LPRINT USING "The entire string &";b$

Output would be: ABCDEFG

LPRINT USING "The first character of the string !"; b$

Output would be: A

LPRINT USING "The first 3 characters \ \"; b$

Output would be: ABC

LTRIM$ Function

Returns a copy of a string with leading spaces removed.

Example:

a$ = " Basic " PRINT "*" + a$ + "*" 'Output is: * Basic * PRINT "*" + LTRIM$(a$) + "*" 'Output is: *Basic *

MACRO_LINK Statement

Links an existing macro file to your macro. Control will not return when the new macro ends. If you do not specify a path in the filename, the system will assume it is the same as the path of the macro you are linking from.

See also the MACRO_PLAY and !INCLUDE Statements.

Syntax:

Macro_link "filename.ext"

Page 17 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 18: Cam 350 Scripting

MACRO_PLAY Statement

Starts the macro script indicated. When this new macro ends, the existing macro resumes with the next instruction after the MACRO_PLAY command.

See also the MACRO_LINK and !INCLUDE statements.

Syntax:

MACRO_PLAY "filename.ext"

MESSAGE BOX Statement

This command displays a Windows-style message box, with configurable buttons and titles. A number of choices are offered for the display title. Each command returns a numeric value, depending on the buttons used in the box, which can be used as a conditional value in other statements.

Note: This command is recommended for intermediate to advanced macro programmers. Beginning macro programmers should use the OK_CANCEL or PRINT commands

Syntax:

MessageBox message$ [, title$] [, flags] [, return%]

message$ = message displayed within the box

title$ = title of dialog (INFORMATION is assumed if title$ value is empty).

flags = specifies the style of box to display (again, INFORMATION is assumed default) The following flags are available:

INFORMATION = OK button and lowercase i icon

WARNING = OK button and Exclamation point icon

ERROR = OK button and Stop sign icon

OKCANCEL = OK and CANCEL buttons, Question mark icon

YESNO = YES and NO buttons, Question mark icon

YESNOCANCEL = YES, NO, and CANCEL buttons, Question mark icon

RETRYCANCEL = RETRY and CANCEL buttons, Question mark icon

# = an integer representing the code for other Windows-style buttons (requires knowledge of MS codes; negative integer is possible).

Page 18 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 19: Cam 350 Scripting

return% = integer value returned, dependant on button pressed:

1 OK button was selected.

2 Cancel button was selected.

3 Abort button was selected. (Only if flag integer is set to ABORT)

4 Retry button was selected.

5 Ignore button was selected. (Only if flag integer is set to IGNORE)

6 Yes button was selected.

7 No button was selected.

Example:

MessageBox "Continue Running Macro?","INFORMATION",YESNO,MacroEnd% if MacroEnd% = 6 then end

MID$ Function

The MID$ Function returns a substring of a string. The MID$ statement replaces part of a string variable with another string.

Syntax:

As a Function:

MID$<stringexpression$,start%[,length%]>

As a Statement:

MID$<stringvariable$,start%[,length%]>=stringexpression$

Example:

a$ = "Where is Paris?" PRINT MID$(a$, 10, 3)

Output is "Par"

Text$ = "Paris, France" PRINT Text$

Output is "Paris, France"

MID$(Text$, 8) = "Texas" PRINT Text$

Output is "Paris, Texas"

Page 19 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 20: Cam 350 Scripting

MKDIR Statement

Creates a new directory.

Example:

MKDIR "c:\MacroTest"

This creates a directory on the C drive called MacroTest.

MOD Function

Divides one number by another and returns the remainder. Real numbers are rounded to integers.

Syntax:

numeric-expression1 MOD numeric-expression2

Example:

PRINT 19 MOD 6.7

BASIC rounds 6.7 to 7, then divides. Output is 5.

NAME Statement

Changes the name of a disk file or directory.

Syntax:

NAME <OldFilename> AS <NewFilename>

Example:

NAME "c:\Test" AS "c:\Testing"

This renames the file Test on the C drive to Testing.

OK_CANCEL Statement

Page 20 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 21: Cam 350 Scripting

The OK_CANCEL command is similar to the Print Statement except there are two buttons: Yes and No. The command returns a value (1=Yes, 0=No) which can be used as a conditional in other macro commands.

Syntax:

Ok_cancel message$, return%

Example:

FOR n = 1 to 10 PRINT "Number is",n OK_CANCEL "Continue?",OK IF OK = 1 THEN next END

OPEN Statement

Enables I/O to a file. In CAM350, it is ASCII Text based, not binary, so only the following syntaxes are accepted:

OPEN "filename" FOR INPUT AS #n OPEN "filename" FOR OUTPUT AS #n OPEN "filename" FOR APPEND AS #n

In each case, n is the number between 1 and 255, and is used to refer to the file in subsequent PRINT, WRITE, and INPUT statements

Example:

OPEN "print.data" for output as #1 PRINT #1, "This is some test data",10,33.4,"Snark",25 PRINT #1, "This is some more test data",200 CLOSE #1 END

PRINT Statement

Print opens a dialog box to display a message. The message may include variables, and can be multiple lines. This dialog box has an OK button. This box stays up, and macro execution is suspended, until OK is pressed.

Page 21 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 22: Cam 350 Scripting

Syntax:

PRINT "message",variable(s)

Example:

PRINT "Number of flashes using current Dcode: ",numflashes!

Adding CR! to your message inputs a carriage line feed. This allows you to have multiple lines in the dialog box, and control where the line breaks.

Example:

PRINT "Number of times the current Dcode Type"+CR!+"is used as a flash: ", NumdcodetypeF!

Because quotation marks are used to specify file names or text to print in macros, a special database query command, Quote!, will insert the character (") into the text that you are printing

Example:

PRINT "This is a "+Quote!+"quote."+Quote!

Output is: This is a "quote."

PRINT USING Statement

Prints strings or numbers using a specified format.

Page 22 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 23: Cam 350 Scripting

Characters that format a numeric expression

# Digit position

. Decimal point position

, Placed left of the decimal point, prints a comma every third digit

+ Position of number sign

- Placed after digit, prints trailing sign for negative numbers

$$ Prints leading $.

** Fills leading spaces with *

**$ Combines ** and $$

Characters used to format a string expression

& Prints entire string

! Prints only the first character of the string

\ \ Prints first n characters, where n is the number of blanks between slashes + 2

Characters used to print literal characters

_ Prints the following formatting character as a literal

Any character not in this table is printed as a literal.

Example:

x# = 1441.2318 PRINT USING "No Decimal ####";x#

Output would be: 1441

PRINT USING "The number with 3 decimal places ####.###";x#

Output would be: 1441.232

PRINT USING "The number with a dollar sign and 2 decimals $$##.##";x#

Output would be: $1441.23

PRINT USING "Number with plus signs +###.#### "; x#

Output would be: +1441.2318

PRINT USING "The number with a comma ##,.##";x#

Output would be: 1,441.23

b$ = "ABCDEFG"

Page 23 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 24: Cam 350 Scripting

PRINT USING "The entire string &";b$

Output would be: ABCDEFG

PRINT USING "The first character of the string !"; b$

Output would be: A

PRINT USING "The first 3 characters \ \"; b$

Output would be: ABC

PRINT#, PRINT# USING Statements

PRINT# writes data to a sequential file. PRINT# USING writes the strings or numbers using a specified format.

Characters that format a numeric expression

# Digit position

. Decimal point position

, Placed left of the decimal point, prints a comma every third digit

+ Position of number sign

- Placed after digit, prints trailing sign for negative numbers

$$ Prints leading $.

** Fills leading spaces with *

**$ Combines ** and $$

Characters used to format a string expression

& Prints entire string

! Prints only the first character of the string

\ \ Prints first n characters, where n is the number of blanks between slashes + 2

Characters used to print literal characters

_ Prints the following formatting character as a literal

Any character not in this table is printed as a literal.

Example:

Page 24 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 25: Cam 350 Scripting

OPEN "print.data" for output as #1 PRINT #1, "This is some test data",10,33.4,"Snark",25 PRINT #1, "This is some more test data",200 CLOSE #1 END

Example:

OPEN "print.data" for output as #1 a# = 123.4567 PRINT #1, USING "###.##"; a# CLOSE #1 END

Output is 123.46

PRINT_MSG, PRINT_MSG USING Statements

PRINT_MSG is similar to PRINT: you may include variables and have multiple lines. The only difference is there is no OK button. The message will remain until another print_msg or close_msg command, or until macro execution stops.

Syntax:

PRINT_MSG "message",variable(s)

Adding CR! to your message inputs a carriage line feed. This allows you to have multiple lines in the dialog box, and control where the line breaks.

Because quotation marks are used to specify file names or text to print in macros, a special database query command, Quote!, will insert the character (") into the text that you are printing.

PRINT_MSG USING prints the strings and numbers using a specified format.

Characters that format a numeric expression

# Digit position

. Decimal point position

, Placed left of the decimal point, prints a comma every third digit

+ Position of number sign

- Placed after digit, prints trailing sign for negative numbers

$$ Prints leading $.

** Fills leading spaces with *

Page 25 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 26: Cam 350 Scripting

**$ Combines ** and $$

Characters used to format a string expression

& Prints entire string

! Prints only the first character of the string

\ \ Prints first n characters, where n is the number of blanks between slashes + 2

Characters used to print literal characters

_ Prints the following formatting character as a literal

Any character not in this table is printed as a literal.

Example:

PRINT_MSG Quote!+"Promise only what you can deliver."+CR+"Then deliver more than you promise."+Quote! DELAY 5000 NEXT

Example:

a# = 123.4567 PRINT_MSG USING "###.##"; a# PRINT_MSG USING "+###.####"; a# a$ = "ABCDEFG" PRINT_MSG USING "!"; a$ PRINT_MSG USING "\ \"; a$

RESET Statement

Closes all disk files.

Example:

OPEN "print.data" for output as #1 PRINT #1, "This is some test data",10,33.4,"Snark",25 PRINT #1, "This is some more test data",200 RESET END

RETURN Statement

Returns control from a subroutine.

Example:

Page 26 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 27: Cam 350 Scripting

' This macro draws a box about any coordinate. 50 INPUT "The size of the box in inches",boxsize half = (boxsize * 1000)/2 INPUT "The center X coordinate in inches",x INPUT "The center Y coordinate in inches",y x = x * 1000 y = y * 1000 GOSUB 100 OK_CANCEL "Continue?",OK IF OK = 1 THEN GOTO 50 END ' Box drawing subroutine 100 startx = x - half starty = y - half endx = x + half endy = y + half Add_rectangle@ axy@ startx,starty axy@ endx,endy RETURN

RIGHT$ Function

Returns the right-most n characters of a string.

Example:

a$ = "Microsoft Qbasic" PRINT RIGHT$(a$, 5)

Output is "basic"

RMDIR Statement

Removes an existing directory.

Example:

RMDIR "c:\MacroTest"

This will remove a directory on your c drive called MacroTest.

RTRIM$ Function

Returns a string with trailing (right-hand) spaces removed.

Example:

Page 27 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 28: Cam 350 Scripting

a$ = " Basic " PRINT "*" + a$ + "*" 'Output is: * Basic * PRINT "*" + RTRIM$(a$) + "*" 'Output is: * Basic*

SELECT CASE Statement

This is similar to the If/Then statement, but it evaluates a single expression then executes different statements or branches to different parts of the script, based on results.

Syntax:

SELECT CASE <expression> CASE <expression> <statement> CASE ELSE <statement> END SELECT

If the expression is true, then the statement is executed. A numeric or string expression can be evaluated. End select terminates statement.

Example:

INPUT "Enter an interger between 1-9", TestValue SELECT CASE TestValue

CASE 1, 3, 5, 7, 9 PRINT "Odd"

CASE 2, 4, 6, 8 PRINT "Even"

CASE IS < 1 PRINT "Too low"

CASE IS > 9 PRINT "Too high"

CASE ELSE PRINT "Not an integer"

END SELECT

SGN Function

Indicates the sign of a number.

Example:

n = -5 PRINT SGN (n)

Output: -1

Y = 10 PRINT SGN (y)

Page 28 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 29: Cam 350 Scripting

Output: 1

SIN Function

Returns the sine of the angle x, where x is in radians.

Example:

n% = 30 PRINT SIN (n%)

Output: =0.988032

SQR Function

Returns the square root of n.

Example:

n% = 25 PRINT SQR (n%)

Output: 5.000000

STR$ Function

Returns a string representation of a number.

Example:

PRINT "The answer is: "+str$(answer%)

SUSPEND, SUSPEND USING Statements

SUSPEND stops running the macro and puts up a message box with a Resume button so you can return to the macro later. While the macro is suspended, you can use the software as if the macro weren't running at all. When you press the Resume button, execution of the macro resumes with the next instruction after the SUSPEND command.

Syntax:

SUSPEND <message$>

Page 29 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 30: Cam 350 Scripting

message$ is the text in the message box which is displayed when the macro is executed.

SUSPEND USING displays a message in the specified format.

Characters that format a numeric expression

# Digit position

. Decimal point position

, Placed left of the decimal point, prints a comma every third digit

+ Position of number sign

- Placed after digit, prints trailing sign for negative numbers

$$ Prints leading $.

** Fills leading spaces with *

**$ Combines ** and $$

Characters used to format a string expression

& Prints entire string

! Prints only the first character of the string

\ \ Prints first n characters, where n is the number of blanks between slashes + 2

Characters used to print literal characters

_ Prints the following formatting character as a literal

Any character not in this table is printed as a literal.

Example:

FOR n = 1 to 10 PRINT_MSG "number is", n DELAY 500 SUSPEND CLOSE_MSG

Example:

SUSPEND USING "###.##",123.45

SWAP Statement

Page 30 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 31: Cam 350 Scripting

Exchanges the values of two variables.

Example:

Temp$ = "123456" Temp2$ = "789" SWAP Temp$, Temp2$ PRINT Temp$ PRINT Temp2$

Output: "789"

Output: "123456"

TAN Function

Returns the tangent of the angle x, where x is in radians.

Example:

n% = 30 PRINT TAN (n%)

Output: -6.405331

UCASE$ Function

Returns a string expression with all letters in uppercase.

Example:

Test$ = "THE string" PRINT Test$ PRINT UCASE$(Test$); " IN UPPERCASE"

VAL Function

Returns the numeric value of a string of digits.

Example:

n$ = 3456 PRINT VAL (n$)

Output: 3456

Page 31 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 32: Cam 350 Scripting

WINCALL Statement

Allows the macro to execute an external application (Notepad, etc), and waits for the application to exit before returning control to the calling macro.

Note: This command is recommended for advanced macro programmers.

Syntax:

WinCall commandline$ [, cmdshow] [, return%]

commandline$ is the full path and name of the external program, along with all parameters (e.g. "d:\mybin\prog.exe param1 param2"). Spaces may be used in parameters and paths, but they must be surrounded by quotes ("): e.g. commandline$ = chr$(34) + "d:\my bin\prog.exe" + chr$(34) + " " + chr$(34) + "param" + chr$(34) produces the following character string: "\"d:\my bin\prog.exe\" \"param\"" (Here \" is " in the string)

cmdshow is a keyword for how a Windows-based application window is to be shown. Values for cmdshow are (if value is not provided, NormalFocus is assumed):

Show = window has focus and is restored to its original size and position.

Hide = window is hidden and focus is passed to the hidden window.

NormalFocus = window has focus and is restored to its original size and position.

MinimizedFocus = wiindow is displayed as an icon with focus.

MaximizedFocus = wiindow is maximized with focus.

NormalNoFocus = window is restored to its most recent size and position. The currently active window remains active.

MinimizedNoFocus = wiindow is displayed as an icon. The currently active window remains active.

cmdshow can be an integer instead. (See the "Microsoft Win32 API" for more information about the integer values for cmdshow, under ShowWindow).

return% is the return code from the external program. This is a value defined by the external program, so you must check its documentation for the appropriate value. (Note: 0 usually means the program finished successfully - but that is not guaranteed).

Example:

Program$ = chr$(34) + "d:\programs\notepad.exe" + chr$(34) + " " + chr$(34) + "param" + chr$(34) WinCall Program$, Show, Done% if Done% = 0 then print "External Application was closed"

Page 32 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 33: Cam 350 Scripting

WINEXEC Statement

Like WinCall, allows the macro to execute an external application (Notepad, etc), but does not wait for the application to exit before returning control to the calling macro (like WinCall does).

Note: This command is recommended for advanced macro programmers.

Syntax:

WinExec commandline$ [, cmdshow]

commandline$ is the full path and name of the external program, along with all parameters (e.g. "d:\mybin\prog.exe param1 param2"). Spaces may be used in parameters and paths, but they must be surrounded by quotes ("): e.g. commandline$ = chr$(34) + "d:\my bin\prog.exe" + chr$(34) + " " + chr$(34) + "param" + chr$(34) produces the following character string: "\"d:\my bin\prog.exe\" \"param\"" (Here \" is " in the string)

cmdshow is a keyword for how a Windows-based application window is to be shown. Values for cmdshow are (if value is not provided, NormalFocus is assumed):

Show = window has focus and is restored to its original size and position.

Hide = window is hidden and focus is passed to the hidden window.

NormalFocus = window has focus and is restored to its original size and position.

MinimizedFocus = wiindow is displayed as an icon with focus.

MaximizedFocus = wiindow is maximized with focus.

NormalNoFocus = window is restored to its most recent size and position. The currently active window remains active.

MinimizedNoFocus = wiindow is displayed as an icon. The currently active window remains active.

cmdshow can be an integer instead. (See the "Microsoft Win32 API" for more information about the integer values for cmdshow, under ShowWindow).

Example:

Program$ = chr$(34) + "d:\programs\notepad.exe" + chr$(34) + " " + chr$(34) + "param" + chr$(34) WinExec Program$, Show

Page 33 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...

Page 34: Cam 350 Scripting

WRITE# Statement

Writes data to a sequential file.

Example:

OPEN "write.dat" for output as #1 WRITE #1, "This is some test data",10,33.4,"Snark",25 WRITE #1, "This is some more test data",200 CLOSE #1 END

Page 34 of 34Basic Commands

10/11/2011mk:@MSITStore:c:\program%20files\downstream%20technologies\cam350%2010.5\ca...