home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR7
/
FOXTAILS.ZIP
/
DBFIXED.PRG
< prev
next >
Wrap
Text File
|
1992-02-29
|
4KB
|
147 lines
* Written by R.L. Coppedge
* Copyright 1992 dbF Software Productions
* By the way, dbF also has:
* SysTrak A Computer Hardware/Software Inventory System
* Flags A Flatfile Application Gen. for db3,4 and Fox
* ClasAdz A Classified/Notice system for Networks
* FerretPro A collection of FoxPro tools (like this one)
* Contact dbF for more information.
* dbF Software Productions
* P.O. Box 37194
* Cleve., Ohio 44137-0194
* CIS: 72117,165
* (216)491-4581
*
*
SET TALK OFF
SET SAFETY OFF
DEFINE WINDOW Dbfixed FROM 1,0 TO 22,79 TITLE "DbFixed"
ACTIVATE WINDOW DbFixed
@3,15 SAY "Copyright 1992, dbF Software Productions"
@4,2 TO 13,70 DOUBLE
@5,4 SAY "This program will help you import data files into a dbF"
@6,4 SAY "format. Files that have some kind of fixed record length"
@7,4 SAY "but with a header (ie, a Cobol data file) length. You"
@8,4 SAY "try finding (or already know) combinations of record and"
@9,4 SAY "header lengths until you find one that fits..."
@10,4 SAY "Sounds like something you wanna do?"
@11,5 GET choice PICTURE '@*H \!\<Ok;\?\<Cancel' DEFAULT "Ok"
READ
IF Choice = "Cancel"
RELEASE WINDOW DbFixed
WAIT "Be that way!" WINDOW
RETURN
ENDIF
DEFINE WINDOW Keepr FROM 16,5 TO 22,65 DOUBLE TITLE "Now what?"
Fl = GETFILE()
IF EMPTY(Fl)
RELEASE WINDOW DbFixed, Keepr
RETURN
ENDIF
Opn = FOPEN(Fl,0)
=ADIR(Fstuff,Fl)
Fsz = Fstuff(2)
Hdsz = 20
Rsz = 80
DO WHILE .T.
CLEAR
@0,3 SAY "Tap <Esc> to Exit"
@1,5 SAY "File size is " + ALLTRIM(STR(Fsz))+ " Bytes Long"
@2,5 SAY "What header size do you want? " GET Hdsz PICTURE "99999" ;
VALID BETWEEN(Hdsz,1,Fsz) ERROR "Umm...keep the file's size in mind, ok?"
@3,5 SAY "What record Size? " GET Rsz PICTURE "99999" ;
VALID BETWEEN(Rsz,1,Fsz) ERROR "Umm...keep the file's size in mind, ok?"
@18,5 SAY "Copyright 1992, dbF Software Productions..."
READ
IF LASTKEY() = 27
EXIT
ENDIF
Nmrecs = INT((Fsz-Hdsz)/ Rsz)
IF Nmrecs > 0
@6,5 SAY "There would be " + ALLTRIM(STR(Nmrecs)) + " Records created by"
@7,5 SAY "importing this file..."
ELSE
@6,5 SAY "Hey, waitaminnit! The file is only " + ALLTRIM(STR(Fstuff(2))) + " bytes long"
@7,5 SAY "That's not big enough for this..."
WAIT WINDOW
LOOP
ENDIF
Rmdr = Fsz - (Nmrecs*Rsz) - Hdsz
IF Rmdr <> 0
@8,5 SAY "There would be " + ALLTRIM(STR(Rmdr)) + " bytes left over..."
@9,5 SAY "That's usually an indicator that you're a bit (or byte) off"
ENDIF
@10,5 SAY "Do you want to see what 2 records would look like?"
@11,2 GET choice PICTURE '@* \!\<Ok;\?\<Cancel' DEFAULT "Ok"
READ
IF Choice = "Ok"
N = FSEEK(Opn, Hdsz, 0)
R1 = FREAD(Opn, Rsz)
R2 = FREAD(Opn, Rsz)
Nlines = INT(Rsz/77) + 1
@3,2 SAY "Ok, with that positioning, the 1st two records look like this:"
D = "1>>"
@4,0 GET D
CLEAR GETS
FOR X = 1 TO Nlines
Slen = IIF(Rsz-77*(X-1)>77,77,Rsz-77*(X-1))
@3 + X, 3 SAY SUBSTR(R1,77*(X-1)+1,Slen)
ENDFOR
D = "2>>"
@5+Nlines,0 GET D
CLEAR GETS
Offset = Nlines
FOR X = 1 TO Nlines
Slen = IIF(Rsz-77*(X-1)>77,77,Rsz-77*(X-1))
@4 + X+Offset, 3 SAY SUBSTR(R2,77*(X-1)+1,Slen)
ENDFOR
ENDIF
ACTIVATE WINDOW Keepr
@0,1 SAY "Now, do you want to export the entire"
@1,1 SAY "file to a database?"
@2,2 GET choice PICTURE '@* \!\<Ok;\?\<Cancel' DEFAULT "Ok"
READ
IF Choice = "Ok"
Newfile = PUTFILE("Enter a File Name" , "Export", "Dbf")
IF EMPTY(Newfile)
WAIT "Import aborted...tap any key" WINDOW
DEACTIVATE WINDOW Keepr
LOOP
ENDIF
USE Dummy
ZAP
NFlds = INT(Rsz/254) + 1
FOR X = 1 TO NFlds
APPEND BLANK
Fn = "Field" + ALLTRIM(STR(X))
REPLACE Field_Name WITH Fn, Field_Type WITH "C", Field_Len WITH IIF(X=Nflds,Rsz-254*(X-1) ,254)
ENDFOR
CREATE (Newfile) FROM Dummy
USE (Newfile) ALIAS Newfile
N = FSEEK(Opn, Hdsz, 0)
DO WHILE !FEOF(Opn)
R1 = FREAD(Opn, Rsz)
APPEND BLANK
FOR X = 1 TO NFlds
Fn = "Field" + ALLTRIM(STR(X))
Slen = IIF(Rsz-254*(X-1)>254,254,Rsz-254*(X-1))
REPLACE (Fn) WITH SUBSTR(R1,254*(X-1)+1,Slen)
ENDFOR
ENDDO
CLEAR
@0,1 SAY "Boy that was fun! Your new database now has"
@1,1 SAY ALLTRIM(STR(RECCOUNT())) + " Records"
@2,1 SAY "Do it again?"
@3,2 GET choice PICTURE '@* \!\<Ok;\?\<Cancel' DEFAULT "Ok"
READ
IF Choice = "Cancel"
EXIT
ENDIF
ENDIF
DEACTIVATE WINDOW Keepr
ENDDO
=FCLOSE(Opn)
CLOSE DATA
RELEASE WINDOW DbFixed, Keepr
RETURN