home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR8
/
123EXP.ZIP
/
IMP_ROW.CLA
< prev
next >
Wrap
Text File
|
1994-01-07
|
23KB
|
540 lines
MEMBER('dcf')
imp_row PROCEDURE
!******************************************************************************
! This sample program illustrates a method for reading a PORTION of a 1-2-3
! format spreadsheet file. It accepts the spreadsheet row and column, the
! orientation of the numbers (either vertical or horizontal) and begins
! importing numbers from that point. It stops importing when the first blank
! cell is encountered in the direction of the import - to the right (hor-
! izontal) or down (vertical). The numbers read are then presented in a
! preview screen. The user can then decide to keep them or try importing
! from another area of the spreadsheet.
! DISCLAIMER: I have not spent any time cleaning up this code. There are
! lots of calls to other functions and procedures that I have not removed.
! There are also references to global variables and files that I have not
! provided.
!******************************************************************************
!══════════════════════════════════════════════════════════════════════════════
! RED - 03/25/93
! This procedure imports a row from a 1-2-3 spreadsheet file into the
! year amounts for the current cash flow line and saves the line.
!══════════════════════════════════════════════════════════════════════════════
parms_scr SCREEN WINDOW(9,61),PRE(scr),HLP('imp_row'),HUE ( , ,0),TRN
ROW(2,61) PAINT(7,1),HUE(8,0),TRN
ROW(1,1) PAINT(8,60),HUE(8,7)
ROW(2,2) PAINT(4,23),HUE(1,7)
ROW(5,25) PAINT(1,4),HUE(1,7)
ROW(3,25) PAINT(1,9),HUE(0,7)
ROW(4,30) PAINT(4,28),HUE(0,7)
ROW(9,2) PAINT(1,60),HUE(8,0),TRN
ROW(1,1) STRING('╒═<0{42}>═{15}╕')
ROW(2,1) REPEAT(6);STRING('│<0{58}>│') .
ROW(8,1) STRING('╘═{58}╛')
ROW(4,30) STRING('┌─{26}┐')
ROW(5,30) REPEAT(2);STRING('│<0{26}>│') .
ROW(7,30) STRING('└─{26}┘')
ROW(1,3) STRING('Import numbers from a row in a spreadsheet')
ROW(5,28) STRING(']')
ROW(2,3) STRING('Spreadsheet Filename:')
COL(25) ENTRY(@S35),USE(wks_filename),HUE(0,7),SEL(15,4),REQ,LFT,UPR
ROW(3,10) STRING('Starting Cell:')
COL(25) ENTRY(@S2),USE(prj:ipr_column),HUE(0,7),SEL(15,4),REQ,LFT,UPR,IMM
COL(27) STRING(':')
COL(28) ENTRY(@N_5),USE(prj:ipr_row),HUE(0,7),SEL(15,4),INS,REQ
ROW(5,12) STRING('Orientation: [')
COL(26) MENU(@S2),USE(prj:ipr_orient),HUE(0,7),SEL(0,7),REQ,IMM
COL(31) STRING('═<16> Numbers are Horizontal'),HUE(0,7),SEL(15,4)
ROW(6,31) STRING('<25> Numbers are Vertical '),HUE(0,7),SEL(15,4)
. .
stat_screen SCREEN WINDOW(10,44),AT(14,36),PRE(sta),HUE(8,0,0),TRN
ROW(10,1) PAINT(1,1),TRN
ROW(1,1) PAINT(9,42),HUE(24,6)
ROW(3,2) PAINT(4,40),HUE(16,6)
ROW(3,3) PAINT(4,38),HUE(17,6)
ROW(4,5) PAINT(2,13),HUE(16,6)
ROW(4,23) PAINT(1,9),HUE(16,6)
ROW(1,43) PAINT(9,1),HUE(16,6)
ROW(1,44) PAINT(1,1),TRN
COL(1) STRING('┌─{41}')
ROW(2,1) REPEAT(5);STRING('│') .
ROW(7,1) STRING('├─{41}')
ROW(8,1) STRING('│')
ROW(9,1) STRING('└─{41}')
ROW(1,43) STRING('┐')
ROW(2,43) REPEAT(5);STRING('│') .
ROW(7,43) STRING('┤')
ROW(8,43) STRING('│')
ROW(9,43) STRING('┘')
ROW(3,3) STRING('┌─<0{8}>─{5}┐<0,0>┌─<0{4}>─{5}┐')
ROW(4,3) STRING('│<0{14}>│<0,0>│<0{10}>│')
ROW(5,3) STRING('│<0{14}>│<0,0>└─{10}┘')
ROW(6,3) STRING('└─{14}┘')
ROW(3,5) STRING('Position')
COL(23) STRING('Cell')
ROW(4,25) STRING(':')
ROW(8,3) STRING('Press [Shift+Esc] to abort.')
message ROW(2,3) STRING(39),HUE(17,6)
wks_pointer ROW(4,8) STRING(@N9)
file_size ROW(5,5) STRING(12)
col ROW(4,23) STRING(2)
row COL(26) STRING(5)
.
preview SCREEN WINDOW(24,59),AT(2,13),PRE(pre),HUE ( , ,0),TRN
ROW(24,2) PAINT(1,57),HUE(8,0),TRN
ROW(2,59) PAINT(23,1),HUE(8,0),TRN
ROW(1,1) PAINT(23,58),HUE(8,3)
ROW(2,3) PAINT(2,55),HUE(0,3)
ROW(4,22) PAINT(3,16),HUE(15,3)
ROW(5,27) PAINT(1,6),HUE(0,3)
ROW(8,7) PAINT(1,1),HUE(1,3)
ROW(1,1) STRING('╒═<0{14}>═{41}╕')
ROW(2,1) REPEAT(5);STRING('│<0{56}>│') .
ROW(7,1) STRING('╞════╤═{13}╦════╤═{13}╦════╤═{13}╡')
ROW(8,1) REPEAT(15);STRING('│<0{4}>│<0{13}>║<0{4}>│<0{13}>║<0{4}>│<0{13}>│') .
ROW(23,1) STRING('╘════╧═{13}╩════╧═{13}╩════╧═{13}╛')
ROW(4,22) STRING('┌─{14}┐')
ROW(5,22) STRING('│<0{14}>│')
ROW(6,22) STRING('└─{14}┘')
ROW(1,3) STRING('Import Preview')
ROW(2,3) STRING('These are the numbers that will be imported. Do you')
ROW(3,3) STRING('want to go ahead and move them into the current line?')
ROW(5,34) MENU(@S3),USE(mem:continue),HUE(3,3),SEL(3,3),REQ,IMM
COL(27) STRING('Yes'),SEL(15,4)
COL(31) STRING('No'),SEL(15,4)
.
REPEAT(15,3),EVERY(1,19),INDEX(preview_idx)
year ROW(8,2) STRING(@N04)
import_no COL(7) STRING(13)
. .
preview_data GROUP ! Table of imported numbers
preview_no REAL,DIM(40)
.
INCLUDE('wks_file.inc')
preview_idx BYTE
row_no SHORT ! Spreadsheet row# (relative to 0)
col_no SHORT ! Numeric spreadsheet column
row_offset BYTE ! Row increment amount for proper orientation
col_offset BYTE ! Column " " " " "
at_eof BYTE
!──────────────────────────────────────────────────────────────────────────────
CODE
action = mem:chg_record
IF lin:method <> mth:discrete_sch
disp_msg('The current cash flow line is not a discrete schedule.')
RETURN
.
DO init_parms ! Set the defualts
DO get_numbers ! Accept the parameters and load
! the numbers
DO cleanup
RETURN
!───Routines───────────────────────────────────────────────────────────────────
init_parms ROUTINE ! Set the defaults if they're empty
IF prj:ipr_filename = ''
prj:ipr_filename = CLIP(cfg:data_dir) & '\DCF.WK1'
.
IF prj:ipr_column = ''
prj:ipr_column = 'A'
.
IF prj:ipr_row = ''
prj:ipr_row = 1
.
IF prj:ipr_orient = ''
prj:ipr_orient = '═'
.
get_numbers ROUTINE ! Accept the parameters and load the numbers
OPEN(parms_scr) ! Display the window
wks_filename = prj:ipr_filename
SETCURSOR ! Cursor off
DISPLAY ! Display fields
LOOP
ALERT ! Reset all keys
ALERT(esc_key) ! Enable the Esc key
ALERT(reject_key) ! and the Shift+Esc key
ALIAS(ctrl_esc,reject_key)
ALERT(accept_key)
ALERT(F3_key)
ACCEPT ! Accept the parms
CASE KEYCODE()
OF reject_key
DO cleanup
RETURN
OF accept_key
UPDATE
SELECT(?)
SELECT ! Accept and edit all fields
CYCLE
OF esc_key
IF FIELD() = ?wks_filename
DO cleanup
RETURN
ELSE
SELECT(?-1); CYCLE
.
OF F3_key
IF FIELD() <> ?wks_filename
BEEP
SELECT(?); CYCLE
. .
CASE FIELD()
OF ?wks_filename
IF KEYCODE() = esc_key
DO cleanup
RETURN
.
IF (wks_filename = '') OR |
(KEYCODE() = F3_key) OR |
(INSTRING('*',wks_filename,1,1)) OR |
(INSTRING('?',wks_filename,1,1))
UPDATE
IF wks_filename = ''
wks_filename = '*.WK1' ! Select spreadsheets
.
IF sel_file(wks_filename,,files_only)
DISPLAY(?wks_filename) ! Redisplay selected file
ELSE
SELECT(?); CYCLE
. .
IF NOT namevalid(wks_filename)
disp_msg('Invalid filename syntax. Please re-enter.')
SELECT(?); CYCLE
.
! Add a default ".WK1" extension if there isn't one
IF NOT INSTRING('.WK',wks_filename,1)
wks_filename = CLIP(wks_filename) & '.WK1'
DISPLAY(?)
ELSE
IF SUB(wks_filename,-1,1) = '.' ! Period at last position?
wks_filename = CLIP(wks_filename) & 'WK1'
DISPLAY(?)
. .
IF NOT filexists(wks_filename)
disp_msg('Filename not found. Please re-enter.')
SELECT(?); CYCLE
.
OF ?prj:ipr_column
IF NOT INRANGE(prj:ipr_column,'A ','IV')
disp_msg('Please enter a column indicator between "A" and "IV".')
SELECT(?); CYCLE
.
OF ?prj:ipr_row
IF NOT INRANGE(prj:ipr_row,1,max_123_rows)
disp_msg('Please enter a row number between 1 and ' & max_123_rows & '.')
SELECT(?); CYCLE
.
OF ?prj:ipr_orient
DO check_ver
IF wks_pointer > 0 ! Good WKS file?
DO init_stats ! Display the stat screen
DO find_cell ! Find the specified cell
IF wks_pointer NOT > file_size ! Any numbers found?
DO load_table ! Load numbers in the table
DO show_preview ! Show the numbers that will load
IF mem:continue = 'Yes' ! Go ahead and keep them?
DO update_line ! Update the line
BREAK ! and quit
. . .
CLOSE(wks_file)
SELECT(?wks_filename); CYCLE
. .
check_ver ROUTINE ! Check for a valid spreadsheet file. wks_pointer
! is > 0 if it's valid.
OPEN(wks_file)
IF ERRORCODE()
err_msg('Unable to access the spreadsheet file.')
wks_pointer = 0
ELSE
file_size = BYTES(wks_file) ! Save the size of the file
GET(wks_file,1,6) ! Read the BOF record
IF (wks:opcode = bof_op) AND | ! BOF record?
((wks:version = ver_123_1) OR | ! Version 1.x or
(wks:version = ver_123_2)) ! 2.x spreadsheet?
wks_pointer = 7 ! Yes - continue on
ELSE
wks_pointer = 0 ! No - try again
CLOSE(wks_file)
disp_msg('Not a valid 1-2-3 spreadsheet file. Please re-enter.')
. .
init_stats ROUTINE
OPEN(stat_screen)
sta:file_size = RIGHT('of ' & LEFT(FORMAT(file_size,@N9),9),12)
sta:row = 1
sta:col = 'A'
sta:wks_pointer = ''
prj:ipr_filename = wks_filename ! Save the parameters in
PUT(project) ! the project record
IF prj:ipr_orient = '═' ! Set the offsets to establish the proper orientation
col_offset = 1 ! Horizontal orientation - move the right
row_offset = 0
ELSE
col_offset = 0 ! Vertical orientation - move down
row_offset = 1
.
find_cell ROUTINE ! Find the specified starting cell
row_no = prj:ipr_row - 1 ! Row# is relative to 0
IF LEN(CLIP(prj:ipr_column)) < 2 ! Compute the column NUMBER from the letters (1-2-3 columns #'s are relative to 0!)
col_no = VAL(SUB(prj:ipr_column,1,1)) - 65 ! Only one letter
ELSE
col_no = ( ( (VAL(SUB(prj:ipr_column,1,1)) - 65) + 1) * 26 ) | ! Two letter
+ (VAL(SUB(prj:ipr_column,2,1)) - 65)
.
sta:message = 'Looking for the starting cell...'
at_eof = false
GET(wks_file,wks_pointer,4) ! Read the first record header
LOOP UNTIL wks_pointer > file_size ! Find the 1st data record
IF INRANGE(wks:opcode,integer_op,formula_op) ! Data opcode?
BREAK ! wks_pointer points to the start of the 1st data record
.
DO get_next
LOOP UNTIL NOT KEYBOARD() ! Check for the abort key
ASK
IF KEYCODE() = reject_key
DO scan_abort
EXIT
. . .
IF wks_pointer > file_size ! Any data found?
DO no_data_err ! No.
EXIT
.
GET(wks_file,wks_pointer,9) ! Read the 1st data record header
cur_col = col_no
cur_row = row_no
LOOP UNTIL wks_pointer > file_size
DO show_cell
IF INRANGE(wks:opcode,integer_op,formula_op) ! Data cell?
IF (wks:row > cur_row) OR | ! Past the specified cell?
((wks:row = cur_row) AND (wks:col > cur_col))
DO no_num_err
EXIT
.
IF (wks:opcode = integer_op) OR | ! Is it a number?
(wks:opcode = floating_op) OR |
(wks:opcode = formula_op)
IF wks:row = cur_row AND | ! Are we on the specified cell?
wks:col = cur_col
BREAK ! Yes - start reading here (at wks_pointer position)
. . .
DO get_next
LOOP UNTIL NOT KEYBOARD() ! Check for the abort key
ASK ! sequence
IF KEYCODE() = reject_key
DO scan_abort
EXIT
. . .
IF wks_pointer > file_size ! Anything found?
DO no_data_err ! No.
.
load_table ROUTINE ! Load the numbers into the preview table
sta:message = 'Extracting the numbers from the file...'
CLEAR(preview_data)
preview_idx = 0
cur_col = wks:col
cur_row = wks:row
LOOP UNTIL at_eof
DO load_number ! Get the number from the cell
DO show_cell ! Display the cell location
preview_idx += 1
IF preview_idx > dcf:years ! All done?
BREAK
.
preview_no[preview_idx] = wks_number ! Move the number into the
! preview table
cur_col = cur_col + col_offset ! Set the next cell location
cur_row = cur_row + row_offset ! to read from
DO find_next
.
find_next ROUTINE ! Skip any records between the current position and the
! next cell where we should find a number (indicated
! by the coordinates in cur_row and cur_col)
LOOP UNTIL at_eof OR (wks_pointer > file_size)
GET(wks_file,wks_pointer,9) ! Read the next header
sta:wks_pointer = wks_pointer ! Display the counter
IF wks:opcode = eof_op ! 1-2-3 EOF mark?
wks_pointer = file_size + 1 ! All done
at_eof = true
ELSE
IF INRANGE(wks:opcode,integer_op,formula_op) ! Data cell?
IF (wks:row = cur_row) AND | ! Did we find the cell?
(wks:col = cur_col)
IF wks:opcode = label_op ! First empty or label cell
at_eof = true ! marks the end
.
BREAK ! Yes - we're done looking
.
IF (wks:row > cur_row) OR | ! Are we past where the cell
((wks:row = cur_row) AND | ! should be?
(wks:col > cur_col))
at_eof = true ! All done!
. . .
DO show_cell ! Display the column and row
wks_pointer += wks:length + 4 ! Move over the current record
DO abort_check ! Watch for Shift+Esc
.
show_preview ROUTINE ! Let the use preview the numbers we found
CLOSE(stat_screen)
OPEN (preview)
mem:continue = 'Yes'
LOOP preview_idx = 1 TO dcf:years ! Show the numbers
pre:year = YEAR(dcf:date) + preview_idx - 1
EXECUTE (lnt:places +1)
pre:import_no = FORMAT(preview_no[preview_idx],fmt:line0)
pre:import_no = FORMAT(preview_no[preview_idx],fmt:line1)
pre:import_no = FORMAT(preview_no[preview_idx],fmt:line2)
pre:import_no = FORMAT(preview_no[preview_idx],fmt:line3)
pre:import_no = FORMAT(preview_no[preview_idx],fmt:line4)
pre:import_no = FORMAT(preview_no[preview_idx],fmt:line5)
pre:import_no = FORMAT(preview_no[preview_idx],fmt:line6)
. .
SELECT(?mem:continue)
ALERT ! Reset all keys
ALERT(esc_key) ! Enable the ESC keys
ALERT(accept_key)
ALERT(reject_key)
ALIAS(ctrl_esc,reject_key)
ACCEPT ! Get the response
IF (KEYCODE() = esc_key) OR (KEYCODE() = reject_key)
mem:continue = 'No'
.
CLOSE(preview)
update_line ROUTINE ! Move the numbers into the line and save it
LOOP preview_idx = 1 TO dcf:years ! Move the numbers
lin:amount[preview_idx] = preview_no[preview_idx]
.
PUT(lineitem) ! Update the line item
IF ERRORCODE()
err_msg('Unable to save the imported number in this line.')
ELSE
action = mem:no_action ! Set action to complete
.
get_next ROUTINE ! Get the next 123 record
wks_pointer += wks:length + 4 ! Move over the current record
GET(wks_file,wks_pointer,9) ! and read the next header
sta:wks_pointer = wks_pointer ! Display the counter
no_data_err ROUTINE
sta:message = ''
CLOSE(wks_file)
disp_msg('Invalid spreadsheet format. No numeric data cells were found.')
CLOSE(stat_screen)
wks_pointer = file_size + 1 ! Accept the filename again
no_num_err ROUTINE
DO show_cell
sta:message = ''
CLOSE(wks_file)
disp_msg('Cell ' & CLIP(prj:ipr_column) & ':' & prj:ipr_row & ' does not contain a number.')
CLOSE(stat_screen)
wks_pointer = file_size + 1 ! Accept the filename again
scan_abort ROUTINE ! Abort the initial scan
BEEP
OPEN(msg_box); msg_text = 'Aborting. Just a moment...'
DO cleanup
disp_msg('The scanning was aborted as requested.')
CLOSE(stat_screen)
wks_pointer = file_size + 1 ! Accept the filename again
load_number ROUTINE ! This moves the numeric data from the current record
! and checks to be sure it's coming from the correct
! cell location. If the record is not a number,
! stop loading.
sta:wks_pointer = wks_pointer
CASE wks:opcode
OF integer_op ! Integer?
GET(wks_file,wks_pointer,11) ! Get the integer record (size=7 + 4 byte header)
wks_pointer += 11 ! Advance the file pointer
wks_number = wks:integer
OF floating_op
GET(wks_file,wks_pointer,17) ! Get the real number record (size=13 + 4 byte header)
wks_pointer += 17 ! Advance the file pointer
wks_number = wks:real_no
OF formula_op ! Formula
GET(wks_file,wks_pointer,17) ! Get the real number result (size=13 + 4 byte header)
wks_pointer += 4 + wks:length ! Advance the file pointer over the formula text (up to 2048 bytes)
wks_number = wks:real_no
ELSE
CLEAR(wks_number,1) ! Set to highest # possible
at_eof = true ! All done!
.
show_cell ROUTINE ! Display the 1-2-3 spreadsheet the column # as
! letter(s) and the row number.
IF col_shown <> wks:col ! Is column display up to date?
col_shown = wks:col ! No - update it
col_letter[1] = wks:col / 26 ! First letter group# (0 if only 1 letter)
col_letter[2] = wks:col % 26 ! Code of second (or only) letter
IF col_letter[1] = 0 ! Only one letter?
sta:col = ' ' & CHR(col_letter[2] + 65) ! Show 1 letter
ELSE
sta:col = CHR(col_letter[1] + 64) & CHR(col_letter[2] + 65)
. .
sta:row = wks:row ! Dislay the row#
abort_check ROUTINE
LOOP UNTIL NOT KEYBOARD() ! Look for keystroke
ASK ! Get keycode if there is one
IF (KEYCODE() = reject_key) OR | ! On Shift+Esc
(KEYCODE() = ctrl_esc) ! or Ctrl+Esc
BEEP
OPEN(msg_box); msg_text = 'Aborting. Just a moment...'
DO cleanup
disp_msg('The extracting was aborted as requested.')
at_eof = true
. .
cleanup ROUTINE
CLOSE(wks_file)
CLOSE(msg_box) ! Clear whatever message was displayed
sta:message = ''