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

How to: Add an array to a report form

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
GB

Sorry if this is easy to some, but I have not had any dealings with this before.

I use the following to create an array which is then shown as a list box on a form:
Code:
DIMENSION MyArray(1)
SELECT field1, field2, field3 FROM MyTable WHERE ;
  CONDITION=mcondition ORDER BY field1 INTO ARRAY MyArray
This works fine but I cannot for the likes of me, find how you get this on to a report.

I have checked the help file (unless I've missed it) without success.

Any guidance or direction would be appreciated.

Thank you

Lee
 

Hi Bill

Thank you for the quick response. By changing this to CURSOR when I try and add this to the form the Data Environment gives two options, Add and Add CursorAdaptor. If I go for the latter I cannot find the one I am looking for.

Could you please explain this process in a bit more details?

Thank you

Lee
 
SELECT field1, field2, field3 FROM MyTable WHERE ;
CONDITION=mcondition ORDER BY field1 INTO Cursor MyCursor

select MyCursor

report form myReport preview to print


This should be enough to print the report

-Batr
 

My apologies, I didn't make this clear. I have a report with fields from a table already on it.

The array is taken from another table which I also want to show on the report. As I mentioned, this works on a form but I'm not sure how to do it on a report.

Lee
 
Lee,

Are you saying you want to show the array as child relations on the report or the actual array values?
If it's child relations, I don't know how you'll do it without using the original MyTable table, not the array.
If it's the array values as displayed on the form, you'll only be able to display one of them referenced by the combo's value.



-Dave Summers-
[cheers]
Even more Fox stuff at:
 

Dave

I am looking to display the child relations. I'm thinking here it would be easier to SELECT FROM etc and put the appropriate data into a temp table and show that on the report.

What do you think?

Lee
 
Lee,

I would create a single cursor that contains all the data you need for the report. The cursor should be denormalised, by which I mean each record should contain the fields for both the parent and child rows. Make it the driving cursor for the report. That way, you won't need the array, and you won't have set any relationships.

Also, you mentioned a temp table. A cursor is, of course, a temp table. In general, there's no reason to creat a "real" table that you only plan to use in the current session, as a cursor serves the same purpose and will be easier to manage.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 

Hi Mike

You beat me to the post (and in fact, it was a piece of code you helped me out with sometime ago, that I have changed to suit)

What I did to resolve the issue was the following:
Code:
tempproj=SYS(3)
SELECT field1, field2, field3 FROM MyTable WHERE ;
  CONDITION=mcondition ;
  ORDER BY field1 INTO TABLE tempproj+'.dbf'

USE tempproj+'.dbf' EXCL
STORE "" TO mdata
STORE "" TO mprojs
SCAN
  STORE TYPECODE+SPACE(4)+PROJECTDES+SPACE(4)+ ;
    DTOC(UPDATED) TO mdata
  mprojs=mprojs+mdata+CHR(13)
ENDSCAN
Within the main table (which is used for the report) was a memo field that is no longer used so what we did was REPLACE it with the variable mprojs
Code:
USE OURTABLE
LOCATE FOR CONDITION=mcondition
REPLACE TMPNOTES WITH mprojs
I added the field name TMPNOTES to the report and now it works.

This may have been a little long winded but I would be grateful if anyone can identify any issues arising out of this procedure.

Thank you

Lee
 
Lee,

Glad to hear you've got it working. The only thing I would add is that you use INTO CURSOR instead of INTO TABLE. (You'd also need to add READWRITE to the INTO CURSOR clause.)

It won't make any difference to the functionality, but it will avoid having to delete the temporary table. Also, it avoids any issues of write-permissions in the target directory.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike's point is that using a cursor instead of a table simplifies things. You then don't have to worry about deleting a file from the disk. You also don't have to worry about where that file is stored or what happens to it if the app crashes before you delete it or if two users or two sessions of your app both try to create it at the same time.

There is almost never a reason to create a new temporary table from within a VFP app. Almost anything you'd want to use a temporary table for, you can use a cursor for more easily.

Tamar
 
The only thing I don't understand is how you get the information from the cursor on a report. It's fairly straight with you add a field from a table but what about from a cursor?

Lee

Windows Vista
Visual FoxPro Versions 6 & 9
 
Lee,
A cursor is a temparily table.
So once you created the cursor by
select * from myTable into Cursor myCursor
than as I wrote before:

select MyCursor
(this selects the cursor in the active workarea)
so you have the temp. table available for your report

report form myReport preview to print
this runs the actual report

-Bart
 
Hi Bart

I think you may be missing my point. I am aware of a cursor but like a table you can add fields to a report so how would you add the fields from a cursor to a report? Is it one of the same?

Lee
 
Lee,

I think you are saying that, with a physical table, you can drag fields onto the report design surface, and also reference them in the expression builder. And perhaps also add the table to the data environment. You want to know how to do that with a cursor. Is that right?

Basically, you can't (other than creating a temporary table at design time merely for the purpose of designing the report). Personally, I don't see that as much of a problem. I just add fields to the report from the toolbar, and type in the field names into the properties box.

Have I understood your question now?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike

That's exactly what I meant. It easy to add field names as you have described I thought there was something I missed when cursors were being mentioned.

Thanks all for your inputs.

Lee

Windows Vista
Visual FoxPro Versions 6 & 9
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top