Creating A Report From Listbox Contents??

Hi,

I was wondering if it was possible to use Xojo Reports to create a report that loads the contents of a Listbox? I have been searching the web and have not found anything that indicates you can do that.

OR… simply load my code that loads into the listbox into the report as well and then display it and print it. Basically my code searches the records between two dates in a sqlite database, does a few calculations and then sticks all the data it finds into the listbox. I would just like to stick all the same data into a report, and I can’t find any examples that do this. My code for the listbox is listed below.

[code] //Loads Member Names
Dim sqlMembers as string
sqlMembers=“SELECT * FROM Members”
ls=Roster.SQLSelect(sqlMembers)

While Not ls.eof

//Make sure member is not already listed
Dim sqlook as String

txtName.Text =(ls.Field("Members").StringValue)

sqlook="SELECT * FROM MeetingAT WHERE Date Between  '" + (txtDate1.Text) + "' And   '" + (txtDate2.Text) + "' And UPPER(Member) = '" + uppercase(txtName.Text) + "'"

rs=Roster.SQLSelect(sqlook)
txtMeetings.Text= format(rs.RecordCount,"0")

List2.AddRow

List2.Cell(List2.LastIndex,0)=txtName.Text
List2.Cell(List2.LastIndex,1)=txtMeetings.Text

//Calculate Percentage

Dim P as Integer
Dim T as Integer
Dim S as Integer
Dim M as Integer

T=Val(txtTotal.Text)
S=Val(txtMeetings.Text)

M = T - S

P = 100 / (M + S) * S

txtPercentage.Text=format(P,"0")
txtMissed.Text=format(M, "0")

List2.Cell(List2.LastIndex, 2)= txtPercentage.Text + "%"
List2.Cell(List2.LastIndex, 3)= txtMissed.Text

ls.MoveNext

wend [/code]

I have created a report with textfields that would correspond with the cells in the listbox. I just don’t know how to get that data actually into the report or if in fact that is possible. Any suggestions would be greatly appreciated.

Jim

James, e-mail me at “harriew at frontiernet dot net” and I will send you a project that creates a report using the data that exists in a listbox. It includes a good explanation of how the code is laid out. I have had a number of people request a copy of it from the NUG Digest. It also includes a sample file that will fill the listbox so you can see the generated report. I hope autocorrection doesn’t modify the e-mail address when I click the Post button.

Might be worth looking at Ben’s Listbox Extra’s http://www.benandruby.com/bens_software/RBstuff.html

Hi Harrie and Bob,

Thank you very much for taking the time to help me.

Harrie, I sent my email to you. I would like to see that project, and I appreciate you sending it to me. I think creating a report from a listbox is the way to go.

Bob, I did find Ben’s Listbox Extras a couple days ago, and it basically prints out a sort of low resolution picture of the listbox. I don’t know if that would work so well for what I wanted to do.

I was also thinking of another way to do this.

The Sqlite query populates the Listbox, which fills the listbox with data row by row. But what if you saved each row of data as a sql record in a new table with each column representing a column in the listbox. Then send that table data back to the report. I think that would work, but it just might really slow the app down too much, which I don’t want to do.

It would be better if I could connect each row of data in the listbox to a report directly. That would be great if Harrie’s project can do that.

Again, thank you for all your help.

I got three e-mails requesting the sample project along with the explanation of how it was done; however, I didn’t see the name James Redway in any of those. Saw a Jim, which could have been you. If you didn’t get it, fire off another e-mail. Don’t know how I would have missed it but I have been known to screw up on occasion. :wink:

Also:

[quote] //Loads Member Names
Dim sqlMembers as string
sqlMembers=“SELECT * FROM Members”
ls=Roster.SQLSelect(sqlMembers)

While Not ls.eof

//Make sure member is not already listed
Dim sqlook as String

txtName.Text =(ls.Field("Members").StringValue)

sqlook="SELECT * FROM MeetingAT WHERE Date Between  '" + (txtDate1.Text) + "' And   '" + (txtDate2.Text) + "' And UPPER(Member) = '" + uppercase(txtName.Text) + "'"

rs=Roster.SQLSelect(sqlook)

[/quote]

Don’t do this…You’ll run into performance problems with doing SQLSelects in a loop like this. Retrieve all MeetingAT-records in a single Select in the correct order, and display the data only then.

Creating A Report From Listbox Contents??

To do that, you need to write the usual printing stuff and put in there:

a loop that read each ListBox Row (use LB.ListCount - 1 as the loop index),
have a Vertical (Integer) counter to print the lines
have a line height step value
set a number of lines to print (Page Height / Line Height = # of lines to print).
have a page number (Integer)

Print the ListBox contents one Row at a time;
in fact, you will use a bunch of Tab variables
print each Cell using its own Tab value, alignment, etc.
if you have an image to print for each “line”, do not forget to take that height value as the line step value

reset the Y value (to the top of page value) when all lines for that page have been printed
increment the page number

If you want to print a header you have to:
Make a line to be sure that header will be printed once per page
print your header (better do it in a different Method
Change the default Y value to skip the header height
Print your header odd / even (for example)

For a footer, apply the header way of coding, using Page Height -

You know how to print string left aligned, centered and right aligned
Centered: (Page Width - length of the string to print) / 2
Right Alignment: Page Width - length of the string to print

You use the Graphics Methods and Properties to print the text / images.
Use a large enough (but not too large) font / size combination.

It is that simple.

Ask if you do not understand something (if I was as dark as my name imply !).

For anyone interested in the example project that I mentioned above dated 6 Sep 2013, my e-mail address is changing to

harriepw at gmail dot com

Still get the occasional request for the code, last one just today and figured that JUST IN CASE, I should put my new e-mail out there and hope the reader reads down to this point.

[quote=340204:@Harrie Westphal]For anyone interested in the example project that I mentioned above dated 6 Sep 2013, my e-mail address is changing to

harriepw at gmail dot com

Still get the occasional request for the code, last one just today and figured that JUST IN CASE, I should put my new e-mail out there and hope the reader reads down to this point.[/quote]

or just post the code somewhere that folks can grab it for the long haul ?