@ Function

The @ function generates the screen format control sequences for a terminal.

Format

@(col)

@(col,row)

@(-code)

Parameter(s)

col

An expression to be taken as the column (x-coordinate) of the position desired.

row

An expression to be taken as the row (y-coordinate) of the position desired.

-code

An expression to be taken as a numeric code signifying a specific effect, such as clearing the screen. Codes are listed below.

Description

All terminals have built-in command sequences which move the cursor to a particular position, clear the screen, place text in reverse video, etc. The @ function returns the proper command sequence for performing many terminal control functions. When this function is within a terminal output statement (PRINT, CRT, DISPLAY, or SEND), the terminal is sent the command string and acts accordingly.

When used in a terminal output statement, the @ syntax is treated as any block of text: it may be combined with other blocks of text (including other calls of the @ function) with the concatenation operator (:), and the carriage return and linefeed may be suppressed with a trailing colon.

There are two forms of the @ function.

Similarly, if the column expression col evaluates to a value greater than the number of columns on the screen, the cursor goes to the last column of the screen. Note, however, that if the column expression evaluates to something less than zero, the leading minus sign causes it to assume one of the special codes of the @ function listed below, and the row specification is ignored.

Code

Description

@(-1)

Clear screen and position cursor at home (upper left corner).

@(-2)

Position cursor at home (upper left corner). Same as @(0,0).

@(-3)

Clear from cursor position to end of the screen.

@(-4)

Clear from cursor position to end of current line.

@(-5)

Begin blinking field.

@(-6)

End blinking field.

@(-7)

Begin protected field. Data in this field cannot be overwritten.

@(-8)

End protected field.

@(-9)

Backspace one character.

@(-10)

Move cursor up one line.

@(-11)

Begin protected field.

@(-12)

End protected field.

@(-13)

Begin reverse video mode.

@(-14)

End reverse video mode.

@(-15)

Begin underline field.

@(-16)

End underline field.

@() function codes 301 - 399 below support calling Windows Printer API methods. Two types of Windows Printer @() function codes are provided:

  • @() function codes 301 - 339 perform setup tasks in preparation for a print job.

  • @() function codes 340 - 399 perform the actual printing.

WARNING—Although multiple printing @() function codes can be concatenated, do not concatenate a setup @() function code with another setup @() function code or a printing @() function code. Setup @() function codes should always be isolated in a single statement.

NOTE—See the Windows GDI topic in Microsoft MSDN Library for more information on the Windows Printer methods.

@(-301)

Load object's x-coordinate position.

@(-302)

Load object's y-coordinate position.

@(-303)

Load object's selected point number.

@(-304)

Load object's selected rectangle number.

@(-305)

Load object's brush on draw rectangle.

@(-311)

Load font's height of character.

@(-312)

Load font's escapement angle.

@(-313)

Load font's orientation angle.

@(-314)

Load font's weight of font.

@(-315)

Load font's italic flag.

@(-316)

Load font's underline flag.

@(-317)

Load font's strike out flag.

@(-318)

Load font's character set.

@(-319)

Load font's output precision.

@(-320)

Load font's pitch and family.

@(-321)

Load font's index of font name string.

@(-322)

Load image’s path to bitmap file string.

@(-324)

Load brush's style.

@(-325)

Load brush's color.

@(-326)

Load brush's hatch style.

@(-327)

Load pen's style.

@(-328)

Load pen's width.

@(-329)

Load pen's color.

@(-330)

Load point's x-coordinate.

@(-331)

Load point's y-coordinate.

@(-332)

Load rectangle's left x-coordinate.

@(-333)

Load rectangle's top y-coordinate.

@(-334)

Load rectangle's right x-coordinate.

@(-335)

Load rectangle's bottom y-coordinate.

@(-336)

Load image's raster opcode.

@(-337)

Load image's stretch opcode.

@(-340)

Create font.

@(-341)

Create brush.

@(-342)

Create hatch brush.

@(-343)

Create solid brush.

@(-344)

Create pen.

@(-345)

Defines the default font.

@(-346)

Selects the default font.

@(-347)

Select font.

@(-348)

Select brush.

@(-349)

Select pen.

@(-350)

Set x-coordinate position.

@(-351)

Set y-coordinate position.

@(-352)

Set text color.

@(-353)

Set background color.

@(-354)

Set background mode.

@(-355)

Set text align.

@(-356)

Set text extra spacing.

@(-357)

Sets the page orientation.

For portrait orientation: @(-357,1)

For landscape orientation: @(-357,2)

Since the orientation affects the entire printed page, this function must be included at the beginning of your print statement.

@(-358, x)

Sets the number of lines on a print page where x is the number of lines.

@(-361)

Draw rectangle with brush.

@(-362)

Fill rectangle with brush.

@(-363)

Draw line.

@(-364)

Draw ellipse.

@(-365)

Draw arc.

@(-366)

Draw polygon.

@(-367)

Draw bitmap - start.

@(-368)

Draw bitmap with path - start.

@(-369)

Draw bitmap - end.

The @ function generates the command string for the terminal being used at run time, according to the current terminal type defined by the TERM command. The most important thing to grasp about the @ function is that all it does is generate a string of control characters, which happen to trigger a unique response when they are sent to the screen.

In mvBASIC, there is a statement called INPUT @, which among other things allows input to be prompted for at a particular coordinate of the screen. The INPUT @ statement, however, does not provide for any of the screen control codes listed above, only for moving the cursor. If the format masking properties of the INPUT @ statement are not being taken advantage of, the same effect might be achieved by preceding a standard INPUT statement with a PRINT statement which uses the @ function directly.

The CALL and ENTER statements also recognize the @ sign in their syntax lines, to signify that the name of the program to be called or entered is kept in a variable. This use of the @ symbol, however, should not be confused with its use in the @ function.

Examples

To clear the screen for a program, the code would read:

PRINT @(-1)

To print the words QUIT? at the bottom of the screen, the code would read:

PRINT @(0,23) : "QUIT?"

In the next example, the @ function is used within a PRINT statement to clear the screen and prompt the user at position (30,10) on the screen. If the user supplies an invalid answer, an error message appears on the bottom of the screen in blinking mode, and the previous invalid answer is erased. The operator is then prompted again until a valid answer is provided.

PRINT @(-1) :

CLEAR.ANSWER = @(30,10) : @(-4)

PRINT @(10,10) : " ENTER A NUMBER: " : @(30,10):

LOOP

   INPUT NUMBER  :

   IF NUM(NUMBER) THEN

      VALID = 1

      GOSUB COMPUTE

   END ELSE

      VALID = 0

      PRINT @(0,23) : @(-5) : " NON-NUMERIC INPUT.":

      PRINT "ENTER A NUMBER" : @(-6) : @(-4):

      PRINT CLEAR.ANSWER :

   END

UNTIL VALID DO REPEAT

These techniques are used in the application:

The example below illustrates a program that prints text to a specified location (x,y coordinates) on the paper.

    PRINT_AT_LOC

001 *

002 ** Set output to printer

003 *

004      PRINTER ON

005 *

006 ** Set location (x,y coordinate)

007 *

008      PRINT @(-350,600): @(-351,900):

009 *

010 ** Print to specified location

011 *

012      PRINT "PRINT AT SPECIFIED LOCATION"

013 *

014 ** Reset output to printer

015 *

016      PRINTER OFF

017 *

018      STOP

The example below illustrates a program that prints an ellipse graphic.

    PRINT_ELLIPSE

001 *

002 ** Set output to printer

003 *

004      PRINTER ON

005 *

006 ** Load brush fields

007 *

008      x = @(-324,0) ;* style

009      x = @(-325,12237498) ;* color

010      x = @(-326,0) ;* hatch style

011 *

012 ** Create brush and assign as brush number 3

013 *

014      PRINT @(-341,3):

015 *

016 ** Select brush number 3 as current brush

017 *

018      PRINT @(-348,3):

019 *

020 ** Set rectangle 2 (left, top, right, bottom)

021 *

022      x = @(-304,2)

023      x = @(-332,900)

024      x = @(-333,800)

025      x = @(-334,2200)

026      x = @(-335,1100)

027 *

028 ** Draw ellipse with rectangle 2

029 *

030      PRINT @(-364,2):

031 *

032 ** Set location (x,y coordinate)

033 *

034      PRINT @(-350,1200): @(-351,900):

035 *

036 ** Print line at specified

037 ** location within ellipse

038 *

039      PRINT "PRINT ELLIPSE"

040 *

041 ** Reset output to printer

042 *

043      PRINTER OFF

044 *

045      STOP

The example below illustrates a program that prints text using a specific font.

    PRINT_CREATE_SELECT_FONT

001 *

002 ** Set output to printer

003 *

004      PRINTER ON

005 *

006 ** Load font fields

007 *

008      x = @(-310,265) ;* character height

009      x = @(-311,100) ;* character width

010      x = @(-312,0) ;* escapement angle

011      x = @(-313,0) ;* orientation angle

012      x = @(-314,700) ;* weight

013      x = @(-315,0) ;* italic flag

014      x = @(-316,1) ;* underline flag

015      x = @(-317,0) ;* strike out flag

016      x = @(-318,1) ;* character set

017      x = @(-319,0) ;* output precision

018      x = @(-320,0) ;* pitch and family

019      x = @(-321,2) ;* font name

020 *

021 ** Create font and assign as font number 1

022 *

023      PRINT @(-340,1):

024 *

025 ** Select font number 1 as current font

026 *

027      PRINT @(-347,1):

028 *

029 ** Set location (x,y coordinate)

030 *

031      PRINT @(-350,600): @(-351,900):

032 *

033 ** Print line using selected font

034 *

035      PRINT "PRINT LINE USING SELECTED FONT"

036 *

037 ** Reset output to printer

038 *

039      PRINTER OFF

040 *

041      STOP

See Also

Statement and Function Reference