home *** CD-ROM | disk | FTP | other *** search
- * Program..: NAMEGEN3.PRG
- * Author...: Tom Rettig
- * Date.....: August 30, 1984
- * Notice...: Copyright 1984 by Tom Rettig & Associates. All rights reserved.
- * Version..: dBASE III, version 1.00
- * Notes....: For generating memory variable names from data file
- * field names, and writing the memory variable
- * initialization routines and the STORE and REPLACE code.
- *
- * Saves the output in a text file with the same name as
- * the database file and a .TXT extension.
- *
- * Establish working environment, and prompt for data file name...
- SET TALK OFF
- CLEAR ALL
- ACCEPT "Enter [drive:]<data file name> with no extension -->" TO datafile
- STORE UPPER(TRIM(datafile)) + ".DBF" TO datafile
- *
- * Open the file if it exists, otherwise exit...
- IF FILE(datafile)
- USE &datafile
- ELSE
- ? datafile + " does not exist where I'm looking for it."
- SET TALK ON
- RETURN
- ENDIF
- *
- * Copy to a structure extended file to access the fieldnames...
- COPY TO Temp STRUCTURE EXTENDED
- USE Temp
- *
- * Convert field names to lower case...
- REPLACE ALL Field_name WITH LOWER(Field_name)
- *
- * Index and reopen the structure file, and erase the screen...
- INDEX ON Field_type + Field_name TO Temp
- USE Temp INDEX Temp
- CLEAR
- *
- * Initialize a text file to receive the output...
- STORE SUBSTR(datafile,1,AT(".",datafile)-1) TO textfile
- SET ALTERNATE TO &textfile
- SET ALTERNATE ON
- *
- * Output the initialization statements...
- STORE '00000000000000000000' TO zeros
- DO WHILE .NOT. EOF()
- DO CASE
- CASE Field_type = 'C'
- ? 'm_' + SUBSTR(Field_name,1,8) + ' = SPACE(' + ;
- STR(Field_len,3) + ')'
- CASE Field_type = 'N' .AND. Field_dec = 0
- ? 'm_' + SUBSTR(Field_name,1,8) ' = ' +;
- SUBSTR(zeros,1,Field_len-Field_dec)
- CASE Field_type = 'N' .AND. Field_dec > 0
- ? 'm_' + SUBSTR(Field_name,1,8) ' = ' + ;
- SUBSTR(zeros,1,Field_len-Field_dec-1) + '.' +;
- SUBSTR(zeros,1,Field_dec)
- CASE Field_type = 'L'
- ? 'm_' + SUBSTR(Field_name,1,8) + ' = .F.'
- CASE Field_type = 'D'
- ? 'm_' + SUBSTR(Field_name,1,8) + ' = CTOD(" / / ")'
- ENDCASE
- SKIP
- ENDDO
- *
- * Output the STORE statements...
- ?
- GO TOP
- DO WHILE .NOT. EOF()
- ? 'm_' + SUBSTR(Field_name,1,8) + ' = ' + ;
- UPPER(SUBSTR(Field_name,1,1)) + SUBSTR(Field_name,2,9)
- SKIP
- ENDDO
- *
- * Output the REPLACE statements...
- ?
- GO TOP
- DO WHILE .NOT. EOF()
- ? 'REPLACE ' + UPPER(SUBSTR(Field_name,1,1)) + SUBSTR(Field_name,2,9) +;
- ' WITH m_' + SUBSTR(Field_name,1,8)
- SKIP
- ENDDO
- *
- * Close the text file...
- SET ALTERNATE OFF
- SET ALTERNATE TO
- *
- * Restore the environment, and exit...
- CLOSE DATABASES
- SET TALK ON
- RETURN
- * EOF_ Namegen3.prg
-