Tim
Thank you very much. I think I understand... But to check (as this is
all new to me): If I wanted to change the clipboard type from WP merge
to WP text (decimal value = 1), I could ignore all the values which DP
is showing on the top line (ie 140 say) and just use the following:
IF {STATE}&1~
and so on
DP would "know" that I was just referring to the clipboard type. Is this
right?
Victor Warner.
Tim Rude wrote:
The & is a binary AND operator. Prepare yourself for some geek-speak...
The various {STATE} values for DP are actually binary flags. The DP help screen
lists the following program states:
PROGRAM STATE FOR USE IN SHELL MACROS
User Options (Ctrl-F3) option 8 includes the shell state word in the
top line display. It only shows if the top line is selected for showing.
The value is shown in decimal & hex as an aid for shell macro construction.
1 0001 Clipboard type is WP merge (else DOS text)
2 0002 Clipboard used for report/import (else disk file)
4 0004 Clipboard will clear (else append) with each put to clipboard
8 0008 Report output goes to Display
16 0010 Report output goes to Printer
32 0020 Report output goes to File
192 00C0 64 0040 = Panel List displayed.
128 0080 = Panel displayed/selected -- depth is 1 (main panel)
192 00C0 = Panel displayed/selected -- depth more than 1
256 0100 Help active (help/edit help), or information message showing.
512 0200 DataPerfect shell menu active (Note: 0600 - editing help direct)
1024 0400 Yes/No or other prompt active.
14336 3800 2048 0800 = Report/Export/Import is running
4096 1000 = Search menu active
6144 1800 = Look-up active
8192 2000 = Define active (define index/panel/field)
10240 2800 = Reveal codes active
12288 3000 = Create/Edit record active
14336 3800 = Report List active
16384 4000 Editing report setup/text.
32768 8000 Cannot go to Shell - search, save, report, import in progress.
If these numbers were all written in Binary format, you would quickly notice a
pattern.
0000 0000 0000 0001 (1) Clipboard type is WP merge (else DOS text)
0000 0000 0000 0010 (2) Clipboard used for report/import (else disk file)
0000 0000 0000 0100 (4) Clipboard will clear (else append) with each put to
clipboard
0000 0000 0000 1000 (8) Report output goes to Display
0000 0000 0001 0000 (16) Report output goes to Printer
0000 0000 0010 0000 (32) Report output goes to File
0000 0000 0100 0000 (64) Panel List displayed.
0000 0000 1000 0000 (128) Panel displayed/selected -- depth is 1 (main panel)
0000 0000 1100 0000 (192) Panel displayed/selected -- depth more than 1
0000 0001 0000 0000 (256) Help active (help/edit help), or information message
showing.
0000 0010 0000 0000 (512) DataPerfect shell menu active (Note: 0600 - editing
help direct)
0000 0100 0000 0000 (1024) Yes/No or other prompt active.
0000 1000 0000 0000 (2048) Report/Export/Import is running
0001 0000 0000 0000 (4096) Search menu active
0001 1000 0000 0000 (6144) Look-up active
0010 0000 0000 0000 (8192) Define active (define index/panel/field)
0010 1000 0000 0000 (10240) Reveal codes active
0011 0000 0000 0000 (12288) Create/Edit record active
0011 1000 0000 0000 (14336) Report List active
0100 0000 0000 0000 (16384) Editing report setup/text.
1000 0000 0000 0000 (32768) Cannot go to Shell - search, save, report, import
in progress.
Suppose the current {STATE} of DP = 1153. That equates to
0000 0100 1000 0001
If you consider that each binary position represents a bit-flag that can be
either on (1) or off (0), the current state has the following three bit-flags
turned on: (1) Clipboard type is WP merge; (128) Panel displayed/selected --
depth is 1 (main panel); and (1024) Yes/No or other prompt active.
Each bit-flag can be toggled on/off without affecting the other bit-flags.
(Note that there are a few states that set/unset two bit-flags simultaneously
but most only toggle single bit-flags).
Since humans (and Shell macros) are more comfortable working with numbers in
decimal format rather than binary, we need an easy way to see if a specific
bit-flag is on or off without having to convert our number to a long series of ones
and zero's and checking the desired position. That's where the binary AND (&)
operator comes in. When you use it, you compare the bit-flags of two numbers and
return a number that shows which bit-flags were ON (1) in both of the compared
numbers.
So, for example, 1153&1024 essentially does this:
0000 0100 1000 0001 (1153)
0000 0100 0000 0000 (1024)
-------------------------------- & (AND)
0000 0100 0000 0000 (1024) result
Any column where there is a 1 in both values ends up as a 1 in the result. Any
column where there is a 0 in either value ends up as a 0 in the result. In our
case, the only place there is a 1 in both numbers in the same column is at the
11th column from the right. So that column ends up as the only bit-flag set to
1 in our result, making our result 1024. Since 1024 is a non-zero value, the
{IF} statement in the Shell macro interprets it as TRUE. If the result had been
zero, the {IF} statement would interpret it as FALSE.
Understanding the way these bit-flags works also explains why we can't do something
like simply checking if the {STATE} value is >=1024 or =1024. Because of the
interaction of other bit-flags, equality comparisons are meaningless. But the &
operator is the perfect tool for checking just that one bit-flag and ignoring what
other flags may or may not be set.
Tim Rude
----- Original Message -----
From: Victor Warner
To: Dataperfect Users Discussion Group
Sent: Monday, June 30, 2008 6:23 AM
Subject: Re: [Dataperf] How to determine whether linked databasehas
recordusing shell macro
Tim,
Adding the code you provided worked. Thank you very much.
I noticed that the {STATE} value is often higher than 1024 (because of the
other things going on with DP, but the code still works. How is that so.
Also what is the role of the "&" in {STATE}&1024?
Thank you again.
Victor
Tim Rude wrote:
Victor,
Have the shell macro go ahead and try to go through the link using the
down arrow. If there isn't an existing record, DP will pop up the
following prompt:
No records are found in this subset. If you want to add records,
press Create Record in Linked Panel (F5). Otherwise, you will
remain in this panel.
It will also sit there waiting for the user to press a key to dismiss
the prompt.
Your macro can check to see if the prompt is displayed by looking at the
{STATE} value. While the prompt is displayed and DP is waiting for a
user response, {STATE}&1024 will not be zero (i.e True).
So your shell macro could do something like this:
{Down}
{WAIT}2~
{IF}{STATE}&1024~
{;}No existing records, dismiss dialog and press F5 to create one...~
{Enter}
{F5}
{ELSE}
{;}Found at least one existing record, do something with it...~
{END IF}
The 2/10 second pause after the {Down} keystroke may not be needed. I
was just wanting to make sure DP had time to respond to the keystroke
before checking if the user prompt was displayed. Experiment with it to
see whether it's needed or not.
Tim Rude
----- Original Message -----
From: "Victor Warner" <[EMAIL PROTECTED]>
To: "Dataperfect Users Discussion Group" <[email protected]>
Sent: Saturday, June 28, 2008 6:33 AM
Subject: [Dataperf] How to determine whether linked database has
recordusing shell macro
I would like to create a shell macro which
1. Goes to field in a DP database which is a link; and
2. Test whether the linked database has a record
3. If there is a record, to go into (eg down arrow), or
4. If there is not create a record (eg F5).
I can create all of the shell macro except for the testing in 2.
Is this possible? And how can it be done? Help with this would be
greatly appreciated.
Victor Warner
_______________________________________________
Dataperf mailing list
[email protected]
http://lists.dataperfect.nl/mailman/listinfo/dataperf
_______________________________________________
Dataperf mailing list
[email protected]
http://lists.dataperfect.nl/mailman/listinfo/dataperf
------------------------------------------------------------------------------
_______________________________________________
Dataperf mailing list
[email protected]
http://lists.dataperfect.nl/mailman/listinfo/dataperf
------------------------------------------------------------------------
_______________________________________________
Dataperf mailing list
[email protected]
http://lists.dataperfect.nl/mailman/listinfo/dataperf
_______________________________________________
Dataperf mailing list
[email protected]
http://lists.dataperfect.nl/mailman/listinfo/dataperf