The Book of Visual Studio .NET - A Visual Basic .NET Crash Course
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
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.
#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.
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() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() '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 components.Dispose() End If End If MyBase.Dispose(disposing) 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