Jump to content

Question on Sub-Scripts


This topic is 7248 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hey All!

As some of you may already know, I have numerous print scripts. Each scripts searches the database for certain qualities, and omits those that don't match the criteria of the script. I have combined all of these scripts (about 34 total) into one big script that executes them all as sub-scripts. I am pretty sure that all of the scripts work if they are run independently, but I am concerned that some processes might have been left out because of how close they are executed.

Should I, and how often should I include pause steps? Are there other procedures that I should perform before executing all of these subscripts?

Thanks for all of your help!

Ken

Link to comment
Share on other sites

Filemaker will completely finish one process before moving on to another. There is really no need for pauses for Filemaker's sake.

For developmnent (and sanity) I try to limit any one script to no more than 20 lines or so. You might need to rearchitect your scripts a bit to make diagnosis problems easier.

Also make sure that you eliminate any redundant script steps, combine them into small utility scripts instead.

Link to comment
Share on other sites

Yeah, I think there's just something wrong with my scripts, but I can't figure it out...here's the script:

Go to Layout [certain layout]

Go to Record/Request/Page [First]

Loop

If ["(PatternCount(Action List, "Appointment Obtained")) and (Status(CurrentDate) >= Appointment on - 4) and (IsEmpty(Letters2.3)]

Set Field ["Letters2.3","Appt. Reminder""]

Insert Current Date [select, "Letters P Date 2.3"]

Go to Record/Request/Page [Exit after last, Next]

Else

If ["Status (CurrentRecordNumber) = Status(CurrentFoundCount)

Omit Record

Exit Loop If ["1"]

Else

Omit Record

End If

End If

End Loop

Go to Layout ["Appointment Reminder Notice"]

Page Setup [Restore, No dialog]

Enter Preview Mode [ ]

Print [No dialog]

Enter Browse Mode

Show All Records

Whats happening is that its only printing out 1 record of the found set. I put a pause script step before the print step, and the three records showed up in the found set (as they are suppose to). However, when I continued the script, it would only print one record. Whats that all about? Am I missing a go to record step or something?

Thanks for all your help! If you have any further questions on this, post them here and I will answer them ASAP.

Link to comment
Share on other sites

Oh, and one more thing....

You know how when it is about to print, and that splash screen comes up very quickly and says "Now Printing Page (#)?" Usually if there is more than one record spooled, the (#) will count off the number of papers it is printing. When running this script, it will not count off.

I don't know if that info helps you or confuses you, but if it confuses you, forget I even mentioned it!!

Ken

Link to comment
Share on other sites

Wow that was alot of problems. You were making this way more complicated than I think that it needed to be. Here is a cleaned up version:

code:


Go to Layout [certain layout]

Go to Record/Request/Page [First]

Loop

If ["(PatternCount(Action List, "Appointment Obtained")) and (Status(CurrentDate) >= Appointment on - 4) and (IsEmpty(Letters2.3)]

Set Field ["Letters2.3","Appt. Reminder""]

Set Field ["Letters P Date 2.3", "Status ( CurrentDate )"]

Else

Omit Record

End If

Go to Record/Request/Page [Exit after last, Next]

End Loop

Go to Layout ["Appointment Reminder Notice"]

Page Setup [Restore, No dialog]

Enter Preview Mode [Pause]

Print []

Enter Browse Mode

Show All Records


I removed your complicated nested IF, multiple Omit, Exit Loop clauses since they were likely screwing you up. I generally start by writing my loop in English or as much pseudo-code as is possible and make sure that it does what I want on paper first, then I start coding. Too often when actually coding you cannot see the forest for the trees.

Link to comment
Share on other sites

Well, actually I'll take the blame for the complicated loop. I think it was mostly my idea in order to avoid the problem of skipping a record after the previous one was omitted. I later remembered that the clean way to handle this is to start at the last record and then loop backwards with a "Go to Record/Request[previous][exit after last]" step. This keeps the loop simple and avoids skipping records.

Link to comment
Share on other sites

quote:

Originally posted by kenneth2k1:

Whats happening is that its only printing out 1 record of the found set. I put a pause script step before the print step, and the three records showed up in the found set (as they are suppose to). However, when I continued the script, it would only print one record. Whats that all about? Am I missing a go to record step or something?


Show Dialog when calling the Print script step. Run the script; when the Print dialog box comes up, double-check to make sure Records Being Browsed is checked, and Current Record is unchecked.

Hope this helps!

Link to comment
Share on other sites

Thanks all for your effort and help.

Yes, I used to have scripts constructed like that CaptKurt, but for some reason they would not work properly. I will describe my setup:

The above script is executed on a database of 10 records. Of the 10, only three records qualify and should be filtered out by the script (meaning, these three records all have "Appointment Obtained" in a field called Action List; today's date is four days prior to the date set in the record's field "Appointment On"; and the field Letters2.3 is empty).

Kurt, I went back and made the script that you wrote out, but when I tested it, it did not work right. Oddly, it marked the proper records correctly (meaning, the field "Letters2.3" was set to "Appt. Reminder", and the current date was entered in field "Letters P Date 2.3" on the three records). However, SIX records printed - the three that were suppose to print, and three that did not match the query at all. I recall having this problem before BobWeaver showed me the extra step:

If [status(Current Record Number) = Status(CurrentFound Count)]

Exit Loop If [1]

Else

Omit Record

It seemed to solve the problem.

Upon running my old script detailed at the beginning of this topic, it worked fine. I went back and did as the bridge said, and checked the print setup. It was set on "Records Being Browsed," so I dont know what was wrong with it yesterday. I had a theory that it might have been having no pause step as the reason it was not working, but I have not been able to repeat the problem since early this morning when it mysteriously went away after I put the "Print With Dialog" in there. I took it back out and it works fine now. Wierd.

Is there anything else I might try, so as to prevent this from happening. I have about 33 more scripts that are similar to this, and I'm worried I might encounter the same problems.

Thanks All!

Ken

Link to comment
Share on other sites

Ken:

I have to agree with Vaughan's suggestion about simplifying your script to a find, replace, print. When I responded to your original inquiry a couple of months ago, about the record skipping problem in your script, I didn't question your main intent. But, it seems to me that if you have so many scripts doing these things, that you have overlooked a much simpler method that will likely do what you want.

Link to comment
Share on other sites

Hello all!

Thanks for all the help! I would like to go back and replace the scripts, but unfortuantely I have aleady spent months making all of them. I suspect it might be counter-productive for me to go back and re-write all of them. Vaughan asked why it couldn't be done with the find, replace, print; I ask why it couldn't be done with the aforementioned script? Are there problems with writing scripts this way? Will I run into problems, or do they just look complicated?

What I am aiming for is one script to house about 33 subscripts, and this script will be attached to a button that a user will click to perform them all. I understand that you men know a lot more than I do about FM and ScriptMaker, but I ask you if there is any other alternative than going back and re-writing all of the scripts?

Any help is greatly appreciated...as always.

Ken

Link to comment
Share on other sites

Maybe not with one script, but the complex procedure you initially posted (loops and omits and stuff) can be done with a much simpler find-replace-print process. That's the point -- do it in the simplest possible way.

Maybe some on-site consultancy would be beneficial.

Link to comment
Share on other sites

Thanks again for the reply, Vaughan.

Using the above script, could you give me a "for example" go get me started?

Also, I have another question that's off this subject but I don't feel like making another post. Perhaps you can answer it for me. One script does a loop through all the records to change contents of a field. I put a "Freeze Window" command in while it makes the changes. Right now, there are only 10 records in my Db, but if there's hundreds or thousands it may take a while to go through all of them. I want to put a message up just before freezing the window to say "Please Wait," but without the OK button of the Show Message step. is there a way to do that?

Thanks

Ken

Link to comment
Share on other sites

Ken

Could you post that second question in a separate thread: it's a good question and keeping it separate makes it easier for other people (and yourself) to find later.

Regarding the script, it was originally:

code:


Go to Layout [certain layout]

Go to Record/Request/Page [First]

Loop

If ["(PatternCount(Action List, "Appointment Obtained")) and

(Status(CurrentDate) >= Appointment on - 4) and

(IsEmpty(Letters2.3)]

Set Field ["Letters2.3","Appt. Reminder""]

Insert Current Date [select, "Letters P Date 2.3"]

Go to Record/Request/Page [Exit after last, Next]

Else

If ["Status (CurrentRecordNumber) = Status(CurrentFoundCount)

Omit Record

Exit Loop If ["1"]

Else

Omit Record

End If

End If

End Loop

Go to Layout ["Appointment Reminder Notice"]

Page Setup [Restore, No dialog]

Enter Preview Mode [ ]

Print [No dialog]

Enter Browse Mode

Show All Records


I reckon it could be reduced to something like this:

code:


Allow User Abort [off]

Go to Layout [certain layout]

Enter Find Mode []

Set Field [ Action List, "Appointment Obtained" ]

Set Field [ Appointment on, "< " & Status(CurrentDate) + 4 ]

Set Field [ Letters2.3, "=" ]

Set Error capture [on]

Perform Find []

If [ Status(CurrentError) <> 0

Beep

Show Message ["No records found, or an error occurred." OK only]

Else

Replace [ Letters2.3,"Appt. Reminder"", no dialog ]

Replace [ Letters P Date 2.3, Status(Currentdate), no dialog ]

Go to Layout ["Appointment Reminder Notice"]

Page Setup [Restore, No dialog]

Print [No dialog]

End If

Show All Records

Go to Layout[ original layout ]


Notes:

1) I haven't tested this.

2) You need to backup your databases before changing your scripts and running them.

3) Leave the Allow User Abort [off[ step out of the script while debugging otherwise ou won't be able to abort the script with the Esc key, but put it in when finished because you don't want users aborting the script.

4) Carefully check the Set Field [] steps to make sure they find the right records.

5) Also carefully check the Replace [] script steps: the second one needs to specify a calculated result, and you need to check the calculation to make sure it inserts the correct value. When you initially make the script allow the replace dialog to appear so you can see what's happening.

6) I'd also put in some Freeze Window steps to speed things up and make it look better.

7) I'd let users see the Print dialog at the end so they can cancel or change print settings as required.

Backup up your databases beforehand!

Link to comment
Share on other sites

Thanks for the reply, Vaughan.

Forgive me, but I'm not sure what you mean. Perhaps I will need to consult someone on this, because my problem is probably too big to solve here. shocked.gif" border="0 !

I have about 33 scripts that each look for a different quality in each record, and are date-sensitive. I don't understand how they all can be done with one script.

Please enlighten me!

Ken

Link to comment
Share on other sites

More questions:

What if ,in the above script, I also wanted to search if a field was empty? For example in the scripts that I wrote with the loops, I had this in the calculation:

(IsEmpty (Action List)) - where "Action List" is a Value List attached to a field with checkboxes.

Also, in the script that you suggested, posted above, you have this:

Set Field [Action List, "Appointment Obtained"]

as stated, the field Action List is a check box field with a Value List attached to it. I want it to see if there is a check next to the value "Appointment Obtained." Will it still work this way?

Thanks a lot for all the help!!!

Ken

Link to comment
Share on other sites

Going back to the prior issue....

It appears that the scripts will work just fine, because I went throught and put a Pause Script Step just before it prints, and all the records that should be printing show up. The problem comes when the printing actually happens... it doesn't seem to like printing ALL the records in the found set - only like the first one. Additionally, if I make each script print with dialog, it seems to work fine. That would be ok, if I didn't have over 30 of them bundled in one script as sub-scripts. If put the print dialog back in, the user would have to click the OK button for each of the scripts!

WIIIEEERRRDD!!!

Link to comment
Share on other sites

Not weird at all: in the Print setup there is an option to print the "records being browsed" or the "current record." Guess which one your's defaults to.

To change, print the way you want (records browsed) then open the script in Scriptmaker, close it, and elect to replace the page setup.

Link to comment
Share on other sites

This topic is 7248 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.