Let a real "Dummy" help with your next Application

Got a Date you want to save, or a couple of totals you'll need later? Maybe a Dummy can help.

by Barry Rochford Barry Rochford is a Consultant and Alpha Developer living in Mid-town Milford Square, PA. (that's where the 4way Stop is). He can be reached at brochford@enter.net. Barry is the President of the New York Alpha User Group. He has written this tip which we hope you'll find useful.

Many Alpha Developers create a "Dummy" or "Start" Table so they can attach all their Menu Forms to that Table rather than attaching them to a "Live" Table. That's a real good idea and I do it myself. But, I always remember how easy it was in Alpha4 to save Totals, Dates, any variables you wanted using VSAVE / VSAVEE. Well, we don't have that ability as such in Alpha5, so I had to improvise and you may find yourself in a situation where you can use it also.

Here's a "real life" situation. I wrote the Accounts Payable Sub-system for a Client as Co-developer. It was fairly easy, "terms" were not required, no partial payments to be handled. All I really had to do was:

No, I didn't forget about printing checks. This Client has the President's Wife handwrite all the checks. I believe she uses the "OneWrite" System. The procedure is the Listing is sent, the checks are written and the Listing is returned with the Check Numbers added along with the date paid. So let's add one more item to the list above.

As with most manual Systems, sometimes the System breaks down. In this particular case, on occasion, the listings with the Check Numbers just never seem to be returned. This does make it difficult for the Office to answer Accounts Payable questions.

Well, here I am, producing a nice looking listing of Invoices to be Paid Today. My Invoice table has those records flagged as PAY_TODAY. I decided there is no way I will allow anyone to flag other Invoices to pay without first entering the Check Numbers and Check Dates and letting me un-flag the Invoices and changing the STATUS to PAID.

I fleetingly thought of "batching", assigning a batch number, thus allowing additional Invoices to be flagged as PAY_TODAY. Then I said NO, that's not the problem. The real problem is, the Check Numbers & Dates were not being returned. Now, how to solve the problem.

We already had a "START" Table and these are the field I used:

Structure of START Table
Field Type Width Comments
Record_ID C 5 "APApp" so I can identify this as the correct record
Desc C 15 "Marked for Pay" or "Ck. @'s Entered" depending on which task was completed.

Printing the "Report of Invoices Being Paid Today" is the last thing done prior to sending the Report out for Check Writing. I used that as my starting point. I wrote a simple script for the OnPrintExit Event. The pseudo code is:

OnPrintExit Event Script - Pseudocode version
Open Start File
Get first record
Does Record_ID="APApp"
Yes - put "Marked for Pay" into Desc
No - Display error message - Start Table Problem, 1st Rcd. not APApp

The actual Xbasic code is:

OnPrintExit event script - Xbasic version
dim tbl as p
tbl=table.open("Start",file_rw_shared)
tbl.fetch_first()
if tbl.record_id="APApp" then
tbl.change_begin()
tbl.desc="Marked for Pay"
tbl.change_end(.t.)
else
ui_msg_box("Warning","Start Table Problem, 1st record not APApp")
end if
tbl.close()
end


I also had a Form used to Enter Check Numbers so I attached a companion Script to its OnExit Event. The pseudocode is almost the same as one above so I won't repeat it. The Xbasic script is:

OnExit Event Script
dim tbl as p
tbl=table.open("Start",file_rw_shared)
tbl.fetch_first()
If tbl.record_ID = "APApp" then
tbl.change_begin()
tbl.desc = "Ck. #'s Entered"
tbl.change_end(.t.)
Else
ui_msg_box("Warning","Start Table problem - 1st record is not APApp")
end if
tbl.close()
end

Now, I did it! I can tell when the Check Numbers have been entered and I have done all the "Housekeeping" required. So, what's the next step? Allowing other Invoices to be marked for Payment only after Check Numbers & Dates have been entered.

To do this required another small Script in the Form where you View/Select Invoices for Pay. I used the OnActivate Form Event.

Open Start File
Get first record
Does Record_ID="APApp"
Yes - Is Desc = "Marked for Pay"?

Yes - Display "No selections allowed, Ck. #'s not entered from Previous Run"

No - display Error Message - Start Table Problem, 1st Rcd. not "APApp"

The Xbasic script attached to the OnActivate Form Event is:

dim tbl as p
tbl=table.open("start",file_rw_shared)
tbl.fetch_first()
if tbl.record_id="APApp" then
if tbl.desc="Marked for Pay" then
ui_msg_box("Warning","No changes Allowed, Ck #'s not entered from Previous Run")
this.allow_change(.f.) 'prevents any change
end if
else
ui_msg_box("Warning","Start Table problem, 1st record not APApp")
end if
tbl.close()
end

Use of the "this.allow_change(.f.)" prevents any changes from being accepted. Now the Office Personnel can say "The SYSTEM won't let us pay any more Invoices until Check Numbers are entered."

If necessary you could have 3 or 4 date fields and 5 or 6 amount fields and use them as you wish. If you added a Record Id, you could have multiple records for different purposes. You could keep totals of Today's Sales, Rec'd on Account, Vendor Invoices entered, Accounts Receiveable and Accounts Payable. The Accountants (Bean Counters) really like this kind of stuff. You could produce a Daily Report with all the Financial Data on one page. You might even be made an Honorary Bean Counter <grin>.

Don't forget 2 rules when reading/writing tables in your Scripts. First, always close your tables. Second, include OnError coding in case of errors. This will save you many headaches in the future.
6/16/98

Return to home page