home *** CD-ROM | disk | FTP | other *** search
- /* ========================================================== */
- /* Final Data ARexx Macro. */
- /* SaveLayout - Save column positions and widths. */
- /* $VER: SaveLayout 1.0 (4.8.94) */
- /* © 1994 SoftWood, Inc. */
- /* Use of this macro is strictly at the user's risk. */
- /* */
- /* This macro is used in conjunction with the RestoreLayout */
- /* macro. Together they will allow you to save the current */
- /* column layout (positions and widths) and then at a later */
- /* time restore the column layout to what is was previously. */
- /* To save the current layout, your database must first be */
- /* saved. Start the macro from Final Data. The current layout */
- /* data will be stored in a file with the same name as your */
- /* database, but with ".FDLayout" appended to the end of the */
- /* filename. Later, the RestoreLayout macro will look at this */
- /* file to restore your column layout. */
- /* */
- /* For those who want to know, the data for each column is */
- /* saved on a single line with the following format: */
- /* columnid columnwidth\n */
- /* The column data is stored in the order that the columns */
- /* appear in the database. */
- /* ========================================================== */
- OPTIONS RESULTS
-
- /* --------------------------------------------------------- */
- /* Get the number of columns. If 0, then exit with an error. */
- /* --------------------------------------------------------- */
- NumColumns
- ncols = RESULT
- IF ( ncols = 0 ) THEN DO
- ShowMessage 1 1 '"No columns defined." "" "" "OK" "" ""'
- EXIT 10
- END
-
- /* -------------------------------------------------- */
- /* Determine the filename to save the database layout */
- /* information to. We'll use the existing path and */
- /* filename appended with ".FDLayout". This assumes */
- /* that the database has already been saved. So exit */
- /* with an error if it has not been saved. */
- /* -------------------------------------------------- */
- Filename
- IF ( RESULT = "" ) THEN DO
- ShowMessage 1 1 '"This is an untitled database." "Please save the database" "before using this macro." "OK" "" ""'
- EXIT 10
- END
-
- Filename COMPLETE
- layoutFile = RESULT || ".FDLayout"
- quotedFile = '"' || layoutFile || '"'
-
- /* -------------------------------------- */
- /* Does the layout file already exist? */
- /* If it does, ask if we should continue. */
- /* -------------------------------------- */
- IF ( EXISTS(filename) ) THEN DO
- firstLine = '"The layout file already exists."'
- secondLine = '"Do you want to replace it?"'
- ShowMessage 2 1 firstLine secondLine quotedFile '"Yes" "No" ""'
- IF ( Result = 2 ) THEN EXIT 5
- END
-
- /* -------------- */
- /* Open the file. */
- /* -------------- */
- IF ( OPEN('layout', layoutFile, 'Write') ) THEN DO
- /* --------------- */
- /* File is opened. */
- /* --------------- */
-
- /* ----------------------------- */
- /* For each column write out the */
- /* columnID and columnWidth. */
- /* ----------------------------- */
- DO c = 1 TO ncols
- GetColumnID POSITION c
- cid = RESULT
- GetColumnDef cid WIDTH
- cwidth = RESULT
- CALL LineOut('layout', cid cwidth)
- END
-
- /* -------------- */
- /* Close the file */
- /* -------------- */
- CALL CLOSE('layout');
-
- END /* End if */
-
- ELSE DO
- /* ------------------------- */
- /* File could not be opened. */
- /* ------------------------- */
- firstLine = '"Cannot open file."'
- ShowMessage 1 1 firstLine quotedFile '"" "OK" "" ""'
- EXIT 10
- END
-
- EXIT
-
-
- /* ============================================ */
- /* LineOut */
- /* Procedure to write a line out to the file */
- /* checking for errors and exiting if any found */
- /* ============================================ */
- LineOut: PROCEDURE
- PARSE ARG filehandle, str
-
- len = WRITELN( filehandle, str )
- IF (len ~= LENGTH(str) + 1) THEN DO
- ShowMessage 1 1 '"Error writing file!" "" "" "OK" "" ""'
- CALL CLOSE(filehandle);
- EXIT 10
- END
-
- RETURN
-