[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Poco Forums • View topic - Mathematical operations and script help please

Mathematical operations and script help please

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Mathematical operations and script help please

Postby mezzers » Thu Nov 13, 2008 2:50 am

Hi all, I just turned my husband onto Pocomail and we're wondering if there's a way to automate parts of an email he regularly sends to our three employees. What it needs to do is pretty simple:

1) Open a new email
2) Select from a list of three email addresses for the To: line
3) Insert a subject which changes with the name of the job
4) Take a number provided and multiply it by .20, then add the result to the original number and insert both figures into the email body -- something like:

The estimated folios for this job are {folios}. Please ensure you don't type more than {folios X .20 + folios} folios without first letting me know.

5) Leave the email open for further editing.

From looking around here and in Poco's scripts I've come up with the barebones of the code I think is needed, but I'm stuck on how to use variables and get this working.

Code: Select all
CreateMessage %m
InputBox $userdata1 "Choose recipient...%var%" "email addy1|email addy2|email addy3"[/i] (Addys scrubbed for posting here)
[i]InputBox $userdata2 "Subject (type over):" "CASE NAME"
InputBox $userdata3 "Enter estimated folios (type over):" 50
AppendBody $msg $userdata3
Set $userdata3 #a
Set #b .20
Multiply #a #b

EditMessage %m
exit


Any help would be wonderful, thanks.

/Mez
mezzers
Poco Tourist
 
Posts: 16
Joined: Fri Mar 25, 2005 5:35 pm
Location: Florida

Postby MarkB » Fri Nov 14, 2008 12:27 am

Here is a working version of your script. The error handler is just to help you debug when you make refinements. Please note that the arithmetic in PocoScript is integer arithmetic.

Code: Select all
Set $OnErrorGoTo "ErrorHandler"

InputBox $toaddress "Recipient:%var%" "ann@xxxxx.xxx|ben@yyyyyy.yyy|chuck@zzzzzz.zzz"
InputBox $subject "Subject (case name):"
InputBox $nfolios "Number of folios:"
Set #nfolios $nfolios
Set #result #nfolios
Divide #result 5
AddIntegers #result #nfolios
CreateMessage %m
AddTo %m $toaddress
AddHeader %m "Subject:" $subject
Set $t ""
AddStrings $t "The estimated folios for this job are " #nfolios ". Please ensure you don't type more than " #result " folios without first letting me know."
AssignBody %m $t
EditMessage %m
Exit

:ErrorHandler
Set $t ""
AddStrings $t "Error: " $ErrorResult "\n"
AddStrings $t "Line " #ErrorLine ": " $ErrorLine
MessageBox $t
Exit
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby MarkB » Fri Nov 14, 2008 1:52 am

Same thing, but with one DialogBox replacing three InputBoxes.

Code: Select all
Set $OnErrorGoTo "ErrorHandler"

Set &address1 0
Set &address2 0
Set &address3 0
DialogBox $PocoScriptName "To" "Ann" &address1 "Ben" &address2 "Chuck" &address3 "Subject" $subject "Number of folios" #nfolios
If &address1 Then Address1
If &address2 Then Address2
If &address3 Then Address3
MessageBox "Please select an address"
Exit
:Address1
Set $toaddress "ann@xxxx.xxx"
Goto ComposeMessage
:Address2
Set $toaddress "ben@yyyyyyy.yyy"
Goto ComposeMessage
:Address3
Set $toaddress "chuck@zzz.zzz"
Goto ComposeMessage

:ComposeMessage
Set #result #nfolios
Divide #result 5
AddIntegers #result #nfolios
CreateMessage %m
AddTo %m $toaddress
AddHeader %m "Subject:" $subject
Set $t ""
AddStrings $t "The estimated folios for this job are " #nfolios ". Please ensure you don't type more than " #result " folios without first letting me know."
AssignBody %m $t
EditMessage %m
Exit

:ErrorHandler
Set $t ""
AddStrings $t "Error: " $ErrorResult "\n"
AddStrings $t "Line " #ErrorLine ": " $ErrorLine
MessageBox $t
Exit
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby mezzers » Fri Nov 14, 2008 8:34 am

Mark, these are brilliant! The one that handles everything with one input box is especially good, I had no idea pocoscript was capable of that.

I really appreciate your time and help...and the material to study so I can learn to write scripts myself.

Thank you! :D

/Mez
mezzers
Poco Tourist
 
Posts: 16
Joined: Fri Mar 25, 2005 5:35 pm
Location: Florida

Postby MarkB » Fri Nov 14, 2008 9:37 am

Thanks.

Two things. First, a reminder that addresses can be in this form rather than bare-bones:
Code: Select all
Set $toaddress "Anne Boleyn <anne@xxxx.xxx>"


Second, please add these two lines near the beginning of the second script in case the user ever leaves those items blank:
Code: Select all
Set $subject ""
Set #nfolios 0
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby mezzers » Fri Nov 14, 2008 10:09 am

MarkB wrote:Thanks.

Two things. First, a reminder that addresses can be in this form rather than bare-bones:
Code: Select all
Set $toaddress "Anne Boleyn <anne@xxxx.xxx>"


I'll remember, I've bookmarked this thread for future reference.

Second, please add these two lines near the beginning of the second script in case the user ever leaves those items blank:
Code: Select all
Set $subject ""
Set #nfolios 0


These are so the script doesn't bomb if either is left blank, right? Done.

I've been playing with both scripts and have learned a lot from them already. Thanks again for your help!

/Mez
mezzers
Poco Tourist
 
Posts: 16
Joined: Fri Mar 25, 2005 5:35 pm
Location: Florida

Postby MarkB » Fri Nov 14, 2008 11:25 am

Yes. A quirk in DialogBox is that it doesn't define the variable when input is blank. Reference (later) to an undefined variable can be a crash-causing error.

PocoScript always rounds down, it seems. 15 divided by 4 = 3. If you need better rounding, you will have to fake it. ((15*10)/4 + 5)/10 = 4. But I'm no mathematician.
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby mezzers » Fri Nov 14, 2008 11:46 am

MarkB wrote:PocoScript always rounds down, it seems. 15 divided by 4 = 3. If you need better rounding, you will have to fake it. ((15*10)/4 + 5)/10 = 4. But I'm no mathematician.


Interesting, we'll have to see how that affects things. We transcribe court hearings and the reason we stop our employees from typing more than 20% over the estimated folios is because we like to get approval for the extra cost. Otherwise we have angry customers calling to ask why their job cost double or whatever we estimated, and we wind up eating the difference. :(

It may just be easier to warn my husband that PocoScript rounds down. If a transcriber comes back saying they're about to go 20% over the estimated folios he always check with them to see how much of the job is actually left anyway.

Off to watch the shuttle launch!

/Mez
mezzers
Poco Tourist
 
Posts: 16
Joined: Fri Mar 25, 2005 5:35 pm
Location: Florida

Postby MarkB » Sat Nov 15, 2008 1:55 am

It may just be easier to warn my husband that PocoScript rounds down.


OK, that's been bothering me. If you replace these lines (from the second script)

Code: Select all
Set #result #nfolios
Divide #result 5
AddIntegers #result #nfolios


with these

Code: Select all
Set #result #nfolios
Multiply #result 12
AddIntegers #result 5
Divide #result 10


that should give you conventional rounding.
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby mezzers » Sat Nov 15, 2008 10:56 am

That works perfectly now, thanks. I thought you weren't a mathematician? :wink:

/Mez
mezzers
Poco Tourist
 
Posts: 16
Joined: Fri Mar 25, 2005 5:35 pm
Location: Florida


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 0 guests

cron