Visual Basic .NET Comments

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This lesson explains the comments in Visual Basic .NET

The comments are one of the few typographic code elements that make a programs structure a bit easier to understand.
They do not execute and they are ignored by the compiler but are an important part of how you organize your code.

Generally speaking, comments can help you as well as other developers (at a later date) to understand the code purpose.

The comment starts with a single quotation mark (') and everything until the end of the line is part of the comment and as mentioned ignored by Visual Basic.

NOTE: you cannot use line continuation characters to make a multi-line comment nor you can have block comment as they are not supported in VB.NET

If you want to comment or uncomment a large block of code quickly, just select the code and then open Edit > Advanced > Comment Selection and Uncoment Slection respectively.

You should always use comments to make your code clear and understandable.

                        ' checking if the username and password are valid
                        If Username.Text = "admin" AndAlso Password.Text = "mypwd" Then
                            Dim mForm As Form = MainForm ' instantiate the MainForm
                            mForm.ShowDialog() ' display the main form
                            Me.Close() ' close the login form
                            ' incorrect username or password provided
                            Username.Text = String.Empty ' reset the username textbox
                            Password.Text = String.Empty ' reset the password textbox
                            ' let them know that username or password is incorrect 
                            MessageBox.Show("Incorrect username or password. Please try again!")
                        End If

Previous Lesson | Next Lesson

Share This

Home | About | Contact | Privacy Policy

Copyright 2017 - All Rights Reserved.