instead of using new keyword we can use create object like in this example we are creating object to write in excel sheet through our programexampleImports Excel Microsoft.Office.Interop.ExcelPrivate Sub Button1_Click(ByVal sender As System.Object ByVal e As System.EventArgs) Handles Button1.Click Dim objApp As Object Dim objBook As Object Dim objBooks As Object Dim objSheets As Object Dim objSheet As Object Dim range As Object ' Instantiate Excel and start a new workbook. objApp CreateObject( Excel.Application ) objBooks objApp.Workbooks objBook objBooks.Add objSheets objBook.Worksheets objSheet objSheets.Item(1) range objSheet.Range( A1 ) 'Set the range value. range.Value Hello World! 'Return control of Excel to the user. objApp.Visible True objApp.UserControl TrueEnd Sub
Hi Sometimes it happens that the client does not have an idea of creating an object of which class. it has to be decided at runtime. For such condition reflection can be used to get the type information of the class. Then we can use the Activator.createinstance class in order to create the instance of the object.
Objects are generally late bound when using class factories with interfaces (or base classes). An example of late binding can be seen below. The function that generates the concrete object (at runtime) will decide which type of concrete object to instantiateIReader reader GetFileOrDBReader();