When you ask a question like that you are going to get as many different opinions as you have people responding. Everyone has their own style of coding and even that style can evolve. See Not Invented Here for an example. Please keep in mind that the following reflects my style (and opinion) only. It is not my intention to trash your code or your style. We all start at a certain level and we all (I hope) strive to improve. There are far better programmers out there than I am so there is much room for improvement in my code as well.
But you asked for comments so here goes. I'll start with the aesthetic because I believe that code should be pleasing to the eye and easy to read as well as functional.
Put a header at the top of your main module. My headers look like this:
'
' Name:
'
' appname
'
' Description:
'
' A short description of what the program does.
'
' Usage:
'
' If the usage is not obvious this should give some details. If it is a console
' app then this section should explain what the parameters are.
'
' Notes:
'
' If the program requires any addition components, or particular versions of
' components then this should be detailed here.
'
' Audit:
'
' 2012-02-12 my name - original code (provide summary of changes with dates)
' Use white space (blank lines) to separate your code into blocks. When writing prose, writers separate blocks of related ideas into paragraphs. This makes the prose flow more naturally and makes it easier to read. In technical writing, the first sentence in a paragraph acts as an introduction to the idea being explored in that paragraph. Similarly, a block of code should usually have a comment indicating what that block does.
A comment should explain what, and possibly how and why (if necessary). A useful comment is "update the counter of how many objects are allocated". A useless comment is "add 1 to x".
Each function and sub should have a mini-header.
All controls (other than static labels) should have a name that describes the purpose of that control. "Button1" is a bad name. "btnGenStats" is a better name because the function is alluded to by the name, and someone reading the code can tell that the code refers to a button (btn prefix) control. Also, if you have many buttons (for example) with names like Button1, Button2, etc, you are more likely to make a mistake (change the code for the wrong button).
Variable names should be descriptive, especially as the scope increases. A variable that has limited scope (such as a loop index) can be short. For example
For i As Integer = 0 to 20
.
.
.
Next "i" has scope only for the duration of the loop. Avoid variables like m1, m2, m3, etc. This says to the world "I am an engineer". Variables should be declared one per line with a short comment on that same line as in:
Private Authors As TreeNode 'all authors are added under this node
Private Library As String 'the fully qualified name of the active library
Private LogFile As String 'file for audit trail of all library operations Use Select clauses where appropriate. For example
If tbRest.Text = t1 Then
My.Computer.Audio.Play(My.Resources.bell, AudioPlayMode.Background)
ElseIf tbRest.Text = m1 Then
tbMins.Text = tbMins.Text + i1
ElseIf tbRest.Text = m2 Then
tbMins.Text = tbMins.Text + i1
ElseIf tbRest.Text = m3 Then
tbMins.Text = tbMins.Text + i1
ElseIf tbRest.Text = m4 Then
tbMins.Text = tbMins.Text + i1
ElseIf tbRest.Text = t2 Then
My.Computer.Audio.Play(My.Resources.bell, AudioPlayMode.Background)
tbMins.Text = tbMins.Text + i1
ElseIf tbRest.Text = t3 Then
My.Computer.Audio.Play(My.Resources.bell, AudioPlayMode.Background)
tbMins.Text = tbMins.Text + i1
End If should be rewritten as
Select Case tbRest.Text
Case t1
My.Computer.Audio.Play(My.Resources.bell, AudioPlayMode.Background)
Case m1
tbMins.Text = tbMins.Text + i1
Case m2
tbMins.Text = tbMins.Text + i1
Case m3
tbMins.Text = tbMins.Text + i1
Case m4
tbMins.Text = tbMins.Text + i1
Case t2
My.Computer.Audio.Play(My.Resources.bell, AudioPlayMode.Background)
tbMins.Text = tbMins.Text + i1
Case t3
My.Computer.Audio.Play(My.Resources.bell, AudioPlayMode.Background)
tbMins.Text = tbMins.Text + i1
End Select And because you have used very non-descriptive variable names like m1, etc. you should put an inline comment on each case statement to explain that case. Incidentally, none of your sections (in the first or second version) will ever be executed because you are comparing a string (tbRest.Text) to integers.
How's that for starters? Discouraged yet? (don't be)
Incidentally, I have my IDE set so that comments are displayed with black letters on a silver-grey background. This makes the comments stand out. With properly written comments it is easier to read just the comments and ignore the code (until later). And, if you comment out a large block of code it is really obvious. I once had to determine the function of a twenty page block of FORTRAN code. It would have been easier had I noticed that pages 4-12 had been commented out with a block comment. If my editor (back in 1985) had supported syntax colouring it would have been obvious.