locked
Code snippet evaluation RRS feed

  • Question

  • Hi to all!
    I've recently decided to take a huge leap and migrate from my good old VB 6.0 to VB.NET, since VB 6.0 was proved to be fairly insufficient for my needs. So, I took a deep breath, loaded myself with a lot of patience and...here I am!The transition from VB 6.0 code to VB.NET seemed quite buffling in the beginning, but later on it proved to be pretty straightforward.So, now, I've decided to get my feet wet and develope my first VB.NET appication.The reason I'm here is that I would like an evaluation of my first code snippet in terms of efficiency, productivity and so on.
    A description of what I'm doing is this:
    On a Windows form, docked at the left side, I have a panel set to AutoScroll. Inside it I've placed a number of panels, each one with a ToolStrip, having a button to collapse or expand the panel.It works so far, but I don't know how efficient my code is. Here is the code of a generic Click Event that handles the clicks of all toolstrip buttons.Each button has a Tag to indicate the state (expanded or collapsed) and each panel has a numeric tag for the height it would have when expanded.
    Here is the code.

    Private Sub ButtonClick(ByVal sender As System.ObjectByVal e As System.EventArgs) _ 
                              Handles TSB_1.Click, TSB_2.Click, TSB_3.Click, TSB_4.Click, _ 
                                      TSB_5.Click, TSB_6.Click 
        'Expand/Collapse button clicks 
        '----------------------------- 
        'Get current button 
        Dim oButton As ToolStripButton = CType(sender, System.Windows.Forms.ToolStripButton) 
        Dim iNum As Integer = Microsoft.VisualBasic.Right(oButton.Name, 1) 
        Dim oPanel As Panel 
        Dim oContr As Control 
        'Get associated panel 
        For Each oContr In pnlSideBar.Controls 
          If TypeOf oContr Is Panel Then 
            If oContr.Name = "Panel" & iNum.ToString Then 
              oPanel = oContr 
              Exit For 
            End If 
          End If 
        Next 
        'Change button and panel attributes 
        If oButton.Tag = 0 Then 
          With oButton 
            .Tag = 1 
            .Image = My.Resources.EXPAND 
            .ToolTipText = "Expand" 
          End With 
          oPanel.Height = 22 
        Else 
          With oButton 
            .Tag = 0 
            .Image = My.Resources.COLLAPSE 
            .ToolTipText = "Collapse" 
          End With 
          oPanel.Height = Integer.Parse(oPanel.Tag) 
        End If 
     
        oButton = Nothing 
        oPanel = Nothing 
        oContr = Nothing 
      End Sub 
     
    So...what I would like to have is an evaluaion of this small code. It seems to be a bit larger than the code I could write in VB 6.0 and I'm sure that there is a better way.What would you say?
    Thank's in advance and hope to see you soon!


    Thursday, February 5, 2009 1:57 PM

Answers

  • Dear Geysser,
    This forum is for feedback on the Microsoft Genuine Advantage program, not for code evaluation. I suggest you look into Technet and the Technet Community Forums.

    Regards,
    Jenifer
    • Marked as answer by JeniferA Friday, February 6, 2009 5:39 PM
    Friday, February 6, 2009 5:39 PM