home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Du Jour
/
SoftwareDuJour.iso
/
BUSINESS
/
DBASE
/
DBAPG.ARC
/
NAMEGEN2.PRG
< prev
next >
Wrap
Text File
|
1984-12-17
|
4KB
|
132 lines
* Program..: NAMEGEN2.PRG
* Author...: Tom Rettig
* Date.....: March 28, 1984
* Notice...: Copyright 1984 by Tom Rettig & Associates. All rights reserved.
* Version..: dBASE II, version 2.4x
* Notes....: For generating memory variable names from datafile
* 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
ACCEPT "Enter [drive:]<data file name> with no extension -->" TO datafile
STORE !(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...
ERASE
@ 1, 0 SAY "========================================"+;
"========================================"
@ 2, 0 SAY "||"
@ 2,19 SAY "C H A N G I N G T O L O W E R C A S E"
@ 2,78 SAY "||"
@ 3, 0 SAY "========================================"+;
"========================================"
*
DO WHILE .NOT. EOF
*
* Display the record number and uppercase field, and
* blank the previous lowercase field if there was one.
@ 10,20 SAY Field:name
@ 11,20 SAY #
*
* Initialize the memory variables.
STORE " " TO new:char
STORE 0 TO counter
*
* Loop to work on each character one at a time
* for the length of the field.
DO WHILE counter < LEN(TRIM(Field:name))
STORE counter+1 TO counter
STORE $(Field:name,counter,1) TO char
*
* If this character is an uppercase letter,
* replace with a lowercase letter.
IF char >= "A" .AND. char <= "Z"
STORE new:char+CHR( RANK(char)+32 ) TO new:char
ELSE
* If this character is not an uppercase letter,
* do not replace.
STORE new:char + char TO new:char
ENDIF
*
ENDDO
REPLACE Field:name WITH $(new:char,2,LEN(TRIM(Field:name))+1)
SKIP
ENDDO
@ 10,0
@ 11,0
@ 12,12 SAY "********** C H A N G E I S C O M P L E T E **********"
*
* Index and reopen the structure file, and erase the screen...
INDEX ON Field:type + Field:name TO Temp
USE Temp INDEX Temp
ERASE
*
* Initialize a text file to receive the output...
STORE $(datafile,1,@(".",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'
? 'STORE $(blank,1,' + STR(Field:len,3) + ' )' +;
' TO m:' + $(Field:name,1,8)
CASE Field:type = 'N' .AND. Field:dec = 0
? 'STORE ' + $(zeros,1,Field:len-Field:dec) +;
' TO m:' + $(Field:name,1,8)
CASE Field:type = 'N' .AND. Field:dec > 0
? 'STORE ' + $(zeros,1,Field:len-Field:dec-1) + '.' +;
$(zeros,1,Field:dec) + ' TO m:' + $(Field:name,1,8)
CASE Field:type = 'L'
? 'STORE F TO m:' + $(Field:name,1,8)
ENDCASE
SKIP
ENDDO
*
* Output the STORE statements...
?
GO TOP
DO WHILE .NOT. EOF
? 'STORE ' + !($(Field:name,1,1)) + $(Field:name,2,9) +;
' TO m:' + $(Field:name,1,8)
SKIP
ENDDO
*
* Output the REPLACE statements...
?
GO TOP
DO WHILE .NOT. EOF
? 'REPLACE ' + !($(Field:name,1,1)) + $(Field:name,2,9) +;
' WITH m:' + $(Field:name,1,8)
SKIP
ENDDO
*
* Close the text file...
SET ALTERNATE OFF
SET ALTERNATE TO
*
* Restore the environment, and exit...
SET TALK ON
RETURN
* EOF: Namegen2.prg