January 27, 2021
Hot Topics:

The Book of Visual Studio .NET - A Visual Basic .NET Crash Course

  • By Developer.com Staff
  • Send Email »
  • More Articles »


Classic Visual Basic allowed developers to create their own data types called User Defined Data Types or UDTs, which were implemented using the Type keyword. Visual Basic .NET has retired the Type keyword and replaced it with the keyword Structure, like so:

Public Structure Person
Dim strFirstName as String
Dim strLastName as String
End Struct

Variable Scope

All variables have a predefined scope that is assigned during initialization. Listed below are a few of the most common scope declarations and their definitions.

  • Private scope: Defines a variables scope as restricted to the current method. A variable defined as having private scope is referred to as a member variable and is commonly prefixed with an "m".
  • Public scope: Allows the parent class, or calling class, access to the data held by a public variable or method.
  • Friend scope: Similar to public scope as far as all code within a project is concerned. The difference between the public scope and friend scope is that variables or methods that are defined with the friend scope cannot be accessed by a parent class outside of the project.
  • Protected scope: A new scope declaration that allows access to classes that inherit from the variables class.


The #Region directive allows you to organize your code into collapsible blocks which help to make the code window easier to work with by displaying only those functions you are working with. Each region can be defined with a name helping each region to be more easily identifiable, as shown here

#Region "MyRegion"
'some code
#End Region

When you are done writing "some code," you can collapse the region and begin working on the next segment of code.

Windows Forms

Visual Basic .NET implements Windows Forms as classes that inherit windows functionality from the Form class found in the System.Windows.Forms namespace. Developing Win32 applications in Visual Basic .NET is still very similar to classic Visual Basic windows development in that windows controls can be dragged and dropped onto the form designer. The difference is that none of the implementation code is hidden.

For example, here's the implementation code for the Windows Form discussed in the previous example of the StringBuilder class. While this type of code must be implemented in classic Visual Basic forms, it is hidden. As you can see, the code is no longer hidden; however, I would strongly recommend leaving this code alone unless you really know what you are doing and have a specific need to fill. Take a look at t he code below and notice that the entire form is actually a class that inherits the System.Windows.Forms.form class. As mentioned earlier in this book, everything in .NET is a class. There are no exceptions.

Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
'This call is required by the Windows Form Designer.
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
End If
End If
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
End Sub
#End Region
End Class

The implementation code for all the controls on the form were stored in the "Windows Form Designer generated code" region. (This information has been removed so you won't be distracted from the Windows Form's own implementation.)

Page 3 of 5

This article was originally published on January 15, 2003

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date