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)

Topic Options
#33095 - 08/23/10 09:13 PM Add number in PP7 design
vincent Lam Offline
OL Newbie

Registered: 02/16/09
Posts: 15
I want to design a inovice using PP7 design. When a user print the invoice, a invoice number "INXXXXXX" will be printed in the invoice. Each time a user print this invoice, the invoice number will be added by 1 automatically. No such attribue can be found in the database.Can I use PP7 do that?If yes, how to do it?

Thanks.

Top
#33103 - 08/24/10 09:28 AM Re: Add number in PP7 design [Re: vincent Lam]
Raphael Lalonde Lefebvre Offline
OL Expert

Registered: 10/14/05
Posts: 4956
Loc: Objectif Lune Montreal
Vincent,

While PlanetPress itself cannot keep a count in memory permanently, it is doable through the use of a vbscript and the exexscriptfile command. Create a global variable of type integer, and for this example, let's call it "MyNumber". Then, in the PressTalk Before of the page where you need to get a new number, add this line:

&MyNumber := execscriptfile('C:\\getcounter.vbs', '', 0)

This will load a getcounter.vbs vbscript file, which will return a new number, and keep track of the counter in a text file. Here's an example of what the code could look like for that vbs:

Code:
dim FSO
dim SavedNumber
dim i
dim newnumber

set FSO = CreateObject("Scripting.FileSystemObject")

set SavedNumber = FSO.OpenTextFile("C:\number.txt", 1)

i = SavedNumber.ReadLine()

SavedNumber.Close

newnumber = CInt(i) + 1

set SavedNumber = FSO.OpenTextFile("C:\number.txt", 2)

SavedNumber.WriteLine(CStr(newnumber))

SavedNumber.Close

Script.ReturnValue = newnumber


This assumes that you've created a "number.txt" file, and that you've typed 0 on it's first line(or whatever number you want to initialize it at). Everytime the page is executed, this will return an integer number that keeps increasing, so you can use that to create the invoice number that you want.

The drawback to this method is that during design time, the script will be executed several times everytimes you click on the page, causing the counter to keep increasing. So, before putting this into production, make sure you reset the counter to the value that you need.

Hope that helps!

Regards,
Raphaël Lalonde Lefebvre


Edited by Raphael Lalonde Lefebvre (03/20/13 09:48 AM)
Edit Reason: Realized just now that I misnamed one of the variables.

Top
#33112 - 08/25/10 03:02 AM Re: Add number in PP7 design [Re: Raphael Lalonde Lefebvre]
vincent Lam Offline
OL Newbie

Registered: 02/16/09
Posts: 15
When &MyNumber := execscriptfile('C:\\getcounter.vbs', '', 0) is typed in PressTalk Before, an error message "Unknown variable Mynumber is prompt.

Top
#33115 - 08/25/10 09:26 AM Re: Add number in PP7 design [Re: vincent Lam]
Raphael Lalonde Lefebvre Offline
OL Expert

Registered: 10/14/05
Posts: 4956
Loc: Objectif Lune Montreal
Did you actually create the MyNumber variable in the global variables? You need to create it there, as an Integer variable.

Go in the Document Structure panel, right-click on Global variables, and select "Global Variable". This will create a new variable. Give it the name you want(in this case, MyNumber) and change it's type to Integer. Click OK.

You now have created the variable, and the code I gave you should work.

Regards,
Raphaël Lalonde Lefevre

Top
#33117 - 08/25/10 11:28 AM Re: Add number in PP7 design [Re: Raphael Lalonde Lefebvre]
vincent Lam Offline
OL Newbie

Registered: 02/16/09
Posts: 15
Actually, MyCounter and MyNumber are created in Global variables as integer variable already. When &MyNumber := execscriptfile('C:\\getcounter.vbs', '', 0) is typed in PressTalk Before, an error message "Unknown variable Mynumber is prompt. i don't know why it happens.

Top
#33118 - 08/25/10 11:39 AM Re: Add number in PP7 design [Re: vincent Lam]
Raphael Lalonde Lefebvre Offline
OL Expert

Registered: 10/14/05
Posts: 4956
Loc: Objectif Lune Montreal
I've just tried it, and it works fine, I didn't get any errors. Try maybe starting from scratch, and recreate the variable, and then retype the execscriptfile command.

I've uploaded an example on FTP(will remain last for 3 days):
Host : ftp.ca.objectiflune.com
Folder : app-ftp-users/OL25/
Username : OL25
Password : VzAmArZB

This form should work fine.

Regards,
Raphaël Lalonde Lefebvre

Top