home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR8
/
123EXP.ZIP
/
IMPRTWK1.CLA
< prev
next >
Wrap
Text File
|
1994-01-07
|
31KB
|
724 lines
MEMBER('cs')
imp123to PROCEDURE
!******************************************************************************
! This sample program illustrates the method for importing from a 1-2-3
! format spreadsheet file.
! The key routines to reference are:
! check_ver - Verifies that the input file is a spreadsheet
! find_A10 - Scans through the spreadsheet looking for a
! particular data cell (in this case, cell A:10)
! get_next - Reads the next spreadsheet file "record"
! read_text - Reads a "label" cell
! read_number - Reads a numeric cell
! 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/12/92
!
! This procedure is used to import takeoffs from a 1-2-3 format spreadsheet
! file. The takeoffs must start at Row 10, Column A and the columns must
! be in the following order. The first blank row after A10 will be
! considered the end of the list of takeoffs.
!
! Column Field Type
! ------ ------------------ ------
! A Category Label
! B Contract Label
! C Component Label
! D Property Unit # Label
! E Takeoff # Number
! F TO Description Label
! G Quantity Number
! H UOM Label
! I Unit Price Number
! J Cost Source Code Number
! K Flags Label - in this order: " Y Y Y N N N N"
! 12345678901234
! L Reference number Label
! M Blueprint Label
! N Source Label
!
! Revision History
! ────────────────
! 12/08/92 - Added check to ensure that the indirect flags are coded
! correctly.
!══════════════════════════════════════════════════════════════════════════════
file_scr SCREEN WINDOW(13,58),PRE(scr),HLP('imp123to'),HUE(7,1,0)
ROW(2,3) PAINT(10,48),HUE(11,1)
ROW(13,1) PAINT(1,1),TRN
ROW(1,58) PAINT(1,1),TRN
ROW(2,58) PAINT(11,1),HUE(8,0),TRN
ROW(13,2) PAINT(1,57),HUE(8,0),TRN
ROW(5,3) PAINT(4,53),HUE(11,1)
ROW(6,9) PAINT(2,46),HUE(15,1)
ROW(2,51) PAINT(3,2),HUE(11,1)
ROW(1,1) STRING('╒═<0{40}>═{14}╕')
ROW(2,1) REPEAT(10);STRING('│<0{55}>│') .
ROW(12,1) STRING('╘═{55}╛')
ROW(2,3) STRING('┌─<0{21}>─{26}┐')
ROW(3,3) STRING('│<0{48}>│')
ROW(4,3) STRING('└─{48}┘')
ROW(5,3) STRING('┌─<0{7}>─{43}┐')
ROW(6,3) REPEAT(2);STRING('│<0{51}>│') .
ROW(8,3) STRING('└─{51}┘')
ROW(9,3) STRING('┌─<0{9}>─┐')
ROW(10,3) STRING('│<0{11}>│')
ROW(11,3) STRING('└─{11}┘')
ROW(1,3) STRING('Import Takeoffs from a 1-2-3 Spreadsheet')
ROW(2,5) STRING('Spreadsheet File Name')
ROW(5,5) STRING('Options')
ROW(6,7) STRING(']')
COL(8) STRING(' '),HUE(15,1)
COL(9) STRING('Delete ALL existing takeoffs before importing')
ROW(7,4) STRING(' '),HUE(15,1)
COL(7) STRING(']')
COL(9) STRING('Write over any existing duplicate takeoffs')
ROW(9,5) STRING('Continue?')
ROW(3,5) ENTRY(@S46),USE(wks_filename),HUE(15,1),SEL(15,4),LFT,UPR
ROW(6,5) STRING('[')
COL(6) ENTRY(@S1),USE(del_all_a),HUE(14,1),SEL(15,4),OVR,IMM,LFT,UPR
ROW(7,5) STRING('[')
COL(6) ENTRY(@S1),USE(writeover_a),HUE(14,1),SEL(15,4),OVR,IMM,LFT,UPR
ROW(10,12) MENU(@S3),USE(mem:continue),HUE(1,1),SEL(1,1),REQ,IMM
COL(5) STRING('No'),HUE(15,1),SEL(15,4)
COL(8) STRING('Yes'),HUE(15,1),SEL(15,4)
. .
stat_screen SCREEN WINDOW(13,43),AT(11,37),PRE(sta),HUE(9,7,0)
ROW(2,43) PAINT(11,1),HUE(8,0),TRN
ROW(13,2) PAINT(1,42),HUE(8,0),TRN
ROW(13,1) PAINT(1,1),TRN
ROW(1,43) PAINT(1,1),TRN
ROW(3,3) PAINT(7,38),HUE(1,7)
ROW(11,3) PAINT(1,27),HUE(8,7)
ROW(1,1) STRING('█▀{40}█'),ENH
ROW(2,1) REPEAT(5);STRING('█<0{40}>█'),ENH .
ROW(10,2) STRING('─{40}'),ENH
ROW(11,1) STRING('█<0{40}>█'),ENH
ROW(12,1) STRING('█▄{40}█'),ENH
ROW(3,3) STRING('┌─<0{8}>─{5}┐<0>┌─<0{17}>─┐')
ROW(4,3) REPEAT(2);STRING('│<0{14}>│<0>│<0{19}>│') .
ROW(6,3) STRING('└─{14}┘<0>│<0{19}>│')
ROW(7,3) STRING('┌─<0{4}>────┐<0{6}>╞═{19}╡')
ROW(8,3) STRING('│<0{9}>│<0{6}>│<0{19}>│')
ROW(9,3) STRING('└─{9}┘<0{6}>└─{19}┘')
ROW(7,1) REPEAT(4);STRING('█<0{40}>█') .
ROW(3,5) STRING('Position')
COL(22) STRING('Takeoffs imported')
ROW(4,24) STRING('Added:')
ROW(5,22) STRING('Updated:')
ROW(6,22) STRING('Skipped:')
ROW(7,5) STRING('Cell')
ROW(8,6) STRING(':')
COL(24) STRING('Total:')
ROW(11,3) STRING('Press [Shift+Esc] to abort.')
message ROW(2,3) STRING(38),HUE(0,7)
wks_pointer ROW(4,8) STRING(@N9),HUE(0,7)
file_size ROW(5,5) STRING(12),HUE(0,7)
col ROW(8,5) STRING(1),HUE(0,7)
row COL(7) STRING(5),HUE(0,7)
add_cnt ROW(4,31) STRING(@N9),HUE(0,7)
update_cnt ROW(5,31) STRING(@N9),HUE(0,7)
skipped_cnt ROW(6,31) STRING(@N9),HUE(0,7)
rec_cnt ROW(8,31) STRING(@N9),HUE(0,7)
.
INCLUDE('wks_file.inc')
flags STRING(15)
rec_cnt LONG
add_cnt LONG
update_cnt LONG
skipped_cnt LONG
final_cnt LONG
err_prefix STRING(60)
hold_takeoff GROUP;BYTE,DIM(SIZE(tko:record)).
del_all_bx GROUP
del_all BYTE
del_all_a STRING(1)
.
writeover_bx GROUP
writeover BYTE
writeover_a STRING(1)
.
!──────────────────────────────────────────────────────────────────────────────
CODE
DO lock_takeoff ! Lock the takeoff file, if possible
DO get_filename ! Get the name of the WKS file
STREAM(takeoff)
IF del_all ! Clear out the takeoffs if
EMPTY(takeoff) ! requested.
.
sta:message = 'Importing the takeoffs...'
cur_row = wks:row ! Set the current row
cur_col = 0 ! and column
LOOP UNTIL wks_pointer > file_size ! Go thru each row in the spreadsheet
CLEAR(tko:record) ! Initialize the takeoff record
sta:row = cur_row + 1 ! Display the row number
LOOP UNTIL wks_pointer > file_size ! Read each field on the row
org_pointer = wks_pointer ! Save the current file position
sta:col = CHR(cur_col + 65) ! Display the column letter
EXECUTE cur_col +1 ! Get the correct field depending
DO get_cat ! on the column we're on.
DO get_cont
DO get_comp
DO get_ppu
DO get_tko_no
! DO skip_column ! There's a blank column between the TO# and the desc - if there's anything there, skip over it.
DO get_desc
DO get_quantity
DO get_uom
DO get_price
DO get_src_code
DO get_flags
DO get_ref
DO get_blue
DO get_source
.
DO abort_check
IF org_pointer = wks_pointer ! Did we get any data?
IF cur_col > 13 ! No. Are we on the last field?
DO write_tko ! Yes. Write the takeoff record
DO down_1_row ! and move to the next row
BREAK
. .
cur_col += 1 ! Move to the next column
. .
FLUSH(takeoff)
sta:wks_pointer = file_size ! Make sure the displayed sizes match
sta:message = '' ! Clear the message
OPEN(msg_box); msg_text = 'Resetting the spreadsheet. Just a moment...'
DO cleanup
final_cnt = add_cnt + update_cnt
CASE final_cnt
OF 0
done_msg('No takeoffs were imported.')
OF 1
done_msg('One takeoff was imported.')
ELSE
done_msg(CLIP(RIGHT(FORMAT(final_cnt,@n9),9)) & ' takeoffs were imported.')
.
RETURN
!───Routines───────────────────────────────────────────────────────────────────
lock_takeoff ROUTINE
CLOSE(takeoff)
OPEN (takeoff) ! Open the file in exclusive use mode to lockout anyone
IF ERRORCODE() ! from using it while it's importing.
err_msg('Importing cannot be done while someone else is using the project.')
SHARE(takeoff)
IF ERRORCODE()
err_msg('Cannot re-open the takeoff file.')
.
RETURN
ELSE
cat:id = '' ! Initialize the lookup key fields
ppu:no = ''
cmp:id = ''
cmp:ppu_no = ''
dsc:id = ''
dsc:rec_type = mem:src_desc_cd
.
get_filename ROUTINE ! Accept the name of the spreadsheet to import
! and be sure it's a valid takeoff spreadsheet
del_all = false ! Set defaults
del_all_a = ''
writeover = true
writeover_a = '√'
mem:continue = 'No'
OPEN(file_scr) ! Display the window
IF prj:imp123to_fil = ''
wks_filename = CLIP(cfg:data_dir) & '\TAKEOFFS.WK1' ! Default filename
ELSE
wks_filename = prj:imp123to_fil
.
SETCURSOR ! Cursor off
DISPLAY ! Display fields
LOOP
ALERT ! Reset all keys
ALERT(esc_key) ! Enable the Esc key
ALERT(reject_key) ! and the Ctrl+Esc key
ALIAS(ctrl_esc,reject_key)
ALERT(accept_key)
ALERT(F3_key)
ACCEPT ! Accept the filename
CASE KEYCODE()
OF reject_key
DO cleanup
RETURN
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('.',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 ?del_all_a; checkbox(del_all_bx)
OF ?writeover_a; checkbox(writeover_bx)
OF ?mem:continue
IF mem:continue <> 'Yes'
DO cleanup
RETURN
.
DO check_ver
IF wks_pointer > 0 ! Good WKS file?
DO init_stats ! Display the stat screen
DO find_a10 ! Find the takeoff list
IF wks_pointer NOT > file_size ! Any takeoffs found?
BREAK ! Yes - continue
. .
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
rec_cnt = 0 ! Init the counters
add_cnt = 0
update_cnt = 0
skipped_cnt = 0
OPEN(stat_screen)
sta:file_size = RIGHT('of ' & LEFT(FORMAT(file_size,@N9),9),12)
sta:row = 1
sta:col = 'A'
sta:rec_cnt = rec_cnt
sta:add_cnt = add_cnt
sta:update_cnt = update_cnt
sta:skipped_cnt = skipped_cnt
prj:imp123to_fil = wks_filename ! Save the filename in
PUT(project) ! the project record
find_a10 ROUTINE ! Find the cell data for Column A, Row 10. Must be a 3
! character string, data will be a total of 10 bytes
! long.
sta:message = 'Looking for the first spreadsheet cell...'
GET(wks_file,wks_pointer,4) ! Read the first record header
LOOP UNTIL wks_pointer > file_size ! Find the start of the list of data records
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 ! sequence and re-accept the
IF (KEYCODE() = reject_key) OR | ! filename if it was pressed.
(KEYCODE() = ctrl_esc)
DO scan_abort
EXIT
. . .
IF wks_pointer > file_size ! Any data found?
DO format_err ! No.
EXIT
.
sta:message = 'Looking for the list of takeoffs...'
GET(wks_file,wks_pointer,9) ! Read the data record header
LOOP UNTIL wks_pointer > file_size
IF (wks:opcode = label_op) AND | ! Label opcode?
(wks:length > 9) AND | ! Is the data 10 bytes or larger? (the category should be 3 chars long)
(wks:col = 0) AND (wks:row = 9) ! Column A, Row 10?
BREAK ! Found it - start reading here (at wks_pointer position)
.
IF wks:row > 10 ! Are we past where the takeoffs
wks_pointer = file_size + 1 ! should start?
sta:row = wks:row + 1 ! Update the row
sta:col = CHR(wks:col + 65) ! and column on the display
BREAK ! and exit
.
DO get_next
LOOP UNTIL NOT KEYBOARD() ! Check for the abort key
ASK ! sequence
IF (KEYCODE() = reject_key) OR |
(KEYCODE() = ctrl_esc)
DO scan_abort; EXIT
. . .
IF wks_pointer > file_size ! Any takeoffs found?
DO format_err ! No.
.
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
format_err ROUTINE ! Display spreadsheet format error
sta:message = ''
CLOSE(wks_file)
disp_msg('Invalid spreadsheet format. Takeoffs must start at Column A, Row 10.')
CLOSE(stat_screen)
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
get_cat ROUTINE
DO read_text
tko:category = UPPER(SUB(wks:string,1, wks:length - 7))
IF tko:category = '' ! Stop at the first blank row
wks_pointer = file_size + 1
ELSE
IF cat:id <> tko:category
cat:id = tko:category
GET(category,cat:key)
IF ERRORCODE()
err_prefix = '"' & CLIP(tko:category) & '" is an invalid category'
DO lookup_err
. . .
get_cont ROUTINE
DO read_text
tko:contract = UPPER(SUB(wks:string,1, wks:length - 7))
IF tko:contract = ''
err_prefix = 'A blank contract id is not valid'
DO lookup_err
ELSE
IF con:id <> tko:contract
con:id = tko:contract
GET(contract,con:id_key)
IF ERRORCODE()
err_prefix = '"' & CLIP(tko:contract) & '" is an invalid contract'
DO lookup_err
. . .
get_comp ROUTINE
DO read_text
tko:component = UPPER(SUB(wks:string,1, wks:length - 7))
IF tko:component = '' ! Can only check the component after we have the PPU# below
err_prefix = 'A blank component id is not valid'
DO lookup_err
.
get_ppu ROUTINE
DO read_text
tko:ppu_no = UPPER(SUB(wks:string,1, wks:length - 7))
IF tko:ppu_no = ''
err_prefix = 'A blank property unit number is not valid'
DO lookup_err
ELSE
IF ppu:no <> tko:ppu_no
ppu:no = tko:ppu_no
GET(propunit,ppu:key)
IF ERRORCODE()
err_prefix = '"' & CLIP(tko:ppu_no) & '" is an invalid property unit'
DO lookup_err
. .
IF (cmp:id <> tko:component) OR |
(cmp:ppu_no <> tko:ppu_no)
cmp:id = tko:component
cmp:ppu_no = tko:ppu_no
GET(cmponent,cmp:key)
IF ERRORCODE()
err_prefix = '"' & CLIP(tko:component) & '-' & CLIP(tko:ppu_no) & '" is an invalid component'
DO lookup_err
. . .
get_tko_no ROUTINE
DO read_number
tko:takeoff_no = wks_number
get_desc ROUTINE
DO read_text
tko:desc = SUB(wks:string,1, wks:length - 7)
get_quantity ROUTINE
DO read_number
tko:quantity = wks_number
get_uom ROUTINE
DO read_text
tko:uom = UPPER(SUB(wks:string,1, wks:length - 7))
get_price ROUTINE
DO read_number
tko:unit_price = wks_number
get_src_code ROUTINE
DO read_number
tko:cost_src_cd = wks_number
IF tko:cost_src_cd = 0
err_prefix = 'A blank cost source code is not valid'
DO lookup_err
ELSE
IF dsc:code <> tko:cost_src_cd
dsc:id = ''
dsc:code = tko:cost_src_cd
GET(desc,dsc:key)
IF ERRORCODE() ! Display "wks_number" in case the number is larger than a SHORT
err_prefix = '"' & CLIP(wks_number) & '" is an invalid cost source code'
DO lookup_err
. . .
get_flags ROUTINE
DO read_text
flags = UPPER(SUB(wks:string,1, wks:length - 7))
! The flags are in the spreadsheet in this order: " Y Y Y N N N N"
! 12345678901234
tko:prj_ind_flg = SUB(flags, 2,1)
tko:cat_ind_flg = SUB(flags, 4,1)
tko:con_ind_flg = SUB(flags, 6,1)
tko:time_loc_flg = SUB(flags, 8,1)
tko:job_cond_flg = SUB(flags,10,1)
tko:variance_flg = SUB(flags,12,1)
tko:ins_fctr_flg = SUB(flags,14,1)
! Check that the flag were coded correctly
IF NOT ( ((tko:prj_ind_flg = 'Y') OR (tko:prj_ind_flg = 'N')) AND |
((tko:cat_ind_flg = 'Y') OR (tko:cat_ind_flg = 'N')) AND |
((tko:con_ind_flg = 'Y') OR (tko:con_ind_flg = 'N')) AND |
((tko:time_loc_flg = 'Y') OR (tko:time_loc_flg = 'N')) AND |
((tko:job_cond_flg = 'Y') OR (tko:job_cond_flg = 'N')) AND |
((tko:variance_flg = 'Y') OR (tko:variance_flg = 'N')) AND |
((tko:ins_fctr_flg = 'Y') OR (tko:ins_fctr_flg = 'N')) )
err_prefix = 'The indirect flags must be coded like: " Y Y Y N N N N"'
DO lookup_err
.
get_ref ROUTINE
DO read_text
tko:reference_no = SUB(wks:string,1, wks:length - 7)
get_blue ROUTINE
DO read_text
tko:blueprint_no = SUB(wks:string,1, wks:length - 7)
get_source ROUTINE
DO read_text
tko:takeoff_src = SUB(wks:string,1, wks:length - 7)
skip_column ROUTINE ! If there's any data in the current column,
! skip over it. Otherwise, leave the pointer
! where it is.
GET(wks_file,wks_pointer,9) ! Get the label header
IF wks:col = cur_col ! Is there data in the column that should be skipped?
wks_pointer += (4 + wks:length) ! Yes - move the pointer to the next record
sta:wks_pointer = wks_pointer
.
lookup_err ROUTINE ! Display error info and exit
FLUSH(takeoff)
disp_msg(CLIP(err_prefix) & ' (cell ' & sta:col & ':' & CLIP(sta:row) & ').')
OPEN(msg_box); msg_text = 'Terminating. Just a moment...'
DO cleanup
disp_msg('The importing was terminated. Please correct the error and try again.')
RETURN
write_tko ROUTINE
IF (tko:contract <> '') AND | ! Was a complete record built?
(tko:takeoff_no <> 0)
ADD(takeoff) ! Yes - save it!
IF ERRORCODE()
IF ERRORCODE() = dupkey_err ! Already exists?
IF writeover = false
skipped_cnt += 1; sta:skipped_cnt = skipped_cnt
ELSE
hold_takeoff = tko:record
GET(takeoff,tko:key) ! Get the existing takeoff
IF NOT ERRORCODE()
tko:record = hold_takeoff
PUT(takeoff) ! Overwrite it
.
IF ERRORCODE()
err_msg('Unable to update a takeoff (contract: ' & |
CLIP(tko:contract) & ', takeoff# ' & tko:takeoff_no & ').')
OPEN(msg_box); msg_text = 'Aborting. Just a moment...'
DO cleanup
RETURN
ELSE
update_cnt += 1; sta:update_cnt = update_cnt
. .
ELSE
err_msg('Unable to add a takeoff (contract: ' & |
CLIP(tko:contract) & ', takeoff# ' & tko:takeoff_no & ').')
OPEN(msg_box); msg_text = 'Aborting. Just a moment...'
DO cleanup
RETURN
.
ELSE
add_cnt += 1; sta:add_cnt = add_cnt
.
rec_cnt += 1; sta:rec_cnt = rec_cnt
.
down_1_row ROUTINE ! Skip any records between the current position
! and the column A of the next row.
cur_row += 1 ! Set the expected new row
cur_col = 0
LOOP UNTIL wks_pointer > file_size
GET(wks_file,wks_pointer,9) ! Get the header
IF wks:opcode = eof_op ! 1-2-3 EOF mark?
wks_pointer = file_size + 1 ! All done
BREAK
ELSE
IF (wks:row = cur_row) AND | ! Are we on column A of the
(wks:col = 0) ! next row?
BREAK ! Yes - don't move the pointer
ELSE
wks_pointer += (4 + wks:length) ! No - keep looking
sta:wks_pointer = wks_pointer
. . .
read_text ROUTINE ! This reads the label data from the current record
! and checks to be sure it's coming from the correct
! cell location. If the record is not valid, the
! file position pointer is not moved.
GET(wks_file,wks_pointer,9) ! Get the label header
sta:wks_pointer = wks_pointer
IF (wks:col = cur_col) AND | ! Are we in the correct column (field)
(wks:row = cur_row) ! and row?
IF wks:opcode = label_op ! Label record?
byte_cnt = 4 + wks:length ! Read the entire record, including the header
GET(wks_file,wks_pointer,byte_cnt) ! Get the opcode, size, column, row, AND data
wks_pointer += byte_cnt ! Advance the file pointer
ELSE
err_prefix = 'A numeric cell was found where a label cell was expected'
DO lookup_err
.
ELSE
wks:string = ''
IF wks:opcode = eof_op
wks_pointer = file_size + 1 ! All done
. .
read_number ROUTINE ! This reads 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 valid, the
! file position pointer is not moved.
GET(wks_file,wks_pointer,9) ! Get the label header
sta:wks_pointer = wks_pointer
IF (wks:col = cur_col) AND | ! Are we in the correct column (field)
(wks:row = cur_row) ! and row?
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
! OF label_op ! Label - change to a number!
! byte_cnt = 4 + wks:length ! Read the entire record, including the header
! GET(wks_file,wks_pointer,byte_cnt) ! Get the opcode, size, column, row, AND data
! wks_pointer += byte_cnt ! Advance the file pointer
! wks_number = SUB(wks:string,1, wks:length - 7)
ELSE
err_prefix = 'A label cell was found where a numeric cell was expected'
DO lookup_err
.
ELSE
wks_number = 0
.
abort_check ROUTINE
LOOP UNTIL NOT KEYBOARD() ! Look for keystroke
ASK ! Get keycode if there is one
IF (KEYCODE() = reject_key) OR |
(KEYCODE() = ctrl_esc)
BEEP
OPEN(msg_box); msg_text = 'Aborting. Just a moment...'
DO cleanup
disp_msg('The importing was aborted as requested.')
RETURN
. .
cleanup ROUTINE
CLOSE(takeoff) ! Close the files
CLOSE(wks_file)
SHARE(takeoff) ! Reshare the takeoff file
CLOSE(msg_box) ! Clear whatever message was displayed