Dec 132017
 
Aston Tate dBase IV Tech Notes for Nov 89. Useful information.
File TN8911.ZIP from The Programmer’s Corner in
Category Dbase Source Code
Aston Tate dBase IV Tech Notes for Nov 89. Useful information.
File Name File Size Zip Size Zip Type
ADDFIELD.PRG 1469 711 deflated
DB4TIPS.TXT 5418 2502 deflated
GATHER.TXT 9229 3752 deflated
GROUPS1.TXT 1083 551 deflated
GROUPSUM.TXT 3291 1550 deflated
INITFORM.COD 8929 2362 deflated
KEYWORD.PRG 699 384 deflated
NET.TXT 14632 5486 deflated

Download File TN8911.ZIP Here

Contents of the DB4TIPS.TXT file


Using dBASE IV
Tips, techniques and anomalies for the dBASE IV user and programmer.
Initializing a Calendar
It doesn't come up a lot, but it does come up at the end of each year. How do
you create a "calendar" database? That is, a database with 365 records, each
record being unique due to the date field.

There are two ways. In both cases you have to create the database with 365
records (see below) but in one case you put the date in when you're creating
the records; in the other, you put in the dates all at once with the REPLACE
ALL command.

Anyway, here's a small program to create 365 records in a database called
"Calendar" and place the date into a field called "Date":


USE Calendar
i = 0
DO WHILE i < 365
APPEND BLANK
REPLACE Date WITH CTOD("01/01/90") + i
i = i +1
ENDDO

Easy, huh? It's obvious, but worth noting anyway, that if the first record is
the first of January, the day of the year is equal to the record number. So,
November 11, 1990, is record 308 and, not coincidentally, also day 308 in the
year 1990.

If you wanted to start the calendar with today's date, the REPLACE command
would be this:

REPLACE Date WITH DATE() + i
Now suppose that you already have a database and you want to stick an
incrementing date into each record. Easy, just

REPLACE ALL Date WITH DATE() + RECNO() -1
or
REPLACE ALL Date WITH CTOD("01/01/90") + RECNO() -1
Since the record numbers start at one, you have to subtract one or you'll
start the calendar on tomorrow's date, not today's.

Speaking of shopping days (not that we were), there are only
CTOD("12/25/" + RIGHT(STR(YEAR(DATE())),2)) - DATE()
days left in this year to buy that special somebody their gift subscription to
TechNotes.

Pick-lists in Retrospect
In the January '89 edition of TechNotes/dBASE IV, Mike Hedblum wrote a very
nicely received article about working with menus. Here, he's modified the
code so that the pick-list is not displayed everytime the cursor is moved
onto the field. Instead, the pick-list is activated by pressing the
spacebar.


*--- Define pick-list.
DEFINE POPUP Priority FROM 3,5 PROMPT FIELD Detail
ON SELECTION POPUP Priority DEACTIVATE POPUP

@ 1,30 SAY "Priority"
*--- GET from pick-list.
@ 1,39 GET priority PICTURE "XX" WHEN Prior_ok(1,39) READ
RETURN

FUNCTION Prior_ok
PARAMETERS row, col
IF .NOT. Edit_ok() && Display popup?
RETURN .F. && No.
ENDIF
SELECT Priority
DO WHILE .T.
ACTIVATE POPUP Priority && Activate popup.
IF LASTKEY() <> 27 && If {Esc}, redo.
EXIT
ENDIF
ENDDO
SELECT Ptrs && Update file and screen.
REPLACE Priority WITH Priority->Detail
@ row, col SAY new_pri COLOR n/bg
RETURN .F.


FUNCTION Edit ok
SET MESSAGE TO "Press {Space} to change value"
IF INKEY(0) <> 32 && If key is not {Space},
SET MESSAGE TO
RETURN .F. && Not space.
ENDIF
SET MESSAGE TO
RETURN .T. && Allow pick-list.
Unrestricting ON KEY LABEL
Because procedures executed through the ON KEY LABEL command (for example, "ON
KEY LABEL F1 DO Proc1") are a special type, some dBASE IV commands are
excluded from being used in these procedures. These are called restricted
commands. Also, programs called within your ON KEY LABEL program (i.e. Proc1
calls Proc2) cannot contain restricted commands.

Restrictions are listed under "FUNCTION" in the dBASE IV Language Reference
starting on page 2-140. If any of these restrictions are used in your ON
KEY LABEL program, dBASE IV will return the message "Restricted Command" when
you press the key that executes the ON KEY LABEL program.

When you get this error message you know that you're using at least one
restricted command; but maybe you've checked and double-checked your code and
can't find where the problem command lies. dBASE IV doesn't give you the
line number with the restricted command either. You're stuck, right? A
rhetorical question, of course. Here's how to get dBASE to tell you where
you've errored.

What we'll do is copy the problem ON KEY LABEL procedure to a file of its own,
turn it into a function, and compile it. dBASE will tell you exactly what
line the restricted command is on. You can then correct the problem and
continue your work.

Follow these steps:
1.Make a copy of the ON KEY LABEL procedure and put it in a file of its
own.

2.Edit the file. If the first line begins with the word PROCEDURE, delete
the first line. The first line of the file should read

FUNCTION
where is the file you're editing.
3.Since functions must return values, after all RETURN statements place a
dummy value (i.e. "RETURN 1" or "RETURN .T."). This can be done easily by
using the search and replace feature of the editor.

4.Save the file, go to the dot prompt and compile the file by using the
COMPILE command.

All restricted commands and the lines they're on will appear as compile
errors. Easy, Huh?

Suppressing the License Screen
Both dBASE IV and dBASE IV Runtime have a command line switch that will
suppress the license screen and its requirement to press Return. Adding a
"/T" to the DOS command line (as in "DBASE /T" or "RUNTIME /T") will cause
the product to start with an abbreviated notice that will disappear without
prompting in about a second.s


 December 13, 2017  Add comments

Leave a Reply