Anuviel Posted June 28, 2007 Posted June 28, 2007 I looked but was not able to find it, if it is out there would someone point me to it or tell me how would this be accomplished? I would like a field that would count/show if a button was pressed? For example: Print button for invoices. When it is pressed it would print the invoice and insert words "printed 1" into the field next to it. If it is pressed again it would insert "Printed 2". I am looking to writing a script that once the button is pressed: Prints the invoice Checks to see if the field next to it has anything inside If it does not then it inserts Printed 1 If it has Printed # inside already it would increase the value Am I going in the right direction here? If I am I could use a hint as to how to get the script to recognize what information, if any, is already inside the field and increase it accordingly. Thanks.,
LaRetta Posted June 28, 2007 Posted June 28, 2007 You could have a number field called Printed. Each time it is printed (via script), your print script would add this script step at the end: Set Field [ Printed ; Printed + 1 ] LaRetta :wink2:
Anuviel Posted June 28, 2007 Author Posted June 28, 2007 Thanks for pointing me in the right direction. I got it with "insert calculated result" As calc I put: "Printed" & Test2::Print_count + 1
LaRetta Posted June 28, 2007 Posted June 28, 2007 It is better to use Set Field [] rather than Insert Calculated Result [ ]. With Insert Calculated Result [ ] , the field must ALWAYS be on the layout; Set Field [ ] has no such limitation. And yes, your Printed field can be text. But, for it to also include the words 'printed' then you can't append to it unless you combine text function with mathematics. Try: Case ( IsEmpty ( yourTable::Printed ) ; "Printed " ) & LeftWords ( yourTable::Printed ; 1 ) & " " & RightWords ( yourTable::Printed ; 1 ) + 1 Truly, it is better the leave the word 'Printed' out of the field and just have it be the text label. LaRetta
Anuviel Posted June 28, 2007 Author Posted June 28, 2007 Thanks., will use set field instead then. Did not know of the limitations as you mentioned - I am still quite new to FM and I pretty much know that the stuff I make probably has a better way of being done then how I made it however I am pretty much self-learn type of a person. I will also set printed as a separate field then as I want the word not being visible until the invoice is printed at least once. It will trigger the first time the button is pressed. By the way how would I be able to detect if someone canceled the print dialog and then have the script clear the fields if it was canceled?
David Jondreau Posted June 28, 2007 Posted June 28, 2007 Immediately after your Print script step, add Set Variable[$print; Get(LastError)] If the user cancels printing, Get(lastError) returns a 1, if printing is fine, a 0. You then add an error trap: If[$print] #What result you want if printing isn't successful Else #what you want if printing is sucessful End If
LaRetta Posted June 28, 2007 Posted June 28, 2007 I will also set printed as a separate field then as I want the word not being visible until the invoice is printed at least once. It will trigger the first time the button is pressed. There is no need to use a separate field for the word printed. Either place the field name on the form or leave the calculation as I had it. The word 'printed' will not appear in the field until it is printed at least once anyway. It would be a shame to waste another field just to hold one word that you set via script (which would also need to then be cleared). By the way how would I be able to detect if someone canceled the print dialog and then have the script clear the fields if it was canceled? Again, no need to clear the field; simply don't set the number (or increment it up) until after the print is successful. And I see no reason to use a variable. Here's one way it can work: Set Error Capture [ On ] Print [ ] If [ Get ( LastError ) ] Exit Script Else Set Field [ Printed ; Case ( IsEmpty ( yourTable::Printed ) ; "Printed " ) & LeftWords ( yourTable::Printed ; 1 ) & " " & RightWords ( yourTable::Printed ; 1 ) + 1 ] End If LaRetta :wink2:
comment Posted June 28, 2007 Posted June 28, 2007 Case ( IsEmpty ( yourTable::Printed ) ; "Printed " ) & LeftWords ( yourTable::Printed ; 1 ) & " " & RightWords ( yourTable::Printed ; 1 ) + 1 If it were me, I'd put in a list of timestamps (or users and timestamps) to keep a log of who printed when. But to get the result above, you could do: Case ( IsEmpty ( PrintLog ) ; "Printed 1" ; SerialIncrement ( PrintLog ; 1 ) ) or just: SerialIncrement ( "Printed 1" ; PrintLog )
Genx Posted June 28, 2007 Posted June 28, 2007 Interesting Michael, this is another one of those functions i've never really seen used before.. Cheers.
LaRetta Posted June 28, 2007 Posted June 28, 2007 (edited) Now this is very cool, Michael! I shall steal it! I can already see thousands of great uses for it. BTW, I considered mentioning a log (or even table) but I got lazy. Thanks for covering it. Edited June 28, 2007 by Guest
Raybaudi Posted June 28, 2007 Posted June 28, 2007 or just: SerialIncrement ( "Printed 1" ; PrintLog ) Stolen ! ( stored )
Anuviel Posted June 29, 2007 Author Posted June 29, 2007 WoW, thanks, a lot of good information here, will right that down for future reference and learn from it. Thanks.
Recommended Posts
This topic is 6418 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now