Página 2 de 9
Command Needed
Enviado: 08 Jan 2013 18:24
por marge0512
Yes, you are right........a loop is what i need. I want it to search all records and return those records (using the word I choose, like "Inc") and bring back in alphabetical order. I do not have dbase on my machine so I cannot open a dbf to delete records and change confidential fields so that i may attach a sample. I have to open the information in excel to be able to read the information in the database.
I will check details though. I may have missed something??
Command Needed
Enviado: 08 Jan 2013 19:29
por marge0512
Hi, i have a question........will one dollar operand search for a word before and after the name? For example, with the code you gave me:
If REC2Find $ UPPER(COMPNY_NAM)<=====This is the field name.
Will the $ search for.....lets say the word "INC".......before and after the company name? I'm thinking of terms as in %like will search the word before the name, like% will search after the name and %like% will search before and after the name. Does just one $ search before and after also?
Thanks!
Command Needed
Enviado: 08 Jan 2013 21:54
por fladimir
Yes, before and after.
Regards...
Command Needed
Enviado: 11 Jan 2013 12:45
por marge0512
Well, i did look at details and I had forgotten the database name before the field name so all is well but I cannot use our SCRL_TOS function because it only displays the last record found. I need to search for a word and have it display ALL records with that information. For example, if i enter the word "Inc" I want all records with the word "Inc" to display on the screen. When i used the "Display" command, it ran through all of the records with the word "Inc" but they didn't stay on the screen. It just ran through the list and then disappeared. I'm sure there must be a way to display them but I need help. I'm researching right now and it looks like maybe the "Say" command??
Thanks!!
Command Needed
Enviado: 11 Jan 2013 15:24
por alxsts
Hi!
In this case, you should export all records meeting the selection criteria to a temporary table:
Código: Selecionar todos
COPY TO tmpTable FOR Upper(REC2Find) $ UPPER(COMPNY_NAM)
After, open that temp table and browse it using DbEdit() function. Try it and if you need any help, keep posting.
Syntax for the COPY command:
Código: Selecionar todos
COPY
Syntax: COPY TO <file>/(<expC1>) [<scope>] [FIELDS <field list>]
[FOR <condition>] [WHILE <condition>]
[SDF/DELIMITED/DELIMITED WITH <delimiter>/(<expC2>)]
Purpose: To copy all or part of the current database file to a new
file.
Arguments: <file> is the name of the new file. If no type clause
is specified, (.dbf) is the default file type and no
extension is necessary. If there is a type clause
specified, the file extension is assumed to be (.txt) unless
specified.
Options: Fields: The FIELDS clause specifies the list of fields
to copy to the target database file. The default is all
fields.
Scope: The <scope> is the portion of the current
database file to COPY. The default is ALL.
Condition: The FOR clause specifies the conditional set
of records to COPY within the given scope. The WHILE clause
specifies the set of records meeting the condition from the
current record until the condition fails.
SDF: The SDF clause specifies the output file type as a
System Data Format ASCII file. Records are fixed length,
each separated by a carriage return/line feed pair. Fields
are fixed length and there is no field separator. Character
fields are padded with trailing blanks, numeric fields are
padded with leading blanks, date fields are written in the
form YYYYMMDD, and logical fields are written in the form
T/F. The end-of-file mark is Ctrl-Z (1A hex.)
Delimited: The DELIMITED clause specifies the output
file type as a DELIMITED ASCII file. Records are variable
length, each separated by a carriage return/line feed pair.
Fields are variable length and separated by commas.
Character fields are bounded by delimiters (the double quote
mark is the default unless you specify a different character
using the WITH clause). Leading and trailing spaces for
numeric and character fields are truncated, date fields are
written in the form YYYYMMDD, and logical fields are written
in the form T/F. Ctrl-Z (1A hex) is the end-of-file mark.
Note: DELIMITED WITH BLANK, DIF, SYLK, and WKS file type
options are not supported in addition to the TYPE keyword.
Usage: All records contained in the active database file are copied
unless limited by a scope or FOR/WHILE clause. Records
marked for deletion will be copied unless DELETED is ON or a
FILTER has been SET.
Network: When you COPY in a network environment, Clipper opens the
target database file EXCLUSIVE.
Library: CLIPPER.LIB
----------------------------------- Examples -------------------------------
This example demonstrates COPYing to another database file:
USE Sales
? LASTREC() && Result: 84
COPY TO Temp
USE Temp
? LASTREC() && Result: 84
The following examples use Testdata.dbf which has four fields, one
for each data type: Char, Num, Date, Logical. For purposes of the
following examples, Testdata contains the following data:
USE Testdata
? Char, Num, Date, Logical
Result:
Character 12.00 08/01/87 .T.
This example COPYs TO an SDF file:
COPY NEXT 1 TO Temp SDF
TYPE Temp.txt
Result:
Character 12.0019870801T
This example COPYs TO a DELIMITED file:
COPY NEXT 1 TO Temp DELIMITED
TYPE Temp.txt
Result:
"Character",12.00,19870801,T
This example COPYs TO a DELIMITED WITH a different delimiter:
COPY NEXT 1 TO Temp DELIMITED WITH '
TYPE Temp.txt
Result:
'Character',12.00,19870801,T
[b]
Syntax for DbEdit function:[/b]
Código: Selecionar todos
DBEDIT()
Syntax: DBEDIT([<expN1>] [,<expN2>] [,<expN3>] [,<expN4>]
[,<array1>] [,<expC>] [,<array2>] [,<array3>] [,<array4>]
[,<array5>] [,<array6>] [,<array7>])
Purpose: To display and edit records from one or more work areas
using a browse-style table layout that executes within a
defined window area.
Arguments: <expN1...expN4> are the coordinates of the DBEDIT()
window. Any, or all, of these arguments can be specified.
<array1> is an array of <expC> containing field names or
expressions of any type. If this argument is not specified,
DBEDIT() defaults to all fields in the current work area.
<expC> is the name of a user-defined function that
executes when an unrecognizable key is pressed or there are
no keys pending in the keyboard buffer. Specify the
function name without parentheses or arguments. Note that
the behavior of DBEDIT() is affected by the presence of this
argument. Refer to the discussion below for more
information.
<array2> is an array of <expC> to be used as PICTURE
strings for column formatting. Specifying an <expC> instead
of an array formats all columns with the same picture.
<array3> is an array of <expC> for column headings.
Specifying <expC> instead of an array gives the same heading
for all columns. To display multi-line headings, embed
semi-colons.
<array4> is an array of <expC> used to draw horizontal
lines separating headings and the field display area.
Specifying an <expC> instead of an array uses the same
character for the heading line separator for all columns.
<array5> is an array of <expC> used to draw vertical
lines separating displayed columns. Specifying an <expC>
instead of an array uses the same separator for all columns.
<array6> is an array of <expC> used to draw horizontal
lines separating footings and the field display area.
Specifying an <expC> instead of an array uses the same
footing line separator for all columns.
<array7> is an array of <expC> to display as column
footings. To force a column footing onto more than one
line, embed a semi-colon where you want the string to
break. Specifying an <expC> instead of an array gives all
footings the same value.
All arguments are optional. You must, however, pass a dummy
argument for any argument you wish to skip.
Returns: A logical value.
Usage: DBEDIT() is an interface function that displays records from
one or more work areas in a table form. It formats the
display according to the window coordinates and the fields
array. All cursor movement keys are handled within
DBEDIT(), including PgUp, PgDn, Home, End, the four arrows,
and all valid Ctrl key combinations that produce cursor
movement. The following are the active keys when a user
function argument is not specified:
Table: DBEDIT() Active Keys
----------------------------------------------------
Key Action
----------------------------------------------------
Uparrow Up one row
Dnarrow Down one row
Leftarrow Column left
Rightarrow Column right
Ctrl-Leftarrow Pan left one column
Ctrl-Rightarrow Pan right one column
Home Leftmost current screen column
End Rightmost current screen column
Ctrl-Home Leftmost column
Ctrl-End Rightmost column
PgUp Previous screen
PgDn Next screen
Ctrl-PgUp First row of current column
Ctrl-PgDn Last row of current column
Return Terminate DBEDIT()
Esc Terminate DBEDIT()
----------------------------------------------------
User Function: When the user function argument (<expC>)
is specified, all keys indicated above are active with the
exception of Esc and Return. When DBEDIT() calls the user
function, it automatically passes two parameters: "status"
and "fld_ptr." The status parameter indicates the current
state of DBEDIT() depending on the last key executed before
the user function was called. The following are the
possible status values:
Table: DBEDIT() Status Messages
----------------------------------------------------------
Status Description
----------------------------------------------------------
0 Idle, any cursor movement keystrokes have been
handled and no keystrokes are pending
1 Attempt to cursor past beginning-of-file
2 Attempt to cursor past end-of-file
3 Database file is empty
4 Key exception
----------------------------------------------------------
The other parameter, fld_ptr, is an index into the array of
field names (<array1>). If <array1> was not specified,
fld_ptr points to the current field in the database
structure and can be accessed using FIELD().
When the user function has been called, you must return a
value instructing DBEDIT() what action to perform next. The
following table summarizes the possible request values and
their consequences:
Table: Requests to DBEDIT() from User Function
----------------------------------------------------------
Value Description
----------------------------------------------------------
0 Quit DBEDIT()
1 Continue DBEDIT()
2 Force reread/repaint and continue;
after repaint, process keys, and go to idle
3 Append mode (not recommended)
----------------------------------------------------------
The user function is called in a number of different
instances:
. A key exception occurs. This happens when DBEDIT()
fetches a keystroke from the keyboard that is not a
DBEDIT() executable key. Any pending keys remain in the
keyboard buffer until fetched within the user function or
DBEDIT() continues.
. DBEDIT() goes to idle. This happens when the keyboard is
empty or after a screen refresh (request = 2) and all
pending keys have been processed. In this instance,
there is one call to the user function.
. Beginning or end-of-file are encountered. This is the
same as idle. All executable keys are performed and then
there is one call with the indicating status message.
Note that when DBEDIT() is first executed, all keys pending
in the keyboard are executed and then DBEDIT() goes to idle
with a user function call. If no keys are pending, the idle
state is immediate.
The structure of the user function should be set up to
handle all status messages received from DBEDIT(). Status
messages characteristically indicate the current state of
DBEDIT() and point to the type of action to be taken by the
user function. The structure therefore should consist of a
CASE structure that branches control to a subprocedure for
each status message to process. Although you may be
interested in less than all five of the status message
values, your structure should at a minimum process idle
states (status = 0) and key exceptions (status = 4).
Ignored status messages can be processed by the OTHERWISE
clause. Tests for specific key presses should only take
place within the called subprocedure. The following block
of code demonstrates the basic structure of a typical user
function:
FUNCTION UserFunc
PARAMETERS status, fld_ptr
PRIVATE request
*
key_stroke = LASTKEY()
*
DO CASE
CASE status = 0
* Idle.
request = ProcessIdle(key_stroke)
CASE status = 1
* Beginning-of-file.
request = ProcessBof(key_stroke)
CASE status = 2
* End-of-file.
request = ProcessEof(key_stroke)
CASE status = 3
* Empty database file.
request = ProcessEmpty()
CASE status = 4
* Key exception.
request = KeyExcept(key_stroke)
OTHERWISE
request = 1
ENDCASE
*
RETURN request
To allow further processing of keys and the subsequent use
of LASTKEY() within called subprocedures, save the value of
the last key pressed to a memory variable before entering
the main CASE structure. Then pass that key value
throughout your subprocedure system as a parameter. To
allow execution of statements after the CASE structure, make
your request to DBEDIT() by assigning the request value to a
memory variable and then RETURN the value as the last
statement in the user function.
The two most important subprocedures in the user function
architecture are the idle state processor and the key
exception handler. In the idle state processor, you perform
the following two basic classes of actions:
. Update a status area on the screen
. Perform actions based on the last DBEDIT() key
executed
The key exception handler is where most of the activity of
the user function system takes place. Here you process user
requests for the following common actions:
. Exit from DBEDIT()
. Toggle the current record delete status
. Edit the current field
. Entry into a menu system
As an example, the following user-defined function
demonstrates a typical key exception handling procedure to
process all of these actions:
FUNCTION KeyExcept
PARAMETER action_key
*
DO CASE
CASE action_key = 27
* Esc...exit DBEDIT().
RETURN 0
CASE action_key = 13
* Return...field edit (see discussion below).
RETURN FieldEdit()
CASE action_key = 7 .AND. (.NOT. EOF()) .AND.;
LASTREC()<> 0
* Del...toggle delete status.
IF DELETED()
RECALL
ELSE
DELETE
ENDIF
RETURN 1
CASE action_key = -9
* F10...enter menu system.
RETURN MenuSys()
OTHERWISE
* Any other key...slightly distasteful tone.
TONE(100, 1)
RETURN 1
ENDCASE
To edit the current field value, test for the field edit key
in the key exception handler and then branch to a
user-defined function--like the following--to GET the field
name corresponding to the "fld_ptr" index in the field array
(<array1>).
FUNCTION FieldEdit()
PRIVATE index_exp, index_val, filter_exp, field_name
* Save current key expression and value.
index_exp = INDEXKEY(0)
index_val = &index_exp.
* Save current filter expression.
filter_exp = DBFILTER()
* Edit current field value.
SET CURSOR ON
field_name = field_list[fld_ptr]
@ ROW(), COL() GET &field_name.
READ
SET CURSOR OFF
* Refresh screen if key value has changed.
RETURN IF(index_val != &index_exp. .OR.;
(!&filter_exp.), 2, 1)
Within FieldEdit() there are four important issues:
The key value changes--if the key value of the controlling
index has changed, update the screen so that the current
record displays in its new position in the index. When you
send a refresh screen request to DBEDIT() (request = 2), the
cursor remains at its current screen position but the screen
display is updated to reflect the change of the current
record in the index. To set this up, save both the
controlling index key expression and its current value
before editing the current field value. Then after the
field edit is complete, send a request for a screen refresh
if the new key value is not the same as the old key value.
The current record is no longer within the filter scope--if
after a change to a field value, the current record is no
longer within the scope of the current filter condition,
update the screen (request = 2) to remove the record from
the display. To set this up, first save the current filter
expression using DBFILTER(). Then after editing the current
field, evaluate the filter expression as a macro and refresh
the screen if it returns false (.F.).
The appearance of the cursor--by default, the DBEDIT()
cursor is OFF. You must therefore SET CURSOR ON before
executing a READ and SET it OFF after the READ.
Accessing the current field name--if you specify a field
array (<array1>) as an argument to DBEDIT() you must use the
same array name in FieldEdit(). If you have not, obtain the
field name using FIELD() using "fld_ptr" as the argument.
Nesting: You can call multiple copies of DBEDIT() within
each copy of DBEDIT() allowing you multiple browse windows
on the screen at one time.
Library: EXTEND.LIB
----------------------------------- Examples -------------------------------
This example demonstrates how to use DBEDIT() with a user function.
SELECT 2
USE Customer INDEX Customer
SELECT 1
USE Sales INDEX Sales
SET RELATION TO Cust_num INTO Customer
DECLARE field_list[4]
field_list[1] = "Branch"
field_list[2] = "Salesman"
field_list[3] = "Amount"
* Fields in another work area must include the alias.
fields[4] = "Customer->Customer"
DBEDIT(4, 0, 22, 79, field_list, "UserFunc")
Command Needed
Enviado: 11 Jan 2013 16:59
por marge0512
Thank you so much!! I don't think that I would have figured out that I would have to put the info in a temp database! I've been trying all sorts of things and running into a dead end every time. I will work with this and ask if I need any help. Thanks again!
Command Needed
Enviado: 11 Jan 2013 20:04
por alxsts
Hi!
Made some changes to your original source code according to last post (temporary table and browsing records). I haven't compiled. Please compile and test.
Código: Selecionar todos
procedure REC_FND
private REC2FIND, SAV_REC
* Save current position in database if search fails
*--------------------------------------------------
PRIVATE cOldArea, cOldScreen
PRIVATE cBorder = CHR(218) + CHR(196) + CHR(191) + CHR(179) +;
CHR(217) + CHR(196) + CHR(192) + CHR(179)
DECLARE field_list[1]
SAV_REC = recno()
set color to &GET_CLR
read
* Continue if escape wasn't pressed
*----------------------------------
if LASTKEY()#ESC_KEY
*--------------------------------
REC2FIND = space(40)
do DISP_MSG with 'Client (include punctuation): '
@row(),col() get REC2FIND
read
* Continue if the escape key was not pressed
*-------------------------------------------
if lastkey() # ESC_KEY
* Remove trailing spaces
*-----------------------
REC2FIND = UPPER(trim(REC2FIND))
*-- AlxSts - Start ---------------------*
* Copy records containing the pattern, if any
*---------------------
COPY TO tmpTable FIELDS COMPNY_NAM FOR (REC2FIND $ UPPER(COMPNY_NAM))
* Save the current work area
*---------------------
cOldArea = SELECT()
* Open Temp table
*---------------------
USE tmpTable EXCLUSIVE
* Check if records exist
*---------------------
IF tmpTable->( LastRec() ) > 0
* yes...
GO TOP
* Create a column heading for DbEdit() column/window
*---------------------
field_list[1] = " Select Company Name "
* Save the screen area used by popup window
*---------------------
cOldScreen = SAVESCREEN(5, 14, 20, 63)
* Draw a box with single border
*---------------------
@ 5, 14, 20, 63 BOX cBorder
* Browse records in tmp table until user
* cancels browsing (ESC) or a record is selected (ENTER)
*---------------------
DBEDIT(6, 15, 19, 62, field_list, "_REC_FND_")
* Restore screen region
*---------------------
RESTSCREEN(5, 14, 20, 63, cOldScreen)
* Restore previous work area
*---------------------
Select( cOldArea )
IF LASTKEY() # ESC_KEY
* User selected someone.
* Save company name from tmp table...
*---------------------
REC2FIND = TRIM(tmpTable->COMPNY_NAM)
* Seek for selected company name
* in the original table...
*---------------------
* Get client index
*--------------------
set order to 7
* Search using the key
*---------------------
set exact off
seek REC2FIND
set exact on
* Return to the first index
*--------------------------
set order to 1
* If found, put the highlight bar on the record
*----------------------------------------------
if !eof()
do SCRL_TOS
else
* If not found, tell the user
*----------------------------
do DISP_MSG with [Client, ]+trim(REC2FIND)+[, not found. Press a key.]
inkey(0)
go SAV_REC
endif
ELSE
* user cancelled...
go SAV_REC
ENDIF
ELSE
Select( cOldArea )
do DISP_MSG with [Client, ]+trim(REC2FIND)+[, not found. Press a key.]
inkey(0)
go SAV_REC
ENDIF
* delete tmpTable...
SELECT( "tmpTable" )
USE
ERASE tmpTable.dbf
SELECT( cOldArea )
ENDIF
*-- AlxSts - End ---------------------*
endif
RETURN
*----------------------------
* User function for DbEdit()
*----------------------------
FUNCTION _REC_FND_
PARAMETERS status, fld_ptr
PRIVATE request
*
key_stroke = LASTKEY()
*
*Table: Requests to DBEDIT() from User Function
*----------------------------------------------------------
*Value Description
*----------------------------------------------------------
* 0 Quit DBEDIT()
* 1 Continue DBEDIT()
* 2 Force reread/repaint and continue;
* after repaint, process keys, and go to idle
* 3 Append mode (not recommended)
*----------------------------------------------------------
DO CASE
CASE status = 0
* Idle. Continue
request = 1
CASE status = 1
* Beginning-of-file.
request = 1
CASE status = 2
* End-of-file.
request = 1
CASE status = 3
* Empty database file.
request = 0
CASE status = 4
* Key exception.
IF key_stroke = 27
* Exit
request = 0
ELSEIF key_stroke = 13
* Record selected...
* exit with temp table file pointer over selected record
request = 0
ENDIF
OTHERWISE
request = 1
ENDCASE
*
RETURN request
*
PS: there is a Clipper Summer guide
here
Command Needed
Enviado: 14 Jan 2013 18:04
por marge0512
Now that............is so cool!!!!!!! Thanks!!
I've been working with this all day and I don't understand it all but I am one happy person right now and i know my user will be! I have a little "tweaking" to do like sorting the company names and so forth but as, for now, I feel like I'm a whole lot closer. I'm sure I will have some questions as i work with this some more but i want to see what I can do myself first.
Thanks again!!
Command Needed
Enviado: 14 Jan 2013 22:42
por rochinha
if you need to tell us. a SCREAM and be alert. For air and onward ...
Command Needed
Enviado: 15 Jan 2013 11:14
por marge0512
Thanks! Well, funny thing though..........in order for me to learn, i changed a couple of things to see what would happen but i changed everything back to the way it was. Now, when the program gets to this line: USE tmpTable EXCLUSIVE, I get an error message that says:
Error DBFNTX/1001 Open Error: tmpTable.dbf (DOS Error 2).
I've researched this error but still don't understand why this is happening.
Command Needed
Enviado: 15 Jan 2013 12:20
por rochinha
Little friend,
See the list of messages
Here
The file is open in other place? the file exist in directory? the path is right?
Use the command,
set default to c:\yoursystem.
Código: Selecionar todos
function main()
set default to c:\system
use tmpFile exclusive
...
return .t.
The problem is that the new drive doesn't have the DOS configuration for the "Too many files are open" error
You must edit %windir%\system32\config.nt and add this line:
Then edit %windir%\system32\autoexec.nt and add a line SET CLIPPER=F100.
It will then run OK.
Good luck
Command Needed
Enviado: 15 Jan 2013 12:45
por marge0512
Thanks! I tried this and rebooted but I am still getting the same error. I don't understand why everything worked for me the first time and then when i started debugging, I get the error. The tmpTable.dbf table does not exist in my directory but wouldn't that table create itself with the
"COPY TO" command? Example: COPY TO tmpTable FIELDS (Compny_Nam) FOR (REC2FIND $ UPPER(Compny_Nam)).
Command Needed
Enviado: 15 Jan 2013 13:46
por alxsts
Hi!
This error message means "File not found". Maybe you have deleted the line that creates the file ("COPY ...") . Check it. If you're not sure, paste the code back from the forum to your program. I think it's not necessary to change any windows setting because the system have been working fine since a long time ago.
marge0512 escreveu:I've been working with this all day and I don't understand it all but I am one happy person right now and i know my user will be!
That's the reason why this forum exists and we also feel happy when someone gets happy...
marge0512 escreveu:I have a little "tweaking" to do like sorting the company names and so forth but as, for now, I feel like I'm a whole lot closer. I'm sure I will have some questions as i work with this some more but i want to see what I can do myself first.
Regarding to the sorted output, I really forgot this detail. I know you want to do it by yourself and here is a tip: it's easy to accomplish this, using another Clipper command that copies records from a table to another, with SORTed output. So, search in the manual.
Keep posting if you need.
Command Needed
Enviado: 15 Jan 2013 13:58
por marge0512
Hi! I double checked and the COPY TO line is still there. I'm wondering if maybe, when i was debugging, that I ended something abruptly when I shouldn't have. That maybe i didn't finish something out to the end??? I do know that i did not finish debugging all of the way and exited because i had received an error message. I do not remember what it was but basically it was telling me that i had the wrong information. I was experimenting and trying to learn. When everything was working right, I tried changing the tmptable's heading at the top which said Compny_Nam. I guess i should have left well enough alone but i wanted to understand.
I did find an aSort command that I'm going to try when I'm "up and running again".
Command Needed
Enviado: 15 Jan 2013 15:18
por alxsts
Hi!
I think you should copy the source code from this forum and paste it back to your project.
I made a mistake in the code.
Please, fix it replacing the line
with
Código: Selecionar todos
DBEDIT(6, 15, 19, 62, {"tmpTable->COMPNY_NAM"} , "_REC_FND_", nil, field_list)
The ASort()
function sorts the elements of an array. Your data is in a table, not in an array. Thus, you must use a
command that sorts rows in a table.