CLOSE

CLOSE

Close a specific set of files

Syntax

      CLOSE [<idAlias> | ALL | ALTERNATE | DATABASES |
             FORMAT | INDEXES]

Arguments

<idAlias> specifies the work area where all files are to be closed.

ALL closes alternate, database, and index files in all work areas, releasing all active filters, relations, and format definitions.

ALTERNATE closes the currently open alternate file, performing the same action as SET ALTERNATE TO with no argument.

DATABASES closes all open databases, memo and associated index files in all work areas, and releases all active filters and relations. It does not, however, have any effect on the active format.

FORMAT releases the current format, performing the same action as SET FORMAT TO with no argument.

INDEXES closes all index files open in the current work area.

Description

CLOSE is a general purpose command that closes various types of Clipper files depending on the specified option. CLOSE with no option closes the current database and associated files, the same as USE with no arguments.

In Harbour, a number of other commands also close files including:

          .  QUIT
          .  CANCEL*
          .  RETURN from the highest level procedure
          .  CLEAR ALL*
          .  USE with no argument

Seealso

QUIT, RETURN, SET ALTERNATE, SET INDEX, USE

? | ??

?|??

Display one or more values to the console

Syntax

       ? | ?? [<exp list>]

Arguments

<exp list> is a list of values to display and can be any combination of data types, including memo.

If you specify no argument and use the ? command, a carriage return/linefeed is sent to the console. If you use the ?? command without arguments, nothing happens.

Description

? and ?? are console commands that display the results of one or more expressions, separated by a space, to the console. These commands are also command synonyms for the QOUT() and QQOUT() functions, respectively.

Although functionally similar, ? and ?? differ slightly. ? sends a carriage return/linefeed to the console before displaying the results of the expression list. ?? displays output at the current screen cursor or printhead position. This lets you use successive ?? commands to display output to the same line.

A ? or ?? command locates the cursor or printhead one position to the right of the last character displayed. If SET PRINTER is OFF, ROW() and COL() are updated to reflect the new cursor position. If SET PRINTER is ON, PROW() and PCOL() are updated with the new printhead position.

If output from a ? or ?? command reaches the edge of the screen as reported by MAXCOL(), it wraps to the next line. If the output reaches the bottom of the screen as reported by MAXROW(), the screen scrolls up one line.

You can echo output from the ? or ?? commands to the printer by specifying a SET PRINTER ON command before beginning output. You can echo output from both of these commands to a text file using SET ALTERNATE TO <xcFile> to create the file, and SET ALTERNATE ON to begin echoing to the file. Like other console commands, SET CONSOLE OFF suppresses the display to the screen without affecting output to the printer or text file.

To format any expression specified, use TRANSFORM() or a user-defined function. If you need to pad a variable length value for column alignment, use any of the PAD() functions to left-justify, right- justify, or center the value. See the examples below.

Examples

       .  This example prints a record from a database file using ? and
          ?? commands with PADR() to ensure column alignment:
       LOCAL nPage := 0, nLine := 99
       USE Salesman INDEX Salesman NEW
       SET PRINTER ON
       SET CONSOLE OFF
       DO WHILE !EOF()
          IF nLine > 55
             IF nPage != 0
                EJECT
             ENDIF
             ? PADR("Page", LTRIM(STR(nPage++)), 72)
             ?? DTOC(DATE())
             ?
             ?
             ? PADC("Sales Listing", 79)
             ?
             nLine := 5
          ENDIF
          ? Name, Address, PADR(RTRIM(City) + "," ;
                + State, 20), ZipCode
          nLine++
          SKIP
       ENDDO
       SET CONSOLE ON
       SET PRINTER OFF
       CLOSE Salesman

Seealso

@…SAY, PAD(), QOUT(), SET ALTERNATE, SET CONSOLE, SET PRINTER

__TextSave()

Template

Procedure

Name

__TextSave()

Category

API

Subcategory

Internal

Oneliner

Redirect console output to printer or file and save old settings

Syntax

      __TextSave( <cFile> )

Arguments

<cFile> is either “PRINTER” (note the uppercase) in which console output is SET to PRINTER, or a name of a text file with a default “.txt” extension, that is used to redirect console output.

Description

__TextSave() is used in the preprocessing of the TEXT TO command to redirect the console output while saving old settings that can be restored later by __TextRestore().

Compliance

C52U

Platforms

All

Files

Library is core

Seealso

Set(), SET ALTERNATE, SET PRINTER, TEXT, __TextRestore()

__TextRestore()

Template

Procedure

Name

__TextRestore()

Category

API

Subcategory

Internal

Oneliner

Restore console output settings as saved by __TextSave()

Syntax

      __TextRestore()

Arguments

none.

Description

__TextRestore() is used in the preprocessing of the TEXT TO command to restore console output settings that were previously saved by __TextSave().

Compliance

C52U

Platforms

All

Files

Library is core

Seealso

Set(), SET ALTERNATE, SET PRINTER, TEXT, __TextSave()

Send to file

Write data to a file

Sending lines to a file is quite easy :

In addition of SET PRINTER on | OFF | <xlToggle> command, SET PRINTER, (like many other SET commands,) has a second form distinguished by TO keyword:

SET PRINTER TO [<xcDevice> | <xcFile> [ADDITIVE]]

The on|OFF form of SET PRINTER controls whether the output of console commands is echoed to the printer.

TO <xcDevice> identifies the name of the device where all subsequent printed output will be sent.

TO <xcFile> identifies the name of the output file. ( If a file extension is not specified, (.prn) is assumed.)

By using that last method we can send our lines to a file, instead of sending directly to printer:

 SET PRINTER TO Prnfile.txt
 SET DEVICE TO PRINTER
 SET PRINTER ON
 //
 @ 0, 0 SAY "This goes to Prnfile.txt"
 ? "So will this!"
 //
 SET DEVICE TO SCREEN
 SET PRINTER OFF
 SET PRINTER TO // Close the print file

Note that, though our target is not printer, we have use a SETting printer ON.

We have another method for sending someting to a file may be SET ALTERNATE command:

 SET ALTERNATE TO [<xcFile> [ADDITIVE]]
 SET ALTERNATE on | OFF | <xlToggle>

SET ALTERNATE is a console command that lets you write the output of console commands to a text file. Commands such as LIST, REPORT FORM, LABEL FORM, and ? that display to the screen without reference to row and column position are console commands. Most of these commands have a TO FILE clause that performs the same function as SET ALTERNATE. Full-screen commands such as @…SAY cannot be echoed to a disk file using SET ALTERNATE. Instead you can use SET PRINTER TO <xcFile> with SET DEVICE TO PRINTER to accomplish this.

SET ALTERNATE has two basic forms. The TO <xcFile> form creates a DOS text file with a default extension of (.txt) and overwrites any other file with the same name. Alternate files are not related to work areas with only one file open at a time. To close an alternate file, use CLOSE ALTERNATE, CLOSE ALL, or SET ALTERNATE TO with no argument.

The on|OFF form controls the writing of console output to the current alternate file. SET ALTERNATE ON begins the echoing of output to the alternate file. SET ALTERNATE OFF suppresses output to the alternate file but does not close it.

Examples :

This example creates an alternate file and writes the results of the ? command to the file for each record in the Customer database file:

 SET ALTERNATE TO Listfile
 SET ALTERNATE ON
 USE Customer NEW
 DO WHILE !EOF()
 ? Customer->Lastname, Customer->City
 SKIP
 ENDDO
 SET ALTERNATE OFF
 CLOSE ALTERNATE
 CLOSE Customer

A single difficulty may be making choose the best between possible methods

You can download a working example prg with a sample .dbf from here :

C5_SET ALTERNATE

 SET ALTERNATE
 Echo console output to a text file
------------------------------------------------------------------------------
 Syntax

     SET ALTERNATE TO [<xcFile> [ADDITIVE]]
     SET ALTERNATE on | OFF | <xlToggle>

 Arguments

     TO <xcFile> opens a standard ASCII text file for output with a
     default extension of .txt.  The file name may optionally include an
     extension, drive letter, and/or path.  You may specify <xcFile> either
     as a literal file name or as a character expression enclosed in
     parentheses.  Note that if a file with the same name exists, it is
     overwritten.

     ADDITIVE causes the specified alternate file to be appended instead
     of being overwritten.  If not specified, the specified alternate file is
     truncated before new information is written to it.

     ON causes console output to be written to the open text file.

     OFF discontinues writing console output to the text file without
     closing the file.

     <xlToggle> is a logical expression that must be enclosed in
     parentheses.  A value of true (.T.) is the same as ON, and a value of
     false (.F.) is the same as OFF.

 Description

     SET ALTERNATE is a console command that lets you write the output of
     console commands to a text file.  Commands such as LIST, REPORT FORM,
     LABEL FORM, and ? that display to the screen without reference to row
     and column position are console commands.  Most of these commands have a
     TO FILE clause that performs the same function as SET ALTERNATE.  Full-
     screen commands such as @...SAY cannot be echoed to a disk file using
     SET ALTERNATE.  Instead you can use SET PRINTER TO <xcFile> with SET
     DEVICE TO PRINTER to accomplish this.

     SET ALTERNATE has two basic forms.  The TO <xcFile> form creates a DOS
     text file with a default extension of .txt and overwrites any other file
     with the same name.  Alternate files are not related to work areas with
     only one file open at a time.  To close an alternate file, use CLOSE
     ALTERNATE, CLOSE ALL, or SET ALTERNATE TO with no argument.

     The on|OFF form controls the writing of console output to the current
     alternate file.  SET ALTERNATE ON begins the echoing of output to the
     alternate file.  SET ALTERNATE OFF suppresses output to the alternate
     file but does not close it.

 Examples

     .  This example creates an alternate file and writes the results
        of the ? command to the file for each record in the Customer database
        file:

        SET ALTERNATE TO Listfile
        SET ALTERNATE ON
        USE Customer NEW
        DO WHILE !EOF()
           ? Customer->Lastname, Customer->City
           SKIP
        ENDDO
        SET ALTERNATE OFF
        CLOSE ALTERNATE
        CLOSE Customer

 Files   Library is CLIPPER.LIB.

See Also: CLOSE FCREATE() FOPEN() FWRITE() SET CONSOLE



C5 Commands

 ?|??            Display one or more values to the console
 @...BOX         Draw a box on the screen
 @...CLEAR       Clear a rectangular region of the screen
 @...GET         Create a new Get object and display it
 @...PROMPT      Paint a menu item and define a message
 @...SAY         Display data at a specified screen or printer row and column
 @...TO          Draw a single- or double-line box
 ACCEPT*         Place keyboard input into a memory variable
 APPEND BLANK    Add a new record to the current database file
 APPEND FROM     Import records from a database (.dbf) file or ASCII text file
 AVERAGE         Average numeric expressions in the current work area
 CALL*           Execute a C or Assembler procedure
 CANCEL*         Terminate program processing
 CLEAR ALL*      Close files and release public and private variables
 CLEAR GETS      Release Get objects from the current GetList array
 CLEAR MEMORY    Release all public and private variables
 CLEAR SCREEN    Clear the screen and return the cursor home
 CLEAR TYPEAHEAD Empty the keyboard buffer
 CLOSE           Close a specific set of files
 COMMIT          Perform a solid-disk write for all active work areas
 CONTINUE        Resume a pending LOCATE
 COPY FILE       Copy a file to a new file or to a device
 COPY STRUCTURE  Copy the current .dbf structure to a new database (.dbf) file
 COPY STRU EXTE  Copy field definitions to a .dbf file
 COPY TO         Export records to a database (.dbf) file or ASCII text file
 COUNT           Tally records to a variable
 CREATE          Create an empty structure extended (.dbf) file
 CREATE FROM     Create a new .dbf file from a structure extended file
 DELETE          Mark records for deletion
 DELETE FILE     Remove a file from disk
 DELETE TAG      Delete a tag
 DIR*            Display a listing of files from a specified path
 DISPLAY         Display records to the console
 EJECT           Advance the printhead to top of form
 ERASE           Remove a file from disk
 FIND*           Search an index for a specified key value
 GO              Move the pointer to the specified identity
 INDEX           Create an index file
 INPUT*          Enter the result of an expression into a variable
 JOIN            Create a new database file by merging from two work areas
 KEYBOARD        Stuff a string into the keyboard buffer
 LABEL FORM      Display labels to the console
 LIST            List records to the console
 LOCATE          Search sequentially for a record matching a condition
 MENU TO         Execute a lightbar menu for defined PROMPTs
 NOTE*           Place a single-line comment in a program file
 PACK            Remove deleted records from a database file
 QUIT            Terminate program processing
 READ            Activate full-screen editing mode using Get objects
 RECALL          Restore records marked for deletion
 REINDEX         Rebuild open indexes in the current work area
 RELEASE         Delete public and private memory variables
 RENAME          Change the name of a file
 REPLACE         Assign new values to field variables
 REPORT FORM     Display a report to the console
 RESTORE         Retrieve memory variables from a memory (.mem) file
 RESTORE SCREEN* Display a saved screen
 RUN             Execute a DOS command or program
 SAVE            Save variables to a memory (.mem) file
 SAVE SCREEN*    Save the current screen to a buffer or variable
 SEEK            Search an order for a specified key value
 SELECT          Change the current work area
 SET ALTERNATE   Echo console output to a text file
 SET BELL        Toggle sounding of the bell during full-screen operations
 SET CENTURY     Modify the date format to include or omit century digits
 SET COLOR*      Define screen colors
 SET CONFIRM     Toggle required exit key to terminate GETs
 SET CONSOLE     Toggle console display to the screen
 SET CURSOR      Toggle the screen cursor on or off
 SET DATE        Set the date format for input and display
 SET DECIMALS    Set the number of decimal places to be displayed
 SET DEFAULT     Set the CA-Clipper default drive and directory
 SET DELETED     Toggle filtering of deleted records
 SET DELIMITERS  Toggle or define GET delimiters
 SET DESCENDING  Change the descending flag of the controlling order
 SET DEVICE      Direct @...SAYs to the screen or printer
 SET EPOCH       Control the interpretation of dates with no century digits
 SET ESCAPE      Toggle Esc as a READ exit key
 SET EXACT*      Toggle exact matches for character strings
 SET EXCLUSIVE*  Establish shared or exclusive USE of database files
 SET FILTER      Hide records not meeting a condition
 SET FIXED       Toggle fixing of the number of decimal digits displayed
 SET FORMAT*     Activate a format when READ is executed
 SET FUNCTION    Assign a character string to a function key
 SET INDEX       Open one or more order bags in the current work area
 SET INTENSITY   Toggle enhanced display of GETs and PROMPTs
 SET KEY         Assign a procedure invocation to a key
 SET MARGIN      Set the page offset for all printed output
 SET MEMOBLOCK   Change the block size for memo files
 SET MESSAGE     Set the @...PROMPT message line row
 SET OPTIMIZE    Change the setting that optimizes using open orders
 SET ORDER       Select the controlling order
 SET PATH        Specify the CA-Clipper search path for opening files
 SET PRINTER     Toggle echo of output to printer or set the print destination
 SET PROCEDURE*  Compile procedures and functions into the current object file
 SET RELATION    Relate two work areas by a key value or record number
 SET SCOPE       Change the boundaries for scoping keys in controlling order
 SET SCOPEBOTTOM Change bottom boundary for scoping keys in controlling order
 SET SCOPETOP    Change top boundary for scoping keys in controlling order
 SET SCOREBOARD  Toggle the message display from READ or MEMOEDIT()
 SET SOFTSEEK    Toggle relative seeking
 SET TYPEAHEAD   Set the size of the keyboard buffer
 SET UNIQUE*     Toggle inclusion of non-unique keys into an index
 SET WRAP*       Toggle wrapping of the highlight in menus
 SKIP            Move the record pointer to a new position
 SORT            Copy to a database (.dbf) file in sorted order
 STORE*          Assign a value to one or more variables
 SUM             Sum numeric expressions and assign results to variables
 TEXT*           Display a literal block of text
 TOTAL           Summarize records by key value to a database (.dbf) file
 TYPE            Display the contents of a text file
 UNLOCK          Release file/record locks set by the current user
 UPDATE          Update current database file from another database file
 USE             Open an existing database (.dbf) and its associated files
 WAIT*           Suspend program processing until a key is pressed
 ZAP             Remove all records from the current database file