none
Vb.net Object oriented features? RRS feed

  • Question

  • Hello,

    I am developing an application. Although I code it and its working properly i just want it to be better in any manner. The part of the thing i have heard is that VB.net has some good object oriented features. Can anybody take a look at my code and give me any idea what do i need to do to have some efficient and good code?

    Private Sub Tbl_propertyDataGridView_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles Tbl_propertyDataGridView.RowHeaderMouseClick

    objExcel = CreateObject("Excel.Application")

    objWBook = objExcel.Workbooks.Add

    '============================ Excel sheet formating

    objWBook.Sheets(3).Delete()

    objWBook.Sheets(2).Delete()

    objSheet = objWBook.ActiveSheet

    colw = 1

    setColWidth(colw, "A1")

    colw = 2

    setColWidth(colw, "C1")

    setColWidth(colw, "G1")

    setColWidth(colw, "H1")

    setColWidth(colw, "J1")

    setColWidth(colw, "L1")

    setColWidth(colw, "N1")

    setColWidth(colw, "P1")

    setColWidth(colw, "Q1")

    setLineStl("D7", "F09", "top", 2)

    setLineStl("D7", "F13", "left", 1)

     

    objSheet.Range("B3", "G3").Font.Bold = True

    objSheet.Range("B5").Font.Bold = True

    objSheet.Range("B5", "f13").Font.Size = 9

    objSheet.Range("B8").RowHeight = 5

    objSheet.Range("A1", "Q76").Interior.ColorIndex = 19

    objSheet.Range("B5", "G14").Interior.ColorIndex = 40

    objSheet.Range("D7", "F7").Interior.ColorIndex = 2

    objSheet.Range("D9", "F9").Interior.ColorIndex = 2

    objSheet.Range("D10", "F10").Interior.ColorIndex = 2

    objSheet.Range("D11", "F11").Interior.ColorIndex = 2

    objSheet.Range("D12", "F12").Interior.ColorIndex = 2

    objSheet.Range("D13", "F13").Interior.ColorIndex = 2


    Sub
    setColWidth(ByVal colwidth As Int16, ByVal cRange As String)

    objSheet.Range(cRange).ColumnWidth = colwidth

    End Sub

    Sub setLineStl(ByVal frange As String, ByVal trange As String, ByVal lnSty As String, ByVal lnThick As Int16)

    Select Case lnSty

    Case lnSty 'left'

    objSheet.Range(frange, trange).Borders(XlBordersIndex.xlEdgeLeft).LineStyle = lnThick

    Case lnSty 'right'

    objSheet.Range(frange, trange).Borders(XlBordersIndex.xlEdgeRight).LineStyle = lnThick

    Case lnSty 'top'

    objSheet.Range(frange, trange).Borders(XlBordersIndex.xlEdgeTop).LineStyle = lnThick

    Case lnSty 'bottom'

    objSheet.Range(frange, trange).Borders(XlBordersIndex.xlEdgeBottom).LineStyle = lnThick

    End Select

    End Sub

    Anybody have any idea? I just need some ideas.
    Thanks in advance.
    Bye

    Supes

    Monday, June 19, 2006 3:35 PM

Answers

  • I wouldnt go overboard in trying to include inheritance.   You using the Excel Object model - making calls to it.   

    You dont need to use inherit Excel Model and add functions to create a easily maintainable and performing application.   You code is looking as though its simply make calls to the excel object model.    You may wrap you functionality up in a class with some methods but it is really pretty straightforward code that I think any use of inheritence would be overkill and possibly even determinental to performance.

    The excel object model is really a collection of methods in a class.   You simply calling those methods - sure youve got different arguments that you passing to them but you code is really not implementing much in the way of new functionality or an object model that is any different from the underlying functionality.

    Why do you think you need to implement OO features ?    You obviously have some ideas which is why you asked the question.

    I'd keep it as easy maintainable, straightforward code.    For something this simply theres absolutely no need to overcomplicate it for the sake of using OO features.

     

    Tuesday, June 20, 2006 5:40 AM

All replies

  • So your setting up an excel spreadsheet and your calling into the Excel object model.

    I'm not sure what you want us to do.   The code works and is reasonable.   I wouldnt get hung up on using some of the Object Oriented features like inheritence unless you really needed them.    Keep it nice and simple - it make maintenance easier for others.

    Anyway - you want to put some exception/error handling in - just in case.   I see none in this code.

     

     

    Monday, June 19, 2006 4:06 PM
  • Hi,

    Thanks for your reply. Well i know that the code is okay but i just thought that there might be a way to make it better using Classes and Objects. I thought that I could inherited a class from this excel object and add my own functions so i don't have to repeat the code again and again for the functions. 
    Well yes i didn't put any exceptions but i will put it in due course.

    Supes
     

    Tuesday, June 20, 2006 4:39 AM
  • I wouldnt go overboard in trying to include inheritance.   You using the Excel Object model - making calls to it.   

    You dont need to use inherit Excel Model and add functions to create a easily maintainable and performing application.   You code is looking as though its simply make calls to the excel object model.    You may wrap you functionality up in a class with some methods but it is really pretty straightforward code that I think any use of inheritence would be overkill and possibly even determinental to performance.

    The excel object model is really a collection of methods in a class.   You simply calling those methods - sure youve got different arguments that you passing to them but you code is really not implementing much in the way of new functionality or an object model that is any different from the underlying functionality.

    Why do you think you need to implement OO features ?    You obviously have some ideas which is why you asked the question.

    I'd keep it as easy maintainable, straightforward code.    For something this simply theres absolutely no need to overcomplicate it for the sake of using OO features.

     

    Tuesday, June 20, 2006 5:40 AM
  • Many thanks. I just thought that I use it because i want to do some practice on how the class would be like and how the inherited class might look.. Other then that "Nothing".

    Can you elaborate on what applications i should use Inheritence and Classes?

    Cheers
    Supes
     

    Tuesday, June 20, 2006 8:23 AM
  • Hi,

    Just a quick question. You know that i'm generating a new excel file and then making the template here. Would there be a possibility to make a template in excel and then i can use that template, make a copy and then generate another file based on that template using .net?

    I didn't try it so therefore asking this question, If yes what would be the possible method or function.

    Cheers
    Supes

    Tuesday, June 20, 2006 10:08 AM