Category : Dbase (Clipper, FoxBase, etc) Languages Source Code
Archive   : TN9010.ZIP
Filename : SETFAR.TXT

 
Output of file : SETFAR.TXT contained in archive : TN9010.ZIP
This article is reprinted from the October 1990 edition of
TechNotes/dBASE IV. Due to the limitations of this media, certain
graphic elements such as screen shots, illustrations and some tables
have been omitted. Where possible, reference to such items has been
deleted. As a result, continuity may be compromised.

TechNotes is a monthly publication from the Ashton-Tate Software
Support Center. For subscription information, call 800-545-9364.

Taking SET()
One Step Further
Adam Menkes

As extensive as the dBASE IV SET() function has become with the
release of version 1.1, it is still limited in the types of results
that can be returned. You know that SET("Color") will return either
ON or OFF, but what if you want specific information such as
SET("Color of Normal") without getting the error message Invalid SET
Expression?

Moving Beyond SET() with SET1()

The user-defined function SET1() supplements the SET() function and
has the ability to return values for attributes that have more than
one word (such as PRINTER 1 FONT 1). This function could be used not
only to return the value of the SET() expression, but also to reset
all attributes to the default settings in the Config.db file (see
Procedure SetDefa). Since there are a few SET commands that can have
more than one attribute such as BELL (ON/OFF - Tone, Duration), CLOCK
(ON/OFF - Row, Col), CURRENCY (Justification LEFT/RIGHT, Symbol), and
DELIMITERS (ON/OFF - Symbol), you may want to alter the Config.db so
that the ON/OFF commands come after the other ones, or alter the
SetDbf.dbf to suit your needs to return a value for Set1() for these
particular commands. For example, you may want to change CURRENCY to
CURRENCYJ and CURRENCYS in SetDbf so that Set1("CurrencyJ") will
return either LEFT or RIGHT and Set1("CurrencyS") will return the
currency sign ("$", "›", "œ", "", or some other symbol). No changes
need be made to the Config.db file for the procedure SetDefa to work
for both attributes of the same SET command. For instance,

.? Set1("Currency")
$
.? Set1("Printer 1 Font 1")
{ESC}(8U, {ESC}(#@ NAME "ROMAN-8 SYMBOL SET"

SET1() Uses SetDBF.dbf

Although this function (and associated procedure) can return valid
expressions, the returned values are read from the Config.db initial
settings unless specific changes are made to the database SetDBF.dbf.
Therefore, if your Config.db file contains:

COLOR OF NORMAL = W+/B

and later you set color to BG/N, issuing the command

? SET1("Color of Normal")

will still return W+/B..

At right is a sample of a typical Config.db file which shows how the
data is retrieved and stored in a database (SetDbf). The data is
APPENDed FROM Config.db TYPE SDF, then the "=" is stripped off, the
blank lines (records) are removed, as well as the comment lines
(records). The database is then indexed so a SEEK may be performed.

Remember that for this to work the Config.db file must have the
settings in distinct columns in order to be appended properly. If you
use Dbsetup, this is done automatically and no modifications need to
be made.

The procedure SetDefa resets all your SET selections to the defaults
in your Config.db file. In order to ensure that certain commands can
be reset, select the SET option in the Dbsetup program, even if you
are going to leave it as the default (as dBASE IV does not write the
defaults to the Config.db file). For example, the F2 function key
(default is "ASSIST") does not appear in your Config.db, yet when you
display your SET options, it appears. If the F2 key were selected in
Dbsetup and saved even if the key remains "ASSIST", it will be saved
to your Config.db and any changes to this key during program execution
will be reset when this procedure is executed. However, keys that
were not included in the Config.db that are changed within dBASE IV
will not be reset unless you change your Config.db file to show the
key equal to nothing (example: Ctrl-F5 = ) or modify your SetDbf.dbf
database to include the keys you want reset to the defaults or blanks.

A procedure called Nada is referenced in the other procedures. It is
not listed here since it is only one command line in length. The
command RETURN is the only command it contains. Why is this
procedure even necessary? As the name suggests, it does nothing, or
does it? Actually, this procedure is essential to ignore errors and
continue your program, as the command "ON ERROR" by itself will call
up the dBASE error message and wait until you CANCEL, IGNORE, or
SUSPEND before continuing. Whereas the command "ON ERROR DO
Something" will bypass the dBASE error checking and accept the
user-defined error message which, in this case, is nothing, and allow
the program to continue without interruption. Alternatively, your
command statement could be "ON ERROR DummyVar = 0" or any other data
stored to a dummy memory variable.

FUNCTION Set1()
FUNCTION Set1
PARAMETER mSet

IF .NOT. FILE("SetDbf.DBF") .OR. .NOT. FILE("SetDbf.MDX")
DO SetDbf
ELSE
DO SelArea1 WITH "SetDbf" && *&*
SET ORDER TO dCommand
ENDIF

SEEK UPPER(mSet)
IF FOUND()
mSet1 = LTRIM(Attribute)
ELSE
mSet1 = "None"
ENDIF
RETURN mSet1

Listing: SetDBF.prg
PROCEDURE SetDbf
mSafety = SET("Safety")
DO Efile WITH "Temp" && *&*
DO SelArea1 WITH "Catalog.CAT" && *&*
* Any Database may be used to create an empty STRUCTURE
EXTENDED file.
COPY STRUCTURE EXTENDED TO Temp.DBF

SELECT SELECT() && Select next highest available work
area.
USE Temp
ZAP && Leaves an empty STRUCTURE EXTENDED
database.

APPE BLANK
REPLACE Field_Name WITH "dCommand", Field_Len WITH 20,;
Field_Type WITH "C"
APPE BLANK
REPLACE Field_Name WITH "Attribute", Field_Len WITH 50,;
Field_Type WITH "C"
* Adds 2 character fields to the database (dCommand and
Attribute).

DO Efile WITH "Setdbf" && *&*
DO SelArea1 WITH "Temp" && *&*
USE
SELECT SELECT() && Select next highest available work
area.
CREATE SetDbf FROM Temp
* CREATE a database from the STRUCTURE EXTENDED database.
* This section gets the DOS environmental variable
'DPATH' which
* you SET to the location of the Config.DB file prior to
entering
* dBase. In your Autoexec.BAT (or any batch file to
enter dBase),
* put in SET DPATH = :.
* Example: SET DPATH = C:\DATA\DBASE\

mPath = GETENV("dPath")
IF RIGHT(mPath, 1) <> "\" .AND. LEN(TRIM(mPath)) <> 0
mPath = mPath + "\"
ENDIF
* Checks to see if DPATH was SET in DOS and if it has an
ending "\".

APPEND FROM &mPath.Config.DB TYPE SDF

* Note that the first period terminates the macro.
* In this example, '&mpath.Config.DB' is
'C:\DATA\DBASE\Config.DB'.
* If you prefer not using DOS variables, simply hard-code in
the
* full path to your Config.DB in the above command line
instead
* of using the macro substitution, and remove all the code
between

SCAN
IF LEN(TRIM(dCommand)) = 0 .OR. SUBSTR(dCommand, 1, 1)
= "*"
DELETE && DELETE all non-command records.
ENDIF
ENDSCAN

REPLACE ALL Attribute WITH UPPER(SUBSTR(Attribute, AT("=", ;
Attribute) + 2, LEN(Attribute)))
* Remove the '=' from the ATTRIBUTE field.

REPLACE ALL dCommand WITH UPPER(dCommand)
* Convert all commands to uppercase.

PACK && Get rid of DELETEd records.
INDEX ON dCommand TAG dCommand
SET SAFETY &mSafety && Restore SAFETY settings.
RETURN

Listing: SetDefa.prg
PROCEDURE SetDefa
PRIVATE mdCommand, mAttribute
ON ERROR DO Nada
* This ON ERROR routine is necessary because errors will
* be encountered in the SCAN / ENDSCAN loop as some SET
* commands SET something, others SET a command TO
something.

IF .NOT. FILE("SetDbf.DBF") .OR. .NOT. FILE("SetDbf.MDX")
DO SetDbf
ELSE
DO SelArea1 WITH "SetDbf" && *&*
SET ORDER TO dCommand
ENDIF

SCAN
mdCommand = dCommand
mAttribute = Attribute

SET &mdCommand TO &mAttribute
SET &mdCommand &mAttribute
SET FUNCTION &mdCommand TO &mAttribute
* Without keeping a database of acceptable SET,
SET ... TO,
* and SET FUNCTION ... TO commands, this will
try the same
* command all three ways and, because of the ON
ERROR, ignore
* the ones that are unacceptable.

ENDSCAN
ON ERROR &&
Reset to default
RETURN

MacroMan! Procedures and Functions (see July 1990 edition of
TechNotes/dBASE IV)

PROCEDURE Efile
*Ä Erases a specified file, even if the file is currently in
USE.
*Ä SYNTAX : DO Procedure WITH
*Ä Example: DO Efile WITH "BadFile.TXT"
PARAMETER vDbf && File to be
erased.
vDbf=FullDbf(vDbf) && ** Checks for .DBF
extension.
IF FILE(vDbf)
IF Inuse(vDbf)<>0 && ** If
database is SELECTed
MSelDbf=Inuse(vDbf) && ** it
returns the Work Area
SELECT(MSelDbf) && and SELECTs that Work Area
USE
&& and closes it so that it can
ENDIF
&& be erased.
ERASE(vDbf)
ENDIF
RETURN

FUNCTION InUse
PARAMETER vDbf
SET EXACT ON
*Ä SET EXACT OFF would cause potential problems if you were
* checking for a database such as "Client" without
specifying the
* extension if a file called Client1, Myclient, or similar
existed
* in the same directory.

mAlias=0
vDbf=FullDbf(vDbf) && See next UDF below
mCount=1
DO WHILE mCount<=10 && This loop checks all 10
Areas.
SELECT(mCount)
IF (vDbf) $ UPPER(DBF())
*Ä The '$' is used instead of '=' so the PATH
does not have
* to be specified in the variable.

mAlias=mCount && Sets the Work Area where it
is being USEd.
RETURN mAlias
*Ä Exit the loop once the Area is found
ENDIF
mCount=mCount+1 && Increments
to check next Area.
ENDDO
SET EXACT OFF
RETURN mAlias


FUNCTION FullDbf
PARAMETER vDbf

vDbf=UPPER(vDbf) && Convert to
Uppercase.
IF LEN(TRIM(vDbf))<>0 && Checks for null.
IF AT(".",vDbf)=0 && Checks for an
extension.
vDbf=TRIM(vDbf)+".DBF" && Adds '.DBF' to the
parameter.
ENDIF
ENDIF
RETURN vDbf


PROCEDURE SelArea1
*Ä Selects Area where DATABASE is in
* use or opens it in an unused area.
*Ä Must be used in conjunction with SelArea2

PARAMETER mParam1
PUBLIC mWasOpen,mMaindbf

IF Inuse(mParam1) <>
0
mMainDbf=Inuse(mParam1) && See Inuse(),
previous page
SELECT(mMainDbf)

mWasOpen=.T.
*Ä mWasOpen is TRUE when the database is in USE prior
to
* being opened by a procedure or function.
ELSE
mMainDbf=SELECT()
SELECT(mMainDbf)
USE(mParam1)
mWasOpen=.F.
*Ä mWasOpen is FALSE if the database was not in USE,
whether
* or not it gets USEd during a procedure or
function.
ENDIF
RETURN




  3 Responses to “Category : Dbase (Clipper, FoxBase, etc) Languages Source Code
Archive   : TN9010.ZIP
Filename : SETFAR.TXT

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/