Matrix calculation mishap

I am still working on my databases of team schedules, which almost works right, but there is one little glitch that I cannot get through except through an awkward kludge. The database opens with a team schedule, which is a matrix. The dates are variables date1, date2, … which are variables set up when the .initialize procedure runs. They are displayed as datepattern(datavalue(“date” + str(info(“MatrixCell”) + val(offset))),“Mon dd, 'yy”). The formula is what displays when the matrix is first opened, even after a showpage command. However, if I move up or down the database, the dates show up properly.

So far, the only way I can avoid this is to move up or down a record and then move back. But there should be an easier way to do this. The awkwardness comes from having to test whether moving the record is stopped or not.

Bruce, you might want to try putting your variable declarations in a .PreInitialize procedure. This should establish everything before the matrix opens. Here is the info on the .PreInitialze procedure when it was added in Version 0.1.019 (released January 28th, 2016):

Added new .PreInitialize procedure that runs before windows are opened. This should not do anything except initialize variables. It definitely should not perform any UI changes or display, so it should NOT contain showvariables, and it should not modify the values of any fields. Just use this for setting up fileglobals. Also, don’t make any assumptions about what window is currently open – it should not reference windows at all.

So I tried that, and no soap. I tried it both with and without setting up initial variables. Some of the other variables, which did work before, are no longer initialized. It says that the variables do not exist.

A mystery to me Bruce, I have used .PreInitialize often in the past without problems. I just ran another test using it to set up a couple of fileglobal variables and it performed as advertised.

Gary’s suggestion of using .PreInitialize is a good one, that is exactly what .PreInitialize is for.

Bruce, since you have left out a lot of details, it’s hard to provide good advice. It sounds like you have a Text Display object in the Matrix Frame with this formula:

datepattern(datavalue("date" + str(info("MatrixCell") + val(offset))),"Mon dd, 'yy")

Does the Matrix Object itself have a formula? If so, you should use that formula in a showvariables statement.

I would actually suggest a completely different approach. Instead of using a bunch of variables, create one variable that is an array, something like this:

let dates = datepattern(first date,"Mon dd, 'yy")+cr()+datepattern(second date,"Mon dd, 'yy")+cr()+...
showvariable dates

You might be able to use a loop to create this, you haven’t said where the dates are coming from.

Then the formula for the Matrix Object would simply be:


And the formula in the Text Display object in the Matrix Frame would be


Jim, I actually sent you one of these schedule databases a while ago, one that crashed when one of the forms opened. That no longer happens in High Sierra, and the Small Schedule form, which is the one that should open first, never did crash. It is page view, not view as list.

Yes, there is a text display object with that formula. Each matrix frame has four elements. Three of them are fields in the individual record, and the other is that date, which is causing the problem.

I will look into doing this differently, perhaps changing the numeric dates from numbers that are formatted in the matrix data box, to text that are calculated and formatted ahead of time. I need to deal with setting up those dates differently sometime anyway, so that someone else can make these schedules besides me. I am getting to the age where I really wish that I could be replaced for a lot of things!

Mostly I wanted to point out that this was happening. It works fine in Panorama 6, but not in Panorama X.

It is good to know about .PreInitialize. These special procedure names are not well documented in Help. They should be, especially since they do not pop up like they did in Panorama 6. New users who did not use Panorama 6 will not be able to find out about them very easily.

I know I often tend to look at things differently from many other people. But there may be other people who look at the world the way that I do, and will run into the same problems.

So I have tried experimenting with this, and I have found a few things.

  1. .PreIinitialize has to assign values to variables. It cannot just declare them.
  2. .PreInitialize and .Initialize have to be capitalized as I wrote them.
  3. .PreInitialize seems to be the only thing running when it runs. It cannot call another procedure.

The last one is awkward, because the dates that I am using are calculated from the value of today() by default, but they may have to be reevaluated. Reevaluating will change the dates, but it does not change the values in the matrix unless, as before, the record that the matrix is displaying is changed.

Anyway, I thought I would pass this along in case anyone wants to write a Help entry for .PreInitialize and .Initialize. I am not certain I am up to it.