Auto close procedure windows on startup


#1

Is there an easy way to automatically close any open procedure windows when opening a database?

thanks
b


#2

The only way I know of would be to have your .Initialize procedure check the open windows and close the ones that were procedure windows.

local allDBWindows,procedureWindows
allDBWindows=info("windows")
procedureWindows=dbinfo("procedures","")
looparray allDBWindows,cr(),element,index
    If element beginswith info("databasename")
        If arraycontains(procedureWindows,array(element,2,":"),cr())
            window element
            closewindow
        Endif
    Endif
endloop

Note that there would be a conflict if you had a form window and a procedure window both name the same name open at this time. In that case it would probably only close the one that was most forward whether or not it was the procedure window. You should never name a form and a procedure the same anyway just for situations like this.


#3

That seems to work perfectly–thanks!

b


#4

You can avoid the potential problem with duplicate names by checking the type of each window as you go through the loop with the info(“windowtype”) function, which returns the window type for the current window.


#5

The problem with using the info(“windowtype”) method is that you need to make the window being tested the front-most window for it to work. That means every window in turn will be brought to the front for testing and it will cause a lot of screen activity especially if there are many windows involved. That was my first approach to this problem and why I chose the scheme I selected. It will only bring a window that is named in the dbinfo(“procedure”,"") list to the front and then immediately close it but has the problem of commonly named windows of forms and procedures.

We could incorporate your scheme within the looparray code after the window name is found in the procedure list. We could then test to make sure it is a procedure window before actually closing it. In the case were it fails that test the window with the form will be left open and end up being the front-most window when the code finishes – still not perfect but an improvement. Here is that revised code:

local allDBWindows,procedureWindows
allDBWindows=info("windows")
procedureWindows=dbinfo("procedures","")
looparray allDBWindows,cr(),element,index
    If element beginswith info("databasename")
        If arraycontains(procedureWindows,array(element,2,":"),cr())
            window element
	   If info("windowtype")=8
                closewindow
	   Endif
        Endif
    Endif
endloop

#6

A thank you first. And a question/request: Gary, can you (or anyone on the forum) give me another example or two of when you would use looparray? This is a new function to me and looks like it might be super useful, although as a non-programmer I’m not sure when or how.

thanks

bk


#7

The looparray is by far my favorite and most useful of all the new statements and functions. You can think of it as the arryfilter on steroids. The arrayfilter will take each element of the array and run a formula that normally uses the contents of the current element via the import() function and returns the result back to the array replacing the original element. The arrayfilter can also use the seq() function in the formulas to tell what number element is being processed at the time. You are, however, limited to only using a formula which means only functions can be used – no statements.

The looparray will allow you to take each element of the array and run any code you want using the value of the current element (equivalent to the import() in arrayfilter) and its index# (same as the seq() in arrayfilter). This allows for a streamlined, straight forward method to do all kinds of involved processing that would have been done previously setting up a loop using a counter for the index# along with an incremented array( function to get the current element. The looparray is also much faster than the old method.

In practice you could have an array of purchased items in an array.

theItems="Large Cog,Small Sprocket,Medium Cam,Extra Large Cog"

Now using the looparray on the theItems array you could process each item in turn to lookup prices, enter into an invoice and total the amounts for a final price all in one easy block of code. You can create variables within the loop code to handle totaling prices as you go through the elements and do pretty much anything you want along the way. Extremely powerful and only limited by your imagination and needs.

Like always with programming skills, it serves you best if you try experimenting yourself with some simple implementations to get a feel for this terrific new tool. Once you wrap your head around it you will find yourself using it all the time.


#8

It’s one of my favorites also. Your description is spot on. I’ll add one thing – the arrayfilter statement allows you to iterate over a text array using a formula. The looparray statement allows you to iterate over an array using arbitrary code. So looparray is much more powerful – however, it is also quite a bit slower. So if speed is important, you should use arrayfilter if possible. But in many situations, it is not possible. If you look inside the code included inside Panorama (in the libraries and wizards), you’ll see looparray used very frequently, probably in hundreds of places.

If you’ve purchased the Panorama X Intensive Training course, looparray is covered there. I can’t remember whether that is in the Data Collections or the Control Flow sessions, it’s one of those.


#9

I’m not sure if it is helpful in this instance, but there is a way to find out the type of a window without bringing it to the front – the windowinfo( function.


#10

Well, I guess I missed that one – too many to keep track of in my pea brain. Here then is the final revised code that will only bring procedure windows forward to close them and leave all the rest as they are:

local allDBWindows,procedureWindows
allDBWindows=info("windows")
procedureWindows=dbinfo("procedures","")
looparray allDBWindows,cr(),element,index
    If element beginswith info("databasename") and  windowinfo(element,"Type")="Procedure"
            window element
            closewindow
    Endif
endloop

#11

Again, many thanks!

b