Wednesday, March 19, 2014

Registering .Net Dlls' for use in VB6 32 applications

You have that legacy application that is not willing to go away and you need to use functionality from code you created in .Net.

You need to register the dll for VB6 to be able to find it.

Best thing to do is to create a batch file with the following code:

1) Make the call from you application folder, so you need to move your cursor to that folder
2) Unregister the dll - this is really important as windows registry can get really messy and totally confused if you have multiple versions of the same dll
3) Register the new dll. NOTE: Use the /codebase switch otherwise it just won't happen

Here is the batch file code:

cd C:\Program Files\YourApplication\
C:\windows\microsoft.net\framework\v2.0.50727\Regasm.exe /u YourNewcode.dll
C:\windows\microsoft.net\framework\v2.0.50727\Regasm.exe ReportLogic.dll /codebase

If your application is used by multiple users, you can add code to run the batch file when users load your application.

.Net Fundamentals - Generic Collections - ArraList - List


The .Net Framework collection provides data structures to store and manipulate collections of items as part of the System.Collections namespace.

Array lists are used to store a bunch of items together, you can store items of different data types or items of the same type:

To create a list of items of the same type in C#:
   ArrayList EndOfQuarterList = new ArrayList();
 
  EndOfQuarterList .Add("March");
  EndOfQuarterList .Add("June");
  EndOfQuarterList .Add("September");
  EndOfQuarterList .Add("December");

To create a list of items of different types in VB:

   Dim MixAndMatch as ArrayList = new ArrayList()

  MixAndMatch.Add("First Item")
  MixAndMatch.Add(10)
  MixAndMatch.Add(3.1416)

  But what if we need a more complex ArrayList? you would need to create a Generic List, this object allows easy creation and manipulation of structured data.

  For example, we need to manage financial information at end of every quarter

   C#:
    class QuarterlyInformation
    {
        private string _Name;
        private byte _Month;
        private double _Income;      
        private double _Expenses;
   
        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }      

        public byte Month
        {
            get { return _Month; }
            set { _Month = value; }
        }      

        public double Income
        {
            get { return _Income; }
            set { _Income = value; }
        }
   
        public double Expenses
        {
            get { return _Expenses; }
            set { _Expenses = value; }
        }

        public double ProfitAndLoss()
        {
            return _Income - _Expenses;
        }

        public QuarterlyInformation(string Name, byte Month, double Income, double Expenses)
        {
            this.Name = Name;
            this.Month = Month;
            this.Income = Income;
            this.Expenses = Expenses;
        }
    }

     static void Main(string[] args)
        {
            //handle my quarterly information

            List<QuarterlyInformation> Financials = new List<QuarterlyInformation>();

            Financials.Add(new QuarterlyInformation("March", 3, 100, 50));
            Financials.Add(new QuarterlyInformation("June", 6, 500, 250));
            Financials.Add(new QuarterlyInformation("September", 9, 350, 100));
            Financials.Add(new QuarterlyInformation("December", 12, 100, 50));

            foreach (QuarterlyInformation item in Financials)
            {
                Console.WriteLine("Profit and Loss {0}:", item.ProfitAndLoss());
            }
        }
 
     
       To summarize, generic lists are a great tool to create strong typed collections of objects