Can not get windows to close

Hello again friends,
I am making tremendous progress in printing my report.
The report prints just fine and I am brought back to the window that I want in the front which is “Data Entry”. The problem is there are two other form windows under that were used in the preparation to print the form. I would like these two windows (forms) to close and go away leaving me with only the “Data Entry” form.
Below is my procedure:

;This procedure will print a one page summary of all discounts
Select «Discount.1» >1 OR «Discount.2» >1 OR «Discount.3» >1 OR «Discount.4»
Field «Gross.1» Total
Field «Gross.2» Total
Field «Gross.3» Total
Field «Gross.4» Total
Field «Assistance» Total
Field «Pre-Paid» Total
Field «Multi Child» Total
Field «Teach Staff» Total
Field «Pastor Staff» Total
Field «Church Mem» Total
Field «Incentive Award» Total
Field «Silent Auction» Total
Field «New Sibling» Total
Field «Other Dis» Total
Field «Discount.1» Total
Field «Discount.2» Total
Field «Discount.3» Total
Field «Discount.4» Total
OutlineLevel 1
OpenForm “Discount Listing Summary”
printtopdf “”,“Printer”,"",“orientation”,“Portrait”
setactivedatabase “SGCS Family Info.19_20.pandb” // use the name of your database
openform “Data Entry”

I just thought of something. After the the procedure runs and the report is printed I am left with 3 open windows with the main one being “Data Entry”. Through that same procedure could I select the window “Discount Listing Summary” and close that window. I could do the same with the second window.

I have a custom statement that closes all the windows in a database except the active one. The code is short.

let otherwindows = arrayrange(info("windows"),2,-1,cr())
looparray otherwindows,cr(),otherwindow
if windowinfo(otherwindow,"database")=info("databasename")
    // bring window forward, then close it
        window otherwindow

This topic was discussed in an earlier post: Window Position with Initialize

Gerald, in your first post on this thread you show code which lists 18 field and total statements. If these are consecutive fields, you could save a lot of typing by using code like this;

field «the field preceding Gross.1»
until info("fieldname") = "Discount.4"

Thanks Cooper,
This worked fine to close one of the two open windows. Any idea how to get them both to close? Should I repeat the code you provided in the procedure.

Thanks Michael. I assume this will only work if the fields I want are in the same order of the database.

Hi Cooper,
I added the following after your code and it closed that second form. My question is at the main Data Entry window the name is “(null):Data Entry”, what does the null mean. I would think it would say "SGCS Family Info.19_20:Data Entry.

Another approach to this would be to replace the above quoted line from your original post with:

openfarform “SGCS Family Info.19_20.pandb”,“Data Entry”

This assumes the Data Entry form is in the SGCS Family Info.19_20.pandb file which we first make secret with the first code line. This should close all the open windows and then reopen the Data Entry window. I have not tested this but it seems pretty straight forward.

The procedure I wrote I think should close all other windows in the same database as the active window. I don’t know why your procedure would leave one open. It will not close a window in a different database.
The window name normally contains the database name followed by a colon followed by the form name. It seems like a window beginning with (null) is not associated with any database. I don’t know how that can happen. If I were troubleshooting this, my first step would be to insert a statement alertsheet arrayrange(info(“windows”),2,-1,cr()) after the existing arrayrange statement to see if the array is correct. It should list all of the open windows.

Good point, and if one of the other open window or windows belong to a different database then my solution will not close them either. Is there more going on here than what the original post suggests?

Here is some code that will close all open windows in all open databases but keep open the currently active window. I have also included a trap to keep the Panorama Help windows open for convenience.

let theStartwindow=info("windowname") 
let theWindowList=info(“windows”)
theWindowList=arraystrip(arrayfilter(theWindowList, ¶,
    {?(import() beginswith "Panorama Help" or import()=
    theStartwindow ,"",import())}),¶)
looparray theWindowList, ¶, element, index
    window element
window theStartwindow

Hello Friends,
After this driving me crazy for several days the following is the final code in my procedure that works just fine and all the unnecessary windows close. Don’t ask me why it finally works but it does. BTW: I have been with Jim at Provue for over 30 years and have never used an array. Is the a Array for Dummies that I could look at?

I would suggest the “Data Collections” video (part of the Panorama X Intensive Training course).