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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Foxpro interleave program 1

Status
Not open for further replies.

Darknyss

Programmer
Oct 26, 2010
8
US
Is there a freeware or shareware program, or a way to do this with simple command lines that can interleave foxpro records? Say I had a table with 500 records numbered sequentially from 1-500, and I wanted to interleave them 2up. When the program finished the sequence numbers should be 1,251,2,252,3,253...etc. Any help would appreciated, thanks! If you guys can, keep it at basic level stuff, I'm still really new to this. :)
 
When numbers are used as "LETTERS" you must think in 'dictionary' sorting. Example lets sort some 'words'

A
AB
ABC
AC
AD
ADA
ADD

ECT.

Now think the same way with numbers as LETTERS
1
12
123
13
14
15
151
155

Notice the pattern A=1, B=2 etc. The sorting is the same whether it is a LETTER or a number that seen by VFP as a LETTER

You may ask why would one want a dictionary sort of numbers. Well think of an outline of a project say I wanted to number my tasks 1 to 20 and sub tasks 1 to 30 and sub sub tasks 1 to 15. So I might have the number 050327 which means the 5th task, 3rd subtask, and 27 sub sub task. A dictionary sort would allow me to sort everything in order. (OK in the real world I would have 3 fields in my table, but I have seen things like it in the past.)

Lion Crest Software Services
Anthony L. Testi
President
 
"Yes, I was trying to shuffle the data around for printing purposes."

Olaf's suggestions above regarding the use of an Index to make the records appear as desired is BY FAR the best method.

There is no reason to have to physically re-sort the records when all you need it done for is to view in a Grid and/or to Print.

And, if you were to physically re-sort the records, you would likely have to do it repeatedly at other later points in time.

Where if you used the Index method, it would ALWAYS be displayed as desired as long as the Index was active.

Additionally if you need special handling for supporting Printing you probably want to copy just the data for your Report into a Temporary Cursor or Data Table on which you can do the data truncation, etc. and not compromise the original data. If you did this, you would either build the Temp Table in the desired order or (much faster) create an Index on it to display the data as desired.

Good Luck,
JRB-Bldr
 
Something to consider.
I have seen cases were programmers have added a number of indexs to a table for special odds and ends reasons. The results can be that the CDX files as large or in some cases (much) larger then the DBF files, and worse the whole application slows down dealing with these mega index files. Now truth be told this situation is rare and it was on computers with much slower CPUs, Diskdrives, networks etc but I still to this day (maybe to my detrament) sill attempt to keep indexs simple.

Sometimes removing indexs is the best way to speed up an application

Lion Crest Software Services
Anthony L. Testi
President
 
The indices built on a Temp table which are created just to support printing are usually small since they are for that one print job only and then the temp file and its indicies are erased.

Code:
  * --- Get ONLY needed records for printing ---
  SELECT MyTable.*;
    FROM MyTable;
    WHERE <whatever selection criteria>;
    INTO CURSOR RptData READWRITE

  * --- Build Index on Temp Cursor ---
  SELECT RptData
  INDEX ON <whatever> TAG TagKey

  * --- Run Report ---
  SELECT RptData
  GO TOP
  REPORT FORM MyReport NOCONSOLE TO PRINT

  * --- Erase both Cursor & Index ---
  SELECT RptData
  USE

Good Luck,
JRB-Bldr
 
The indices built on a Temp table which are created just to support printing are usually small since they are for that one print job only and then the temp file and its indicies are erased"

I am 100% in agreement with you! (Not that my agreement matters a Rat's %@&^%#@* <smile>. )

Indexes on SELECT Cursor results is a good trick to speed up things without gunking up the actual table. I was not clear in my posting that the 'too many' indexs was meant for tables, not cursors.


Lion Crest Software Services
Anthony L. Testi
President
 
How does it work? By default STR(number) creates a 10 char string. So the index expressions I create actually are fixed width.

The first 10 chars are Mod(Recno()-1,64) transformed to c(10), this is the remains of division by 64 and mainly sorting all numbers of the same remainder together. Within that group of records the order should be by recno(), therefore the second str(recno()).

I actually don't know if you should round mathematical or take floor() or ceiling, it depends what you need. Thinking of printing pages I'd say in the case of two divisions even if you have an odd number of pages you'd add one blank page, so you'd rather use ceiling(), eg also for 511 or 510 or down to 505 I'd take 64 as it's Ceiling(505/8). You may actually pad data by adding 7 blank records then.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top