IMPORTANT ANNOUNCEMENT

These forums were permanently set to read-only mode on July 20, 2022. From that day onwards, no new posting or comment is allowed on the site, but the historical content remains intact and searchable.

A new location for posting questions about PlanetPress Suite is now available:

OL Learn - PlanetPress Classic (opens in new tab)

Page 1 of 2 1 2 >
Topic Options
#49670 - 10/09/14 08:20 PM adding a column
FormMaster Offline
OL Expert

Registered: 05/12/03
Posts: 193
Loc: Los Angeles
Hi,

Believe it or not, I have been working on forms for 8 years and have NEVER had to add (sum) a column of numbers. What is the easiest way to do this?

I have a column of numbers that runs from line 23 to 33, and within columns 4-6.

Thank you.

Top
#49676 - 10/10/14 03:04 AM Re: adding a column [Re: FormMaster]
Dal Offline
OL Guru

Registered: 08/29/08
Posts: 114
Loc: UK
Create a presstalk object and write this in it:
Code:
Define(&total, integer, 0)

&current.line:= 23
Repeat()
    &total:= &total + strtoint(@(&current.line,4,6))
Until(&current.line = 33)

Show(inttostr(&total))

Top
#49682 - 10/10/14 10:03 AM Re: adding a column [Re: FormMaster]
FormMaster Offline
OL Expert

Registered: 05/12/03
Posts: 193
Loc: Los Angeles
Thank you Dal. I will give this a try!

Top
#49683 - 10/10/14 10:14 AM Re: adding a column [Re: FormMaster]
FormMaster Offline
OL Expert

Registered: 05/12/03
Posts: 193
Loc: Los Angeles
Hmmm. I tried this, but I get a "string too long" error.


Edited by FormMaster (10/10/14 10:14 AM)

Top
#49684 - 10/10/14 10:24 AM Re: adding a column [Re: FormMaster]
jim3108 Offline
OL Expert

Registered: 04/19/10
Posts: 316
Loc: London, UK
"Loop too long" means you have a never-ending loop - the control variable is never incremented.

Add &current.line := &current.line + 1 in the loop.

Like this:

Code:
Define(&total, integer, 0)

&current.line:= 23
Repeat()
    &total:= &total + strtoint(@(&current.line,4,6))
    &current.line := &current.line + 1
Until(&current.line = 33)

Show(inttostr(&total))

Given that you have specified line range, I would probably use a For loop here...
Code:
Define(&total, integer, 0)

for(&current.line, 23, 1, 33)
    &total:= &total + strtoint(@(&current.line,4,6))
endfor()

Show(inttostr(&total))

For loops automatically increment the control variable so remove the susceptibility to forget it.


Edited by jim3108 (10/10/14 10:32 AM)
Edit Reason: Why do I need a reason?

Top
#49685 - 10/10/14 10:52 AM Re: adding a column [Re: FormMaster]
FormMaster Offline
OL Expert

Registered: 05/12/03
Posts: 193
Loc: Los Angeles
James,

This works correctly except it is only picking up the 3 digit numbers.

We're watching columns 4-6, but the data might be 1, 2, or 3 digits long - like this:

..2
..5
.10
105
..4
115

(the dots are empty space)

So right now, it's giving me a total of 220. it's only seeing the 3 digit numbers.

How do we make PP see all the numbers?

Thanks.


Edited by FormMaster (10/10/14 11:03 AM)

Top
#49686 - 10/10/14 11:18 AM Re: adding a column [Re: FormMaster]
jim3108 Offline
OL Expert

Registered: 04/19/10
Posts: 316
Loc: London, UK
OK. If the dots are empty space it should convert to the integer correctly.

If they were dots it would need to be:
Code:
Define(&total, integer, 0)

for(&current.line, 23, 1, 33)
    &total:= &total + strtoint(strip('.',@(&current.line,4,6)))
endfor()

Show(inttostr(&total))

Try trimming the selection before we convert:
Code:
Define(&total, integer, 0)

for(&current.line, 23, 1, 33)
    &total:= &total + strtoint(trim(@(&current.line,4,6)))
endfor()

Show(inttostr(&total))

Is it at all possible that there is another character in the empty spaces?


Edited by jim3108 (10/10/14 11:23 AM)
Edit Reason: Why do I need a reason?

Top
#49687 - 10/10/14 11:31 AM Re: adding a column [Re: FormMaster]
jim3108 Offline
OL Expert

Registered: 04/19/10
Posts: 316
Loc: London, UK
I have just tested this and it works.



That is not to say that you aren't still having problems so let's look a little closer.

Can you send me your data file?


Edited by jim3108 (10/10/14 11:35 AM)
Edit Reason: Why do I need a reason?

Top
#49691 - 10/10/14 12:01 PM Re: adding a column [Re: FormMaster]
FormMaster Offline
OL Expert

Registered: 05/12/03
Posts: 193
Loc: Los Angeles
This is the strangest thing. I'm not getting any compile errors, but the box on the form is simply blank. Not even a zero.

Am I missing something? Do I need to do anything else beside create a PP object and place it on the form with the above code?

Yes. I will send the data file. Thank you.


Edited by FormMaster (10/10/14 12:05 PM)

Top
#49692 - 10/10/14 12:04 PM Re: adding a column [Re: FormMaster]
jim3108 Offline
OL Expert

Registered: 04/19/10
Posts: 316
Loc: London, UK
Ok let's go from the start.

Simple document

* Sample data - ASCII (or Line Printer)
* Page 1 - Normal Page
-> on page 1, place PressTalk object.
-> in PT object, paste my last code example.

What do we get on page?

PS: We are working with ASCII text here aren't we?

Top
Page 1 of 2 1 2 >