Closing Forms in VB.NET

This code finds all open forms and closes them one by one. Then it exits the application. This ensure nothing is left behind leaching memory.

http://bytes.com/topic/visual-basic-net/answers/507363-close-all-forms-but-main

dim Success as Boolean
do
success = true
try
for each f as form in my.application.openforms
if f.name <> “Main” then f.close()
next f
catch ex as exception
success = false
end try
loop until success

Me.close()
Application.Exit()

 

Another note about the above code:http://www.vbforums.com/archive/index.php/t-255285.html

Application.Exit() does NOT raise the Form.Close() event and can leave processes of a Form running in the memory ( thus is classed as unsafe ) , before running Application.Exit() you must use Form.Close() on each Form. here’s a quote direct from MSDN …

CAUTION The Form.Closed and Form.Closing events are not raised when the Application.Exit method is called to exit your application. If you have validation code in either of these events that must be executed, you should call the Form.Close method for each open form individually before calling the Exit method.

Another handy script for comparing db objects (like sps and triggers)

http://gallery.technet.microsoft.com/scriptcenter/Compare-Stored-Procedure-6c…

Description

This is a stored procedure to compare the code of the objects like Stored Procedures , Triggers , Views and Function between two databases. This will be helpfull to generate a report on which objects are out of synch. This uses the system table SYS.SQL_modules.

Parameters

 @SourceDBName = Source Database Name
 @DestDBName    = Destination Database Name with which the code has to be compared
 @ObjectName     = For comparing the required object names only. This parameter accepts wildcard LIKE also.
                            Default ‘%’.All Objects

  Usage

1. To compare the code for all the objects

    EXEC CompareObjectCode @SourceDBName='<SourceDB>’,@DestDBName='<DestDB>’

2. To compare the code for the objects having a specfic pattern in the name. The below does a comparision for the objects containing the leters “sp”

    EXEC CompareObjectCode @SourceDBName='<SourceDB>’,@DestDBName='<DestDB>’,@objectname = ‘%sp%’

———————————

IF OBJECT_ID(‘CompareObjectCode’,’P’) IS NOT NULL
    DROP PROC CompareObjectCode

GO

CREATE PROC CompareObjectCode
 @SourceDBName SYSNAME      
,@DestDBName   SYSNAME    
,@ObjectName   SYSNAME     = ‘%’

AS
/* Parameters

 @SourceDBName = Source Database Name
 @DestDBName   = Destination Database Name with which the code has to be compared
 @ObjectName   = For comparing the required object names only. This parameter accepts wildcard LIKE also.
                 Default ‘%’ = All Objects

                  */

    DECLARE @SQL VARCHAR(MAX)

    SELECT @Sql =
    ‘
    SELECT  ”Object Name” = ISNULL(SRC.name,Dest.name)
           ,”Object Type” = ISNULL(SRC.type_desc,Dest.type_desc)
           ,”Status” =   CASE
                                WHEN SRC.Definition is null THEN ”Missing in Source”
                                WHEN Dest.Definition is null THEN ”Missing in Destination”
                                WHEN SRC.Definition <> Dest.Definition THEN ”Definition Mismatch”
                                ELSE ”Match”
                                END
           ,”Source Created Date” = SRC.create_date
           ,”Source Modify Date”  = SRC.modify_date
           ,”Destination Created Date” = Dest.create_date
           ,”Destination Modify Date”  = Dest.modify_date
      FROM
        (
         SELECT so.name,so.create_date,so.modify_date,sm.definition ,so.type_desc
           FROM ‘ + @SourceDBName + ‘.SYS.objects so
           JOIN ‘ + @SourceDBName + ‘.SYS.sql_modules sm
             ON so.object_id = sm.object_id
          WHERE so.name like ”’ + @ObjectName + ”’
        ) Src
        FULL OUTER JOIN
        (
         SELECT so.name,so.create_date,so.modify_date,sm.definition ,so.type_desc
           FROM ‘ + @DestDBName + ‘.SYS.objects so
           JOIN ‘ + @DestDBName + ‘.SYS.sql_modules sm
             ON so.object_id = sm.object_id
          WHERE so.name like ”’ + @ObjectName + ”’
        ) Dest
        ON SRC.name = dEST.name
    ‘

    EXEC (@Sql)

GO

Gonna do some serious damage to some code I’m working tomorrow… #forthegreatergood

I sure hope I can get this application to work. It’s set up so differently than how I learned to code.

So, google to the rescue.

These articles should help me get started.

http://vbnotebookfor.net/2007/09/28/how-to-pass-data-between-forms-in-vbnet/

http://forums.codeguru.com/archive/index.php/t-189965.html

http://www.ozgrid.com/forum/showthread.php?t=87841

http://social.msdn.microsoft.com/Forums/eu/vbgeneral/thread/a8688e69-3824-41e…