Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to change the record to record top 2

Status
Not open for further replies.

jezky82

MIS
Jul 7, 2012
39
0
0
ID
how to change the record to the record above, not Positions the record pointer, but move data goto top record
 
Well, that's not how tables or cursors work.

You're rather talking about a user interface feature. There are some options, one is using a Listbox with MoverBars = .T. and you can move records by dragging them.
Drag& Drop is something, which could be programmed for a grid or listbox, but it's much more work than simply setting a property to .T.

Another easy way of resorting is working with two grids and two tables or cursors, the user can select from one and add them to the other in the wanted order.

Bye, Olaf.
 
yes , i want new record in top record,
to append command adding blank record at the end, I would like the addition at the beginning of the record
 
It's still rather a display issue, isn't it?

Add a datetime field tNow, set it's default value to DATETIME(), INDEX ON tNow TAG xNow DESC, SET ORDER TO TAG xNow DESCENDING,

Now APPEND BLANK will physically still add records at the end of the DBF file, but nothing else makes sense. The new records still now display on top position because of the index order in reverse time. That's the way you do that.

Bye, Olaf.
 
You want to insert a new record at the top of the table?

The only way to do that is as follows:

Code:
GO TOP
INSERT BEFORE

and then fill in the fields in the new record.

That will place the new record at the physical top of the table. But do you really want to do that? It's much more usual to add a record to the end of the table, using APPEND BLANK, and then use an index to sort it to the top. It's also much more efficient.

To a certain extent, the physical order of records is unimportant. What matters is the order in which you process them, and that is what indexes are for.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
i can not find syntax insert before , how i can do it
 
It's among the commands for backwards compatibilty only. Mike should be able to answer that, I assume it's really just INSERT BEFORE, standalone, while the table or cursor you want to add a record is the current workarea, same as aPPEND BLANK, just inserting at top.

It's not the preferred solution with tables that grow large, as that means to rewrite the dbf file to add a record as recno 1 and append all other records to it. Doing that on a 10MB DBF means reading 10MB, writing 1 record+10MB = about 20 MB network traffic, if the DBF is on a network share. That's - let's say - not amusing in multi user environments.

Bye, Olaf.
 
The syntax is just as I showed it: [tt]INSERT BEFORE[/tt] - nothing more or less. But, as Olaf said, it's a "backward compatibility" command, so ideally you won't use it. In fact, the whole concept of physically inserting a record in a given position within the table is démodé.

As we have both said already, better to [tt]APPEND BLANK[/tt], and use an index to ensure that the record appears at the top of the table.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi jezkey82

INSERT adds records to the current table at the current record pointer position. INSERT is almost always a bad idea. This command is part of FoxPro's Xbase legacy and generally leads to bad code. In all our experience, we've only found one situation where using INSERT was a good idea — more on that below.

Don't confuse this INSERT command with the SQL INSERT command, which is very useful.

Usage
INSERT [ BLANK ] [ BEFORE ]

Used by itself, INSERT is much like APPEND by itself, but requires exclusive access. It adds a record and brings up an EDIT-type window to fill in the fields. The fly in the ointment is that the new record is physically inserted immediately following the current record. This means that every record following that position has to be physically moved to make room. On a large table, INSERT is a spectacularly bad choice.

Adding the BLANK keyword is like using the BLANK keyword of APPEND. The new record is added behind the scenes and there's no interaction.

The BEFORE keyword indicates that the new record should precede rather than follow the current record.

If the table has any open indexes (even if order is set to 0), the new record is added at the end, whether or not you specify BEFORE. This actually makes it a better command than it is otherwise, but also makes it obsolete since you can do the same thing with APPEND.

INSERT can't be used with most of the cool stuff in Visual FoxPro. You can't INSERT in a buffered table, or in one that has rules, triggers, primary keys or candidate keys.

INSERT respects SET CARRY, bringing forward values from specified fields when CARRY is ON.

So, what about the one time we've found INSERT useful? The situation was a very small table (never more than a couple of hundred records), which was to be copied out to an SDF file, from which it would be sent to the printer. The record order was essential to the reporting process. Because the result might be more than one page, we needed to insert a record containing a page feed character after every 54 records. INSERT was just the ticket. The moral, though, is the situation has to be pretty unusual before it's worth using INSERT."

from Hacker's Guide to Visual Foxpro 7.0

Furthermore this command ranges among those classified as "COMMANDS NEVER TO USE"

I'd guess you stick to Olaf's suggestion.

hth

MarK
 
Mark,

Reading that extract from Hackfox reminds me that INSERT takes a BLANK clause, just like APPEND. That's useful to know, becuase it avoids having an Edit window pop up. (But it does not change the fact that it's a deprecated command.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
yes , i want new record in top record,

You are putting your attention on the wrong thing.

As Olaf has said: It's still rather a display issue, isn't it?

The sequence that the actual records exist within the cursor/table should be of NO CONSEQUENCE.

You get them to be DISPLAYED in a specific sequence by using an Index on the original cursor/table or by using a SQL Query to acquire records in a specific order such as for use in a Report, etc.

So, your focus should be on getting the new record to APPEAR at the top of the display/grid - not on physically residing as the first record in the table.

So if you want the cursor/data table itself to DISPLAY the records in a specific order such that the newest record(s) appear at the top, then you would follow Olaf's suggestion and create an Index on the cursor/data table such as:
* Add a DateTime field tNow to the table in question
* REPLACE ALL tNow WITH DATETIME() FOR EMPTY(tNow)
* INDEX ON tNow TAG xNow DESC
* SET ORDER TO xNow

Also note that as new records are added the new field (tNow) would need to be populated with DATETIME() so that the Index would make it APPEAR at the top - ahead of other records whose tNow values were lower.

Or, if you were acquiring specific records from the table into a specific sequence you would again add the new suggested field and then run a SQL Query - something like:
SELECT *;
FROM MyTable;
WHERE <whatever selection criteria needed>;
ORDER BY tNow DESC;
INTO CURSOR TheseResults READWRITE

Good Luck,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top