BBS: Inland Empire Archive Date: 05-18-92 (21:21) Number: 112 From: MATT HART Refer#: NONE To: BLAINE CARMICHAEL Recvd: NO Subj: Help! Conf: (2) Quik_Bas
BC> I have it set up now, I have to edit the Data Type and recompile. I BC> would like to be able to have some sort of data file that would hold the BC> new Data Type and Old Data Type and make the changes to the file. This There are several ways to do this. It depends on how you know you need a new data type. Is this a change made through the course of the project (A "Woops! I need another field!") or a user selected change (Joe, let's add a field in our customer database program we bought from Blaine). In the first case, you simply need to convert existing 'test' or beta data. This could be done through the use of a sequential file which keeps information on the field of a file. I use a program written to document file record types. It has the structure: Idx TYPE (1 byte) LENGTH (integer) COMMENTS (20 bytes) 1 A ?? Alpha-numeric / string 2 I 2 Integer 3 L 4 Long integer 4 S 4 Single precision 5 D 8 Double precision 6 C 8 Currency The Idx numbers are the key to the conversion. When inserting a line, the program will automatically assign a new and unique index to the Idx field. With this program, I save these structures in a data file that has a similiar name to the program data file I.E. Employee file is "EMPL.???" and the information file is "EMPL.FIL". Here's a sample of it: 1 A 10 ID 2 A 15 First name 3 A 1 Middle Initial 4 A 15 Last Name 5 A 9 Social Security Number 6 A 25 Address 7 A 15 City 8 A 2 State 9 A 10 Zip Code 10 C 8 Salary 11 S 4 Standard Rate If I need to change this, and have already entered dozens of employees as test data, then I copy this EMPL.FIL to EMPLFIL.OLD and run my program, insert lines and such where needed. Then run an auto conversion program: ftconvrt emplfil.old empl.fil data\EMPL.* or ftconvrt {old data file} {new data file} {files to change} Not only do you always have a record of your data structures (and it all prints out with "Page x of y" in a nice laser form layout) but conversion is quick, simple, automatic. Here's a side note on fielding data for your programs : You can field within a FOR/NEXT loop, reading the info from a sequential file, needing nothing more than the length of each field. FILE.DAT 25 (Record length) 5 (number of fields) 10,5,5,4,1 (field lengths) OPEN "I",1,"FILE.DAT" INPUT #1,Reclen OPEN "R",2,"FILE.RND",Reclen INPUT #1,NumFields REDIM Dat$(1 TO NumFields) Dum = 0 FOR i = 1 TO NumFields INPUT #1,FldLen FIELD 2,Dum AS Dummy$, FldLen AS Dat$(i) Dum = Dum + FldLen NEXT CLOSE 1 Now buffer 2 is fielded into Dat$() with the proper lengths. Okay - next item. A resizable, field changeable, all- purposeable file type. This is best accomplished with a file header. The only catch here is that the header may have some wasted space depending on the record size. The program described at the top can create such a header pretty easily. Header info: Integer - Record Size Integer - Number of Fields 4 bytes to start with. OPEN "R",1,"FILE.DAT",2 FIELD 1,2 AS Num$ GET 1,1 : RecSize = CVI(Num$) GET 1,2 : NumFields = CVI(Num$) REDIM Dat$(1 TO NumFields),DatType$(1 TO NumFields),DatLen(1 TO NumFields) Field info: Integer - Field Length 2 byte Ascii - Field Type Identifier (A,I,S,L,D,C) Rec = 3 ' starting location of FIELD info FOR i = 1 TO NumFields GET 1,Rec : Rec = Rec + 1 DatLen(i) = CVI(Num$) GET 1,Rec : Rec = Rec + 1 DatType$ = RTRIM$(Num$) NEXT CLOSE 1 You need to figure out where the actual records begin (after the header). FirstDataByte = Rec * 2 ' First byte past the header info IF FirstDataByte MOD RecSize = 0 THEN ' Directly on a record boundary FirstRec = FirstDataByte \ RecSize ELSE FirstRec = FirstDataByte \ RecSize + 1 ENDIF Dum = 0 OPEN "R",1,"FILE.DAT",RecSize FOR i = 1 TO NumFields FIELD 1,Dum AS Dummy$,DatLen(i) AS Dat$(i) Dum = Dum + DatLen(i) NEXT This type of record is great for dBase type applications, because you can dynamically change the record size and type, and do conversions on the fly. --- * Origin: Midnight Micro! V.32/REL (918)451-3306 (1:170/600)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET