To All,
Here is my CloseAll global function script. A zipped copy version is attached as well.
Regards,
Ira J. Perlow
Computer Systems Design & Associates
[email protected]
function CloseAll as N(Typename as C,MaxAlias as N)
' Created by Computer Systems Design & Associates
' Copyright 2001 Computer Systems Design & Associates, All Rights Reserved
' Last Update: March 30, 2001
' Purpose: To close all open layouts of a specific type regardless of the alias
' Input: TypeName=List of TypeNames (e.g. "FORM,BROWSE")
' if blank, defaults to "FORM,BROWSE"
' MaxAlias=Minimum number of aliases to search for and close
' If value is less than 0, then only the 1st layout is closed, no aliases
' Output:Total number of layouts closed
' Errors:None
' Typical Usage:
' CloseAll("",10)
' Examples:
' CloseAll("",10) ' Close all forms and browses to at least alias 10
' CloseAll("Form",10) ' Close all forms to at least alias 10
' CloseAll("Form",-1) ' Close only primary instances of forms
dim Typename as C
dim MaxAlias as N
' Returns 0 if no forms are open
CloseAll=0
' Set default layouts to close
If trim(Typename)==""
Typenms="FORM BROWSE"
Else
Typenms=UPPER(alltrim(typename))
End If
' Set count of closed forms to 0 initially
closecnt=0
' Iterate though all layout types
FOR j=1 to w_count(Typenms)
Typenm=UPPER(ALLTRIM(WORD(Typenms,j)))
'enumerate through all forms
formnm=eval(":A5."+Typenm+"_enum('')")
if .not.(formnm=="")
while .not.(formnm=="")
trace.writeln("checking "+Typenm+" Named="+formnm)
' close all layouts up to maxalias for formnm
i=0
frm=":"+left(alltrim(formnm),at("@",formnm,1)-1)
frmnm=frm
' close next alias if it exists
while i>=0
trace.writeln("checking "+Typenm+" alias Named="+frmnm)
ptr=obj(frmnm)
if is_object(ptr)
' This line closes the layout for any of the Type Names
' in the list on the off case there is more than 1 object
' with the same name but different types. If we get the
' wrong one for the current type, it will pick it up for
'the other type
IF *WORD(keywords(typenms),UT(ptr.class()))
'trace.writeln("Closed "+UT(ptr.class())+" alias Named="+frmnm)
ptr.close()
closecnt=closecnt+1
frmnm=frm+ltrim(str(i))
i=i+1
ELSE
frmnm=frm+ltrim(str(i))
if i>maxalias
i=-1 ' Set to -1 to force exit
else
i=i+1 ' else set up for next alias
end if
END IF
else
frmnm=frm+ltrim(str(i))
if i>maxalias
i=-1 ' Set to -1 to force exit
else
i=i+1 ' else set up for next alias
end if
end if
end while
' get the next form name to close
formnm=eval(":A5."+Typenm+"_enum(formnm)")
end while
end if
Next j
CloseAll=closecnt
END
end function
Here is my CloseAll global function script. A zipped copy version is attached as well.
Regards,
Ira J. Perlow
Computer Systems Design & Associates
[email protected]
function CloseAll as N(Typename as C,MaxAlias as N)
' Created by Computer Systems Design & Associates
' Copyright 2001 Computer Systems Design & Associates, All Rights Reserved
' Last Update: March 30, 2001
' Purpose: To close all open layouts of a specific type regardless of the alias
' Input: TypeName=List of TypeNames (e.g. "FORM,BROWSE")
' if blank, defaults to "FORM,BROWSE"
' MaxAlias=Minimum number of aliases to search for and close
' If value is less than 0, then only the 1st layout is closed, no aliases
' Output:Total number of layouts closed
' Errors:None
' Typical Usage:
' CloseAll("",10)
' Examples:
' CloseAll("",10) ' Close all forms and browses to at least alias 10
' CloseAll("Form",10) ' Close all forms to at least alias 10
' CloseAll("Form",-1) ' Close only primary instances of forms
dim Typename as C
dim MaxAlias as N
' Returns 0 if no forms are open
CloseAll=0
' Set default layouts to close
If trim(Typename)==""
Typenms="FORM BROWSE"
Else
Typenms=UPPER(alltrim(typename))
End If
' Set count of closed forms to 0 initially
closecnt=0
' Iterate though all layout types
FOR j=1 to w_count(Typenms)
Typenm=UPPER(ALLTRIM(WORD(Typenms,j)))
'enumerate through all forms
formnm=eval(":A5."+Typenm+"_enum('')")
if .not.(formnm=="")
while .not.(formnm=="")
trace.writeln("checking "+Typenm+" Named="+formnm)
' close all layouts up to maxalias for formnm
i=0
frm=":"+left(alltrim(formnm),at("@",formnm,1)-1)
frmnm=frm
' close next alias if it exists
while i>=0
trace.writeln("checking "+Typenm+" alias Named="+frmnm)
ptr=obj(frmnm)
if is_object(ptr)
' This line closes the layout for any of the Type Names
' in the list on the off case there is more than 1 object
' with the same name but different types. If we get the
' wrong one for the current type, it will pick it up for
'the other type
IF *WORD(keywords(typenms),UT(ptr.class()))
'trace.writeln("Closed "+UT(ptr.class())+" alias Named="+frmnm)
ptr.close()
closecnt=closecnt+1
frmnm=frm+ltrim(str(i))
i=i+1
ELSE
frmnm=frm+ltrim(str(i))
if i>maxalias
i=-1 ' Set to -1 to force exit
else
i=i+1 ' else set up for next alias
end if
END IF
else
frmnm=frm+ltrim(str(i))
if i>maxalias
i=-1 ' Set to -1 to force exit
else
i=i+1 ' else set up for next alias
end if
end if
end while
' get the next form name to close
formnm=eval(":A5."+Typenm+"_enum(formnm)")
end while
end if
Next j
CloseAll=closecnt
END
end function
Comment