File switching problem

My Invoices file opens my Advertisers file, and vice versa. In the .initialize procs of both files, I have an openfile statement that opens the other file. This was used in Pan 6 so that both files would be open no matter which one the user opened first. It has worked fine for years, and it was working in Pan X, until recently.

I assume that openfile (and opendatabase) will run the .initialize when the file is first opened but NOT if the file is already open. I’ve used it for years just to switch between files.

I began getting an error when the files opened up, and so far this is what happens. The code below is in the Invoices file. I started getting an error: fgItem1popup doesn’t exist when the files opened up and .initialized. But if I add in a Message statement, there is NO error, and everything works fine, after clicking the Message OK button. The variable is loaded correctly.

Also, I changed openfile to opendatabase to see if it would help, but it acts the same.

fileglobal fgItem1popup

let mainwin = info(“windowname”)
OpenDatabase “Advertisers”
OpenSecret “Price Master”
Window mainwin
message mainwin // Remove this and the error occurs in the following

fgItem1popup = arraybuild(¶, “Price Master”, “«Type»”)

I wonder if replacing the message statement with a wait 0 might cure the problem.

What version are you using? There was a problem with some .Initialize procedures in the b27 release, this was fixed in the b28 release. I’m wondering if you might have missed the recently uploaded b28 release.

Also, FYI, you could eliminate the first line in your code and make the last line

letfileglobal fgItem1popup = arraybuild(¶, “Price Master”, “«Type»”)

I’m not suggesting this will have anything to do with the problem you are encountering, just that it might be more convenient.

Yes, I’m using b28 (especially since that fixed another bug I had, thank you much :slight_smile: )

Replacing the Message statement with wait 0 does fix the problem (I had tried a delay 2, but that did not fix it).

Or, replacing it with setactivedatabase “” fixes it. (Of course, the preceding window statement should have the same effect.)

I originally did have the letfileglobal as the last line, but when the error began showing up, I went back to the old method to be sure the variable was being defined in the Invoices file, before the Price Master was opened secretly. When the error was occurring, if I opened the very helpful variable view tool before opening my files, it showed that the fgItem1popup var is in the Price Master file!

It does seem to be related to intializing. If the error occurs, and I then run the .initialize proc manually, the error does not occur, and the var works as expected.

That’s interesting. I would probably go with that as the solution.

Also, you could simply use:

opendatabase "Advertisers"
opensecret "Price Master"
setfileglobal "Main Database","fvItem1popup",arraybuild(¶, “Price Master”, “«Type»”)

Of course you’ll have to put in the correct name for your main database. Or you could even do this:

opendatabase "Advertisers"
opensecret "Price Master"
setfileglobal info("proceduredatabase"),"fvItem1popup",arraybuild(¶, “Price Master”, “«Type»”)