Open in a New Window

BASICCAD STATEMENTS:

Provided by Bob Putman

Download PDF file: cmdref.pdf

The purpose of each statement is described, along with its syntax. An explanation and example of each statement is also provided.

ASSIGNMENT Statement
ANYKEY Statement
CHAIN Statement
CLEAR Statement
CLOSE Statement
CLS Statement
COLOR Statement
DIM Statement
DO WHILE and LOOP Statements
END Statement
ENTITY Statement
EXIT DO Statement
EXIT FOR Statement
FOR and NEXT Statements
GET Statement

GETATTR Statement
GETSELECT Statement
GETXY Statement
GOSUB and RETURN Statements
GOTO Statement
IF Statement (single line)
IF Statement (Group IF)
INPUT Statement
INPUT # Statement
LABELS
LAYER Statement
LOCATE Statement
MESSAGE Statement
ON ERROR Statement


OPEN Statement
POINTVAL Statement
PRECISION Statement
PRINT Statement
PRINT # Statement
PUT Statement
PUTATTR Statement
RESUME Statement
RUN Statement
SETPOINT Statement
STOP Statement
TAB Statement
WCLOSE Statement
WINDOW Statement

Usage Note

A note on usage in this section:

Statement

 

Refers to a BasicCAD statement. See "BasicCAD Statements" for a description of these.

Function

Refers to a BasicCAD function, such as SIN(x) or SYS(32). See "BasicCAD Built-in Functions" for a description of these.

Macro Command

Refers to a DesignCAD 3D MAX Plus for Windows drawing command, such as Line or Hatch. The DesignCAD 3D MAX Plus macro commands are listed in "DesignCAD 3D MAX Plus Command List."

Macro Parameter

Refers to an argument necessary for a DesignCAD 3D MAX Plus command. Parameters may be numerical values or strings, and variables can be substituted for constants. The DesignCAD 3D MAX Plus macro parameters are listed after the macro commands. in "DesignCAD 3D MAX Plus Command List."

ASSIGNMENT Statement

PURPOSE:

To assign a value to a numeric variable.

SYNTAX:

    variable = expression

EXPLANATION:

"Variable" can be any numeric variable name. "Expression" can be any valid numeric expression.

"Stringvar" is any valid string variable name. "Expressionlist" is one or more string or numeric expressions separated by commas. Numeric expressions can be assigned to a string – they are evaluated and converted to ASCII format. Using more than one expression allows you to concatenate strings.

EXAMPLES:

x = sin(t) + 3 * j ^ 2

xpos = xpos + 1

z=sqr(var(2))

xp(j) = xp(k) * 2

a$ = "This is a test"

j = 23

b$ = "the answer is ", j    

' b$ is "the answer is 23"

a1$ = "1234"

a2$ = "5678"

a3$ = a$, b$                            ' a3$ is "12345678"


ANYKEY Statement

PURPOSE:

To wait for a single key press.

SYNTAX:

    ANYKEY {variable}

EXPLANATION:

The ANYKEY statement waits for and reads keystrokes from the keyboard. This statement can be used with or without a variable. If a variable is used, then the value of the key pressed is assigned to that variable. String variables or numeric variables can be used. If a numeric variable is used, the ASCII code of the keystroke is assigned to the variable. Pressing a mouse button will act as a keystroke, but will assign no value to the variable in the ANYKEY statement.

 This statement is useful if you want to pause for a key press after printing to the bottom of the screen or to a text window.

EXAMPLE:

ANYKEY

ANYKEY A$  ' Read a keystroke into A$

ANYKEY KEY    ' Read a keystroke into KEY



CHAIN Statement

PURPOSE:

To transfer control to another BasicCAD program.

SYNTAX:

    CHAIN programname

EXPLANATION:

This statement is used to run another BasicCAD program, leaving all the variables from the current program intact when the other program is executed. A string variable or constant can be used for the program name.

The CHAIN statement causes the new program (programname) to replace the current program in memory. To return to the original program, you must execute another CHAIN or RUN statement from the new program. The execution of a program called by the CHAIN statement always begins at the first line in the called program.

The RUN statement is similar to the CHAIN statement, but the RUN statement clears all variables before executing the new program.

Note: If you use a CHAIN statement that calls an encrypted (.BSX) BasicCAD program, you must specify the filename complete with its .BSX extension.

EXAMPLE:

CHAIN PGMNAME$

CHAIN "TEST1"

CHAIN "SECRET.BSX"



CLEAR Statement

PURPOSE:

To erase all variables in the program.

SYNTAX:

    CLEAR

EXPLANATION:

This statement is used to erase and de-allocate all variables in the program. It can be used to free memory or to re-initialize variables.

EXAMPLE:

CLEAR



CLOSE Statement

PURPOSE:

To close a disk file.

SYNTAX:

    CLOSE { filenumber }

EXPLANATION:

This statement is used with the OPEN statement. If a disk file has been opened for input or output, it should be closed after being used. Filenumber is the number of the file to be closed. If it is omitted, all open files will be closed.

A disk file left open when the program ends is automatically closed. However, the CLOSE statement must be used to close an open file before that file number is used again.

EXAMPLE:

CLOSE 1



CLS Statement

PURPOSE:

Clear a text window.

SYNTAX:

    CLS

EXPLANATION:

The CLS statement clears all the text inside the text window. If a text window is not open, this statement has no effect. See the WINDOW statement for more information on text windows.

EXAMPLE:

window 5, 30            ' open a window 5 lines x 30 chars.

print "press any key to continue..."

anykey ' move to column 20

cls        ' clear the text window



COLOR Statement

PURPOSE:

Set the text color in a text window.

SYNTAX:

    COLOR foreground {, background}

EXPLANATION:

This statement is used to set the color of text in a text window.

Foreground is the foreground color for the text, and background is the background color. The colors can range from zero to 19. These numbers correspond to the standard Windows palette, not to DCW’s palette.

The COLOR statement affects only the text displayed with PRINT statements after the COLOR statement is executed. The text color remains set at the specified color until the next COLOR statement is executed.

EXAMPLE:

precision 0                  ' print numbers as integers

window 20, 30              ' open a window 20 lines x 30 chars.

for i = 0 to 19              ' start a loop to change the

                                                ' foreground color

color 0,i      ' foreground 0, background i

print "this is a test of color", i

next i

anykey



DIM Statement

PURPOSE:

To specify the size of one or more arrays.

SYNTAX:

DIM variable(expression) {, variable(expression)...}

EXPLANATION:

The DIM statement is used to allocate storage for arrays. An array is a single variable with several elements, addressed with a subscript in parentheses such as: A(20).

An array must be dimensioned before it is used. Any numeric expression can be used for the array size. String arrays are allowed. All arrays are one-dimensional – that is, an array can have only one subscript.

An array cannot be re-dimensioned. A DIM statement must be executed only once. A variable array must be dimensioned before the variable is used.

EXAMPLES:

dim a(10)

dim jx(200), jy(200)

dim a$(20)

n = 15

dim point(n)



DO WHILE and LOOP Statements

PURPOSE:

To execute a series of instructions in a loop.

SYNTAX:

DO WHILE logexpression

.



LOOP

EXPLANATION:

The DO WHILE statement is used to start a loop that will be executed as long as the logical expression "logexpression" is true. When the LOOP statement is encountered, program execution is transferred back to the DO WHILE statement and the logical expression is checked again. When the expression is false, execution continues after the LOOP statement.

The logical expression consists of one or more relational expressions separated by AND or OR. A logical expression can also be preceded by NOT.

A relational expression consists of two numeric or string expressions separated by one of the following relational operators: <, <=, =, >=, >, <>.

When using a DO loop, be sure the logical expression will eventually change to false, or the loop will never end. (Any BasicCAD program can be terminated by pressing the Esc key, however.)

DO WHILE loops can be nested up to eight levels deep.

EXAMPLE:

j = 1

do while j < 20

 print j

 j = j * 2

loop

print "done"

prints:   1.000

            2.000

            4.000

            8.000

            16.000

            done



END Statement

PURPOSE:

To terminate the program and return to DesignCAD 3D MAX Plus.

SYNTAX:

END

EXPLANATION:

The END statement can be placed anywhere in the program. An END statement at the end of the program is optional. This statement is the same as the STOP statement.

EXAMPLE:

if i > max then end



ENTITY Statement

PURPOSE:

To access an entity in the drawing by entity number.

SYNTAX:

ENTITY expression

EXPLANATION:

The ENTITY statement is used to read an entity into the SYS function variables 90-99. The entity is accessed by entity number – the arbitrary order in which the entity was placed in memory. This makes it possible to process all entities in the drawing. The Entity statement also places all of the entity's points into memory (as if the user had set the points manually) so that they can be accessed by POINTVAL.

Note that for Grid entities, entity type 32, sys (99) represents not the number of points, but the number of individual Grid Line entities (type 33) to follow. For each Grid Line, sys (99) retains its normal meaning.

EXAMPLE:

' count the number of circle entities in layer 20

' sys(9) is the number of entities in the drawing

n = 0

for j = 1 to sys(9)

  entity j

  ' sys(93) = layer, and sys(90) = entity type

  if sys(93) = 20 and sys(90) = 16 then n = n + 1

  next j

message "number of circles: ", n


EXIT DO Statement

PURPOSE:

To exit a DO loop prematurely.

SYNTAX:

EXIT DO

EXPLANATION:

The EXIT DO statement can be used to exit a DO loop from anywhere within the loop. This makes it easy to exit a DO loop without using a label and a GOTO statement.

EXAMPLE:

do while i < 1000

  anykey keycode

  if keycode = 27 then exit do

  loop



EXIT FOR Statement

PURPOSE:

To exit a FOR-NEXT loop prematurely.

SYNTAX:

EXIT FOR

EXPLANATION:

The EXIT FOR statement can be used to exit a FOR-NEXT loop from anywhere within the loop. This makes it easy to exit a FOR-NEXT loop without using a label and a GOTO statement.

EXAMPLE:

for j = 1 to 100

  anykey keycode

  if keycode = 27 then exit for

  next



FOR and NEXT Statements

PURPOSE:

To execute a section of the program a certain number of times.

SYNTAX:

FOR variable = expression TO expression {STEP expression}

EXPLANATION:

The "variable" is used as the counter. The first "expression" is the initial value of the counter variable. The second "expression," after "TO," is the test or final value of the counter. The optional STEP "expression" can be used to specify the amount that the counter is incremented each iteration.

The program statements after the FOR statement and before the NEXT statement are called the loop. Each time the loop is executed, the counter is incremented. If it is greater than the test value, the loop is exited and the program branches to the line following the NEXT statement. (If the STEP "expression" is negative, then the loop is exited when the counter is less than the test value.)

FOR-NEXT loops can be nested, that is, one FOR loop can be placed inside another. The FOR-NEXT loops can be nested up to eight levels deep.

EXAMPLES:

for j = 1 to 4                 'output:            1.00

  print j                         '                       2.00

  next                            '                       3.00

                                    '                       4.00

for j = 4 to 1 step -1    output:         4.00

  print j                                            3.00

  next                                               2.00

                                                       1.00

for j = 1 to 2                output:              1.000 1.000

  for k = 1 to 3                                    1.000 2.000

    print j, k                                            1.000 3.000

    next                                                    loop 1

  print "loop 1"                                         2.000 1.000

  next                                                         2.000 2.000

                                                                  2.000 3.000

                                                                    loop 1

for j = 2 to 1

            print "this will not be printed"

            next



GET Statement

PURPOSE:

To read a record from a random access file

SYNTAX:

GET file, recordnumber, stringvar

EXPLANATION:

This statement is used to read a record from a random access file. The record length is specified in the OPEN statement.

When the GET statement is executed, the designated record (recordnumber) of the file will be read into the string variable (stringvar). The MKS$ and the CVS functions can be used to convert numeric values to and from four-byte strings for file input and output.

EXAMPLE:

open "r," 1, "test.dat," 80

for j = 1 to 10

  input "Enter the record number: ", recno

  get 1, recno, a$     ' get record recno

  print right$(a$, 20) ' print the last 20 bytes

  next j



GETATTR Statement

PURPOSE:

To get entity type, group status, and layer of an entity.

SYNTAX:

    GETATTR entity, type {,select, layer, group, red, green, blue, solid}

("Solid" represents the identifying number of the solid of which the entity is a part. If the entity is not part of a solid, then solid returns zero.)

EXPLANATION:

This statement is used to get the entity type, group status, and layer of an entity. Entity is the entity number – one for the first entity in the drawing, two for the second, etc. Type is the entity type, as shown:

1 = Line

2 = Ellipse

3 = Text

4 = Curve

7 = Elliptical Arc

11 = Bezier Curve

15 = Attribute

16 = Circle, Circular Arc

17 = Hatch

21 = New Layer

22 = Text Arc

23 = Layer Names

24 = Arrow

26 = Symbol

31 = Plane

32 = Grid

33 = Grid Line

70 = Point Ma

74 = Dimension, Angle

75 = Dimension

76 = Dimension, Diameter/Radius

77 = Dimension, Arc

78 = Dimension, Radius Progressive

79 = Dimension, Progressive

80 = Dimension, Chamfer

81 = Dimension, Coordinate

90 = Bitmap Image

Note that not all of these types can be created in DesignCAD 3D MAX Plus. They are included, nevertheless, because they may be encountered in drawings which were created using DesignCAD 2D.

Select is zero if the entity is not selected, or one if the entity is currently selected. Layer is the layer number of the entity. Group is the group ID number if the entity is part of a Group, or zero otherwise. Red, green, and blue are the color components of the entity's color.

Type, select, layer, group, red, green, and blue must be BasicCAD variables, not expressions, since they will be assigned values.

EXAMPLE:

'Get total length of all lines in the drawing.

l = 0

for j = 1 to sys(9)

                                    'sys(9) is the number of entities

  getattr j, type, group, layr

  if type = 1 then l = l + length(j)

  next

message "The length is ", l



GETSELECT Statement

PURPOSE:

To get the entity number(s) of the currently selected entity(s)

SYNTAX:

    GETSELECT expression, variable

EXPLANATION:

This statement can be used to retrieve entity numbers of selected items so these items can be investigated with the ENTITY statement, if desired, or information about the entities can be retrieved with GETATTR and changed with PUTATTR. "Expression" is a number, variable, or mathematical expression evaluating to an integer; this number determines which of the selected entities you want the entity number for. "Variable

" is the name of the variable you want to store the entity number in.

GETSELECT will ignore any selection status changes made by the PUTATTR statement. Entities must have been selected by the DesignCAD Select command, either earlier in the BasicCAD program or before you ran the program.

EXAMPLE: (assumes you have already selected as many as ten items before running the program)

dim ent(10)                               'set up an array for entity numbers

maxsel=(sys(80)*(sys(80)<10)) + (10*(sys(80)>=10))

window 10,40

for j = 1 to maxsel

  getselect j, ent(j) 'get info for selected items

  print "Picked item ",j, " is entity ", ent(j)

  next j                 'go to the next item

anykey



GETXY Statement

PURPOSE:

To get the X, Y, Z coordinates of the current cursor position

SYNTAX:

    GETXY variable variable variable

EXPLANATION:

This statement can be used to assign the X, Y, Z coordinates of the current cursor position to three variables. It is very useful in getting the "current" position to provide a reference location for the rest of the program.

EXAMPLE:

getxy x1 y1 z1

>line

{

for j = 0 to 360 step 45

  x = x1 + cos(j) * 10

  y = y1 - sin(j) * 10

  <pointxyz [x, y, z1]

  next j

}



GOSUB and RETURN Statements

PURPOSE:

To call a subroutine.

SYNTAX:

    GOSUB label

RETURN

EXPLANATION:

The GOSUB statement is used to transfer program execution to another statement out of the normal sequence of execution. This statement resumes execution after the GOSUB statement when a RETURN statement is encountered – it calls a subroutine. "Label" can be any valid BasicCAD label. A RETURN statement must be used to return from a subroutine called by a GOSUB statement.

EXAMPLE:

  x = 20

  y = 20

  gosub rotate

  >line

  {

  <pointxyz [gx1, gy1, gz1]

  <pointxyz [x1, y1, gz1]

  rotate:

  x1 = gx1 + sine * x + cosine * y

  y1 = gy1 - cosine * x + sine * y

  return



GOTO Statement

PURPOSE:

To branch to another statement.

SYNTAX:

    GOTO label

EXPLANATION:

This statement is used to transfer program execution to another statement out of the normal sequence of execution. "Label" can be any valid BasicCAD label.

EXAMPLE:

retry:

  input "enter a number less than 20: ", x

  if x >= 20 then goto retry



IF Statement (single line)

PURPOSE:

To execute a BasicCAD statement under certain conditions.

SYNTAX:

    IF logexpression THEN statement

EXPLANATION:

"Logexpression" is a logical expression that can be answered true or false. If the expression is true, then the "statement" is executed; otherwise, it is not.

The logical expression consists of one or more relational expressions separated by AND or OR. A logical expression can also be preceded by NOT.

A relational expression consists of two numeric or string expressions separated by one of the following relational operators: <, <=, =, >=, >, <>.

EXAMPLES:

if eof(1) <> 0 then end

retry:

  input "enter a number less than 20: ", x

  if x >= 20 then goto retry

if a$ = "y" then goto affirm



IF Statement (Group IF)

PURPOSE:

To execute a set of BasicCAD statements under certain conditions.

SYNTAX:

    IF logexpression THEN

statements

.

.

{ ELSE

statements

.

. }

END IF

EXPLANATION:

"Logexpression" is a logical expression that can be answered true or false. If the expression is true, then the first set of statements is executed, otherwise the second set is executed. The ELSE section is optional, but the END IF is required.

The logical expression consists of one or more relational expressions separated by AND or OR. A logical expression can also be preceded by NOT.

A relational expression consists of two numeric or string expressions separated by one of the following relational operators: <, <=, =, >=, >, <>.

With the Group IF statement, the IF statement line must end with the word "THEN" (except for comments). In contrast, the single-statement IF must have the conditionally executed statement following the word "THEN" on the same line.

EXAMPLES:

if eof(1) <> 0 then

  print "end-of-file was encountered."

  end           ' stop the program

  end if

if j > 90 then

  print "j is too large: ", j

else

  x = sin(j) * l

  y = y + 1

  end if




INPUT Statement

PURPOSE:

To read a value from the keyboard and assign it to a variable.

SYNTAX:

    INPUT string, variable list
    INPUT variable list

EXPLANATION:

The INPUT statement is used to ask the user for input and assign the entered value to a variable. "String" is an optional message to be displayed for the user. "Variable list" is one or more variables, separated by commas, to which the input values are to be assigned.

If a single string variable is used, the entire string input from the keyboard is assigned to the variable.

If numeric variables are used, the numbers input from the keyboard are assigned to the corresponding variables.

If more than one variable is used with the INPUT statement, any strings input should be enclosed in quotes ("").

Values read with the INPUT statement can be any valid BasicCAD expressions – they do not have to be simple constants. For example, the user can enter SQRT(2) or 45/2 when a number is requested.

EXAMPLES:

input "Enter the initial value: ", init

input "Enter the input file name: ", file$


open "i", 1, file$

input "Enter the coordinates: ", x, y, z


INPUT # Statement

PURPOSE:

To read a line from a disk file and assign it to a variable.

SYNTAX:

    INPUT #file, variablelist

EXPLANATION:

This statement is used to read a line from a disk file and assign it to a numeric variable or to a string variable. The INPUT statement reads an entire line from the disk file. File is the file number that was used in the OPEN statement. Variablelist is a set of one or more variables separated by commas. The variables can be string or numeric variables.

When this statement is executed, a line from the file is read and a value is assigned to each variable. If the line from the file has fewer values than there are variables, the leftover variables are not modified.

String values in the file should be enclosed in quotes if there are multiple values on a line. If an entire line from the file is to be read into a single string variable, use a single string variable with the INPUT # statement.

Values read can be any valid BasicCAD expressions – they do not have to be simple constants.

The file must have been opened using the OPEN statement before the INPUT # statement is executed. The BasicCAD function EOF(file) can be used to determine whether the end-of-file has been reached.

EXAMPLES:

for j = 1 to 20

  input #1, jx(j), jy(j)

  next

input #1, name$

open "i", 2, "testfile"

do while eof(1) = 0

  input #2, a$

  print a$

  loop



LABELS

PURPOSE:

To provide a reference to locations in the program for GOTO or RESUME statements.

SYNTAX:

label:

EXPLANATION:

"Label" can be up to seven characters long, may consist of letters and numbers, and must begin with a letter. A BasicCAD statement can optionally follow a label on a line.

EXAMPLE:

retry:  ' this is a label

  input "Enter a number less than 20: ", x

  if x >= 20 then goto retry



LAYER Statement

PURPOSE:

To turn drawing layers on or off, and to set the current layer.

SYNTAX:

LAYER(expression) = expression

EXPLANATION:

The LAYER statement can be used to set a layer to be visible/invisible or editable/uneditable. It can also be used to set the current layer. The following values can be used with the LAYER statement:

 0 – Invisible and not editable

 2 – Visible but not editable

 6 – Visible and editable

 14 – Set as current layer

The first expression is the layer number, and the second expression must be one of the above values. The LAYER function can be used to get the current status of a layer. See the BasicCAD function descriptions in this Help file.

The DesignCAD >Regenerate command should be used to regenerate the drawing if the visibility of layers has been changed. Otherwise, entities from invisible layers may remain on the screen. Entities from visible layers may not appear on the screen.

If you have used PUTATTR to change the layer of an item, you must use the LAYER statement to reset the current layer in order for the layer info in the coordinate bar to display correctly. You can use:

layer(sys(3)) = 14

'this updates the layer information in the 'drawing.    

EXAMPLES:

layer(1) = 14  ' set the current layer to layer 1

for j = 0 to 255  ' make all visible and editable

  layer(j) = 6

  next j



LOCATE Statement

PURPOSE:

To position the cursor in a text window.

SYNTAX:

LOCATE row, column

EXPLANATION:

The LOCATE statement positions the cursor in the text window that was opened by the WINDOW statement. The next PRINT statement will begin at the specified row and column.

This statement has no effect if a text window is not open.

EXAMPLE:

window 7, 40

locate 3, 9

print "centered in the window"

anykey



MESSAGE Statement

PURPOSE:

To output data to the screen.

SYNTAX:

MESSAGE { list of expressions }

EXPLANATION:

The MESSAGE statement is used to output numeric and/or string expressions to the DesignCAD screen. It is similar to the PRINT statement, except that a dialog box is opened for each message statement. The program pauses until the user presses the OK button. This command uses the Windows Message Box function.

If more that one line is to be output, chr$(13) can be included in the output expressions.

EXAMPLES:

message j, " is the current value."

message "x: ", x, chr$(13), "y: ", y

'(This puts x and y on separate lines in the same 'message box.)



ON ERROR Statement

PURPOSE:

To set up an error handling routine.

SYNTAX:

ON ERROR GOTO label

EXPLANATION:

After the ON ERROR statement has been executed, any BasicCAD error will cause the execution to be transferred to the specified label. Program execution will continue until a RESUME statement is encountered.

This statement is used to trap errors in a program. The ERR function can be used to determine the error code. See the RESUME statement.

EXAMPLE:

on error goto handler

  open "i", 1, "------"     ' invalid file name

  print "No Error"               ' this won't be printed

cont:

  print "Program Done"   ' second line printed

  end

handler:

  print "Error: ", err(1)   ' first line printed

  resume cont



OPEN Statement

PURPOSE:

To open a file for input or output for the INPUT #, PRINT #, GET, or PUT statements.

SYNTAX:

OPEN "A", filenumber, filename

OPEN "I", filenumber, filename

OPEN "O", filenumber, filename

OPEN "R", filenumber, filename, recordlength

EXPLANATION:

A file must be opened before it is accessed by the INPUT # or PRINT # statements. To open a file for sequential input, use the "I" parameter before the file name. To open a file for sequential output, use "O." (This is the letter O, not the number zero.) You can use "A" to append data to a file – this is like "O", but if the file exists, data will be output to the end of the file.

To open a file for random access (for GET and PUT), use "R." If random access is specified, then the record length must also be specified. This value represents the number of bytes that will be read or written with the GET and PUT statements.

LPT1 can be specified for the file name in order to output to the printer. However, LPT1 can be used only for output, with OPEN "O."

The filenumber can be one to four. Up to four files can be opened at one time. Filename can be any valid DOS file name, including the path.

EXAMPLES:

open "o", 1, "outfile"

input "Enter the input file name: ", file$

open "i", 1, file$

open "r", k, file$, 80



POINTVAL Statement

PURPOSE:

To assign the coordinates of one of the points that has been set to two variables.

SYNTAX:

POINTVAL variable variable variable  expression

EXPLANATION:

The three "variables" will be assigned the X, Y, and Z coordinates of the point that has been set in DesignCAD. The "expression" determines which point will be assigned to the variables. The number of points currently set can be determined in the system function SYS(1). An error will occur if expression is greater than the number of points set in SYS(1).

EXAMPLES:

pointval x y z 1  ' coordinates of first point

' get all points into jx, jy, jz

for j = 1 to sys(1)

  pointval jx(j) jy(j) jz(j) j

  next j



PRECISION Statement

PURPOSE:

To set the precision for PRINT statements and for numeric-to-string conversions.

SYNTAX:

PRECISION expression

EXPLANATION:

The PRECISION statement determines the number of digits to the right of the decimal point to be used in PRINT statements and in numeric-to-string conversions.

For example, a precision of zero can be used to print or assign only whole numbers. A precision of four can be used to print numbers to the nearest .0001.

The PRECISION statement affects only the conversion of an expression – it does not affect the value of a numeric variable.

The precision remains the same until it is changed again by the PRECISION statement.

EXAMPLE:

x = 44.123456789

precision 0

print x * 2                     ' prints "88"

precision 4

print x                           ' prints "44.1235"

precision 0

x = 2

a$ = x

f$ = "file" + a$ + ".dat"

print f$                         ' prints "file2.dat"



PRINT Statement

PURPOSE:

To output data to the screen.

SYNTAX:

PRINT { list of expressions }

EXPLANATION:

The PRINT statement is used to output numeric and/or string expressions to the DesignCAD screen. It is identical to the PRINT # statement, except the data is output to the screen rather than to disk.

Only one line of output can be displayed at a time, unless a text window is open. If more that one line is to be output, the PRINT statements can be separated by ANYKEY statements. This requires the user to press a key before the next line is displayed.

If a text window is open (see the WINDOW statement), the PRINT statement will be displayed in the window. The LOCATE and TAB statements can be used to position the output for the window.

The PRINT statement can be terminated with a semicolon (";") to leave the cursor at the end of the line of a text window. The next PRINT statement will begin at that location.

The MESSAGE statement is similar to the PRINT statement, but the MESSAGE statement opens a dialog box for the message. The user must press the OK button to continue after the message is displayed.

EXAMPLES:

print j, " is the current value."

print "x: ", x, " Press any key to continue"

anykey

print "y: ", y

window 5, 20

print "abcd";

print "efgh"            ' "abcdefgh" will be printed



PRINT # Statement

PURPOSE:

To output data to a disk file.


SYNTAX:


PRINT #file, { list of expressions }


EXPLANATION:


The PRINT # statement is used to output numeric and/or string expressions to a disk file. It is identical to the PRINT statement, except the data is output to disk rather than the screen. File is the file number that was used in the OPEN statement.
The file must have been opened using the OPEN statement before this statement is executed. Numeric expressions are output in ASCII format. A carriage-return and line-feed are output after each PRINT # statement.

The PRINT # statement can be used to output to a printer by opening the file "LPT1" with the OPEN statement. If no expressions are used with a PRINT # statement, a blank line is output.


EXAMPLE:

open "o", 1, "filename"
open "o", 2, "filetwo"
print #1, j, " is the current value."
print #2, "x = ", x
j = 2
print #j, x, y, z
print #1


PUT Statement

PURPOSE:

To output a record to a random access file

SYNTAX:

PUT file, recordnumber, stringexpression

EXPLANATION:

This statement is used to output a record to a random access file. The record length is specified in the OPEN statement.

When the PUT statement is executed, the string (stringvar) will be written to the file at the designated record (recordnumber).

If the string to be output is less than the record length, it will be padded with undefined characters. If the string is longer than the record length, it will be truncated.

The MKS$ and the CVS functions can be used to convert numeric values to and from four-byte strings for file input and output.

EXAMPLE:

open "r", 1, "test.dat", 80

'           read a name and address into the first and

'           second 40 bytes of an 80 byte record then

'           output it to record number three.

  input "Enter the name: ", name$

  input "Enter the address: ", address$

  i = 40 - len(name$)

  a$ = name$ + string$(i, " "), address$

  put 1, 3, a$        ' output to record three

  next j



PUTATTR Statement

PURPOSE:

To set the entity type, group status, and layer of an entity.

SYNTAX:

PUTATTR entity, type, {,select, layer, group, red, green, blue, solid}

("Solid" represents the identifying number of the solid of which the entity is a part. If the entity is not part of a solid, then set solid to zero.)

EXPLANATION:

This statement is used to set the entity type, status, layer, or group of an entity. Entity is the entity number – one for the first entity in the drawing, two for the second, etc. The specified entity will be assigned the specified attributes.

Type is the entity type, as shown:

1 = Line

2 = Ellipse

3 = Text

4 = Curve

5 = Elliptical Arc

11 = Bezier Curve

15 = Attribute

16 = Circle, Circular Arc

17 = Hatch

21 = New Layer

22 = Text Arc

23 = Layer Names

24 = Arrow

26 = Symbol

31 = Plane

32 = Grid

33 = Grid Line

70 = Point Mark

74 = Dimension, Angle

75 = Dimension

76 = Dimension, Diameter/Radius

77 = Dimension, Arc

78 = Dimension, Radius Progressive

79 = Dimension, Progressive

80 = Dimension, Chamfer

81 = Dimension, Coordinate

90 = Bitmap Image

Select is zero if the entity is not to be selected, and one if the entity is to be selected. Layer is the layer number to be assigned to the entity. Group is the group ID number if the entity is to become part of that Group, or zero if it is not to be part of a Group. Red, green, and blue define the color for the entity.

EXAMPLE:

' Change all entities in layer 6 to layer 12.

l = 0

for j = 1 to sys(9)   ' sys(9) is the number of entities

  getattr j, type, select, layr, group, red, green, blue

  if layr = 6 then layr = 12

  putattr j, type, select, layr, group, red, green, blue

  next j



RESUME Statement

PURPOSE:

To resume program execution after an ON ERROR unit.

SYNTAX:

RESUME { label }

EXPLANATION:

The RESUME statement is used to continue program execution after an ON ERROR unit has been activated by a BasicCAD error.

Label can be used to specify the location at which program execution will resume. If the label is omitted, the program execution will resume at the statement following the statement that caused the error.

See the ON ERROR statement.

EXAMPLE:

  on error goto handler

  open "i", 1, "------"                 ' invalid file name

  print "No error"               ' this won't be printed

cont:

  print "Program done"   ' second line printed

  end

handler:

  print "Error: ", err(1)   ' first line printed

  resume cont



RUN Statement

PURPOSE:

To transfer control to another BasicCAD program or to a DOS or Windows program.

SYNTAX:

RUN programname$

EXPLANATION:

The Run statement can be used to run another BasicCAD program or a COM or EXE program from within your BasicCAD program.

Running another BasicCAD program with the RUN statement

When this statement is used to run another BasicCAD program, all the variables from the current program are cleared when the other program is executed. A string variable or constant can be used for the program name.

The RUN statement causes the new program (programname) to replace the current program in memory. To return to the original program, you must execute another RUN or CHAIN statement from the new program. The execution of a program called by the RUN statement always begins at the first line in the called program.

If the file extension of the BasicCAD program is omitted, .BSC will be used. To use an encrypted BasicCAD program, specify the extension .BSX.

The CHAIN statement is similar to the RUN statement, but the CHAIN statement leaves all variables intact when the new program is executed.

Running a BAT, COM, or EXE program with the RUN statement

To run a program from within BasicCAD, just specify the program name with the RUN statement. For example,

run "edit.com c:\files\test.dat"

This command will run the DOS editor EDIT and automatically load the file TEST.DAT The BasicCAD program will continue after EDIT.COM is closed.

With the RUN statement, you can run both DOS and Windows applications.

EXAMPLE:

run pgmname$

run "test1"

run "edit.com myfile.bsc"

message "Finished Editing"



SETPOINT Statement

PURPOSE:

To require the user to set a number of points.

SYNTAX:

SETPOINT string expression

EXPLANATION:

This statement displays the message in "string," and allows the user to set a number of points. "Expression" is the number of points to be set. The user can press Enter or Esc before all the points are set. The system function SYS(1) is the current number of points set – it can be checked to determine if enough points were set.

EXAMPLE:

retry:

  setpoint "Set 2 to 4 points." 4

  if sys(1) < 2 then goto retry



STOP Statement

PURPOSE:

To terminate the program and return to DesignCAD.

SYNTAX:

STOP

EXPLANATION:

The STOP statement can be placed anywhere in the program. A STOP statement at the end of the program is optional. This statement is the same as the END statement.

EXAMPLE:

if i > max then stop


TAB Statement

PURPOSE:

To move the cursor in a text window to a certain column.

SYNTAX:

TAB column

EXPLANATION:

This statement moves the cursor to a specified column in the text window. The next PRINT statement will begin at that column.

If the new column is less than the current column, the cursor will move to the next line. The average character width of the current font is used to calculate character columns, since in Windows different characters may have different widths.

EXAMPLE:

window 5, 30               'open a window 5 x 30 chars.

print "left side";            ' ";" leaves on same line

tab 20                          ' move to column 20

print "right side"            ' print at column 20



WCLOSE Statement

PURPOSE:

To close the text window or dialog box.

SYNTAX:

WCLOSE

EXPLANATION:

This statement closes the text window, or dialog box. The drawing behind the text window will be replaced.

A text window that is opened by the WINDOW command remains on the screen until it is closed or until the program terminates.

EXAMPLE:

window 5, 20               ' open a window 5 x 20 chars.

locate 3, 10

print "This is a test"

anykey

wclose                          ' close the text window



WINDOW Statement

PURPOSE:

To open a text window or dialog box for subsequent PRINT statements.

SYNTAX:

WINDOW nrows, ncols

EXPLANATION:

This statement opens a text window or dialog box on the screen. Nrows and ncols are the number of rows and columns for the text window – they determine the window size.

As long as the text window is open, all PRINT statements are displayed in the window. The text window remains open until a WCLOSE statement is executed or until the program terminates.

The CLS, LOCATE, and TAB statements can be used to clear the screen and position the cursor in the text window. The COLOR statement can be used to set the text color inside the window.

Only one text window can be opened at a time.

EXAMPLE:

window 5, 20               ' open a window 5 x 20 chars.

locate 3, 10

print "This is a test



BasicCAD Built-In Functions

BasicCAD functions can be used in numeric expressions. The functions all have a single numeric argument, which can be any numeric expression. For example, ABS(J * 2) would be equal to the absolute value of J * 2.

The following functions are supported:

Numerical Functions

ABS(x)            Absolute Value.

ACOS(x)            Arc Cosine

ANGLE(dx, dy)       Get the angle between two points a distance of dx apart horizontally and dy vertically.

ASIN(x)            Arc Sine

ATAN(x)            Arc Tangent

COS(x)            Cosine

EXP(x)            Exponential - e^X

INT(x)            Truncate to integer closest to zero.

LN(x)   Natural Logarithm

LOG(x)            Logarithm (base 10)

ODD(x)            Returns one if x is odd, zero if x is even.

ROUND(x)            Round to Closest Integer.

SGN(x)            Sign of x (-1 if negative, 1 if positive).

SIN(x) Sine of x.

SQR(x)            Square.

SQRT(x)            Square Root

TAN(x)            Tangent.

TRUNC(x)            Truncate to integer closest to zero (same as INT).

System Functions

AREA(i)            (where 'i' is the entity number of the object) This function works on both vector and surface entities ( planes and grids).

EOF(x)            Returns one if file x is at end-of-file, zero otherwise. Note that x is the number used to OPEN the file.

ERR(x) Returns the error code of the error. This function returns zero until an ON ERROR has been activated. The error codes are listed in "BasicCAD Error Codes" in this Help file.

EXIST(a$)            Returns one if file a$ exists, zero if not, -1 if a$ is an invalid file name.

LAYER(x)             Layer status of layer x. Returns 0-15

            Assume y=LAYER(x)

            if ODD(y)=0,                  -> no entities in layer x.

            if ODD(y)=1,                  -> entities are in layer x.

            if ODD(y\2)=0,   -> layer x is invisible.

            if ODD(y\2)=1,   -> layer x is visible.

            if ODD(y\4)=0,   -> layer x is not editable.

            if ODD(y\4)=1,   -> layer x is editable.

            if ODD(y\8)=1,   -> x is the current layer.

LENGTH(i)            (where 'i' is the entity number of the object) This works on both vectors and planes.

SCREENX(z)            Returns screen X coordinate of drawing X coordinate z.

SCREENY(z)            Returns screen Y coordinate of drawing Y coordinate z.

VOLUME(k)            (where 'k' is the solid number) This ('k') must be obtained by selecting the object and then using sys(95) to determine its solid ID.

Note:    See AREAVOL.BSC in the BASICCAD directory for a simple demonstration of these functions.

String Functions

ASC(a$)            ASCII code for the first character of a$.

CVS(a$)            Convert the four-character string a$ to a real number. This is the inverse of MKS$.

INSTR(a$, b$)            Returns the location of the first occurrence of string b$ in string a$. Zero is returned if there are no occurrences.

LEN(a$)            Length of string a$.

VAL(a$)            Numeric value of string a$ (accepts feet-inches or degrees-minutes-seconds). For example:

A$="2'4"" returns 2.3333.

            A$="60D40M15S" returns 60.6708.

            A$="45" returns 45.000

CHR$(x)            Returns the character with an ASCII code of x.

LEFT$(a$, x)            Returns the leftmost x characters of a$.

MID$(a$, x, y)            Returns y characters of a$ beginning at x.

MKS$(x)            Converts x to a four-character string.

RIGHT$(a$, x)            Returns the rightmost x characters of a$.

STRING$(x, a$)       Returns a string of x copies of a$.

Two other functions are supported:

SYS(x) System Variable Function.

This function returns the value of a DesignCAD System Variable. The variable returned is determined by the value of the argument. See the SYS function.

SYS$(x)            System String Variable Function.

This function returns the value of a DesignCAD System StringVariable. The variable returned is determined by the value of the argument. See the SYS$ function.


SYS Functions

The SYS functions represent many different DesignCAD system variables. SYS(1), for example, is the number of points set, and SYS(3) is the current layer. A list of the available SYS variables and their valid ranges follows:

1

Number of points set [0-200]

3

Current layer [0-255]

7

Current precision [-7<=x<=7]

9

Number of entities in the drawing [read-only]

10

Units of measurement for display [1=inches, 0.0254=m, 2.54=cm, 25.4=mm.]

11

Units per inch on output [0<=x<=10e6]

12

Default text size [0<=x<=10e6]

13

Default text angle [-36<=x<=360]

14

Display grid type [1=XY, 2=YZ, 3=XZ]

15

Display grid enable/disable [1, 0]

17

Snap grid on or off [1, 0]

19

Display grid size [0<=x<=10e6]

 

 

20

Snap grid size [0<=x<=10e6]

21

Attribute display enable/disable [1, 0]

22

Save parameters with drawing, enable/disable [1, 0]

23

Mathematical or geographical angles [1, 0]

25

Sound off/on/error only [0, 1, 2]

26

Manipulate current layer only off/on [0, 1]

30

Large cursor step size [0<=x<=10e6]

31

Small cursor step size [0<=x<=10e6]

32

Drawing unit size [0<=x<=10e6]

34

Returns 1 if entities are selected, 0 otherwise

35

Number of sides in the rubber-band polygon [3-100]

 

 

37

Cursor step consistent with Screen or Drawing [1, 2]

38

Mirror Text enable/disable [1, 0]

40

Crosshair enable/disable [1, 0]

80

Number of entities currently selected [read_only]

Not affected by PUTATTR

Functions 90-99 are values for an entity just selected with the Entity statement.
They are all read_only values.

90

Entity type

91

Entity line type

92

Obsolete -- See Sys$(92) for entity color information

93

Entity layer

94

Group Number

95

Solid Number

96

Entity selected? [1=yes, 2=no]

99

Number of points in entity (or number of grid lines for grid entity)

101

Dimension type [1, 2, 3, 4]

104

Arrowhead type [1, 2, 3, 4]

106

Dimension precision [-7<=x<=7]

110

Coordinate system [-1 = left-hand, 1 = right-hand]

120

Minimum X value in the drawing [read_only]

121

Minimum Y value in the drawing [read_only]

122

Maximum X value in the drawing [read_only]

123

Maximum Y value in the drawing [read_only]

124

Minimum Z value in the drawing [read_only]

125

Maximum Z value in the drawing [read_only]

134

Printer top margin [varies with media]

135

Printer bottom margin [varies with media]

136

Printer left margin [varies with media]

137

Printer right margin [varies with media]

152

Scale drawings on retrieval and copy option 1=fixed, 2=changeable

190

Handle 1 X value [-10e6<=x<=10e6]

191

Handle 1 Y value [-10e6<=x<=10e6]

192

Handle 2 X value [-10e6<=x<=10e6]

193

Handle 2 Y value [-10e6<=x<=10e6]

194

Handle 3 X value [-10e6 <=x<=10e6]

195

Handle 3 Y value [-10e6 <=x<=10e6]

202

Handle 1 Z value [-10e6 <=x<=10e6]

203

Handle 2 Z value [-10e6 <=x<=10e6]

204

Handle 3 Z value [-10e6 <=x<=10e6]

205

View Angle about X axis

206

View Angle about Y axis

207

View Angle about Z axis

208

View Distance

209

Projection Mode [0=perspective, 1=parallel]

300

Current drawing color, Red value [0-255]

301

Current drawing color, Green value [0-255]

302

Current drawing color, Blue value [0-255]

306

Rubber-band color, Red value [0-255]

307

Rubber-band color, Green value [0-255]

308

Rubber-band color, Blue value [0-255]

309

Display grid color, Red value [0-255]

310

Display grid color, Green value [0-255]

311

Display grid color, Blue value [0-255]

312

Point color, Red value [0-255]

313

Point color, Green value [0-255]

314

Point color, Blue value 0-255]

315

Selection color, Red value [0-255]

316

Selection color, Green value [0-255]

317

Selection color, Blue value [0-255]

321

Background color, Red value..[0-255]

322

Background color, Green value..[0-255]

323

Background color, Blue value..[0-255]

327

Entity point color (when in Point Selection Mode), Red value [0-255]

328

Entity point color, Green value [0-255]

329

Entity point color, Blue value [0-255]

331

Cursor color, Red value

332

Cursor color, Green value

333

Cursor color, Blue value

334

3D cursor X color, Red value

335

3D cursor X color, Green value

336

3D cursor X color, Blue value

337

3D cursor Y color, Red value

338

3D cursor Y color, Green value

339

3D cursor Y color, Blue value

340

3D cursor Z color, Red value

341

3D cursor Z color, Green value

342

3D cursor Z color, Blue value

343

Smooth Solids On/Off [1, 0]

413

Dimension layer [0-255]

433

Angular dimension precision [-7<=x<=7]

438

Dimension text size [0<=x<=10e6]

442