Академический Документы
Профессиональный Документы
Культура Документы
A Visual Basic program is built up from standard building blocks. A solution comprises one
or more projects. A project in turn can contain one or more assemblies. Each assembly is
compiled from one or more source files. A source file provides the definition and
implementation of classes, structures, modules, and interfaces, which ultimately contain all
your code.s.
1. Option statements
2. Imports statements
3. Namespace statements and namespace-level elements
A program can also contain conditional compilation statements. You can intersperse these in
the source file among the statements of the preceding sequence.
Option Statements
Option statements establish ground rules for subsequent code, helping prevent syntax and
logic errors. The Option Explicit Statement ensures that all variables are declared and spelled
correctly, which reduces debugging time. The Option Strict Statement helps to minimize
logic errors and data loss that can occur when you work between variables of different data
types. The Option Compare Statement specifies the way strings are compared to each other,
based on either their Binary or Text values.
Imports Statements
You can include an Imports Statement (.NET Namespace and Type) to import names defined
outside your project. An Imports statement allows your code to refer to classes and other
types defined within the imported namespace, without having to qualify them. You can use as
many Imports statements as appropriate. For more information, see References and the
Imports Statement.
Namespace Statements
Namespaces help you organize and classify your programming elements for ease of grouping
and accessing. You use the Namespace Statement to classify the following statements within
a particular namespace. For more information, see Namespaces in Visual Basic.
Class Statement
Structure Statement
Module Statement
Interface Statement
Function Statement
Sub Statement
Declare Statement
Operator Statement
Property Statement
Event Statement
Data elements at module level are variables, constants, enumerations, and delegates.
Data elements at procedure level are limited to local variables and constants.
Sub Main()
Sub Main(ByVal cmdArgs() As String)
Function Main() As Integer
Function Main(ByVal cmdArgs() As String) As Integer
The most common variety of this procedure is Sub Main(). For more information, see Main
Procedure in Visual Basic.
Following is the general form of a typical decision making structure found in most of the
programming languages −
VB.Net provides the following types of decision making statements. Click the following links
to check their details.
Statement Description
iVB.Net - Statements
A statement is a complete instruction in Visual Basic programs. It may contain keywords,
operators, variables, literal values, constants and expressions.
Declaration statements − these are the statements where you name a variable,
constant, or procedure, and can also specify a data type.
Executable statements − these are the statements, which initiate actions. These
statements can call a method or function, loop or branch through blocks of code or
assign values or expression to a variable or constant. In the last case, it is called an
Assignment statement.
Declaration Statements
The declaration statements are used to name and define procedures, variables, properties,
arrays, and constants. When you declare a programming element, you can also define its data
type, access level, and scope.
The programming elements you may declare include variables, constants, enumerations,
classes, structures, modules, interfaces, procedures, procedure parameters, function returns,
external procedure references, operators, properties, events, and delegates.
Executable Statements
An executable statement performs an action. Statements calling a procedure, branching to
another place in the code, looping through several statements, or evaluating an expression are
executable statements. An assignment statement is a special case of an executable statement.
VB.Net - Loops
There may be a situation when you need to execute a block of code several number of times.
In general, statements are executed sequentially: The first statement in a function is executed
first, followed by the second, and so on.
Programming languages provide various control structures that allow for more complicated
execution paths.
A loop statement allows us to execute a statement or group of statements multiple times and
following is the general form of a loop statement in most of the programming languages −
VB.Net provides following types of loops to handle looping requirements. Click the
following links to check their details.
VB.Net provides the following control statements. Click the following links to check their
details.
VB.Net - Strings
In VB.Net, you can use strings as array of characters, however, more common practice is to
use the String keyword to declare a string variable. The string keyword is an alias for the
System.String class.
VB.Net - Constants
The constants refer to fixed values that the program may not alter during its execution. These
fixed values are also called literals.
Constants can be of any of the basic data types like an integer constant, a floating constant, a
character constant, or a string literal. There are also enumeration constants as well.
The constants are treated just like regular variables except that their values cannot be
modified after their definition.
Declaring Constants
In VB.Net, constants are declared using the Const statement. The Const statement is used at
module, class, structure, procedure, or block level for use in place of literal values.
VB.Net - Variables
A variable is nothing but a name given to a storage area that our programs can manipulate.
Each variable in VB.Net has a specific type, which determines the size and layout of the
variable's memory; the range of values that can be stored within that memory; and the set of
operations that can be applied to the variable.
We have already discussed various data types. The basic value types provided in VB.Net can
be categorized as −
Type Example
SByte, Byte, Short, UShort, Integer, UInteger, Long, ULong and
Integral types
Char
Floating point types Single and Double
Decimal types Decimal
Boolean types True or False values, as assigned
Date types Date
Multiple-Document Interface (MDI)
Applications
Multiple-document interface (MDI) applications enable you to display multiple documents at the
same time, with each document displayed in its own window. MDI applications often have a
Window menu item with submenus for switching between windows or documents.
3. From the Toolbox, drag a MenuStrip control to the form. Create a top-level menu
item with the Text property set to &File with submenu items called &New and
&Close. Also create a top-level menu item called &Window.
The first menu will create and hide menu items at run time, and the second menu will
keep track of the open MDI child windows. At this point, you have created an MDI
parent window.
4. Press F5 to run the application. For information about creating MDI child windows
that operate within the MDI parent form
In the following procedure, you will create MDI child form that displays a RichTextBox
control, similar to most word-processing applications. Substituting the
System.Windows.Forms control with other controls, such as the DataGridView control, or a
mixture of controls enables you to create MDI child windows (and, by extension, MDI
applications) with diverse possibilities.
Note
The dialog boxes and menu commands you see might differ from those described in Help
depending on your active settings or edition. To change your settings, choose Import and
Export Settings on the Tools menu. For more information, see Personalize the Visual Studio
IDE.
1. Create a new Windows Forms project. In the Properties Windows for the form, set
its IsMdiContainer property to true, and its WindowsState property to Maximized.
2. From the Toolbox, drag a MenuStrip control to the form. Set its Text property to
File.
3. Click the ellipses (…) next to the Items property, and click Add to add two child tool
strip menu items. Set the Text property for these items to New and Window.
4. In Solution Explorer, right-click the project, point to Add, and then select Add New
Item.
5. In the Add New Item dialog box, select Windows Form (in Visual Basic or in Visual
C#) or Windows Forms Application (.NET) (in Visual C++) from the Templates
pane. In the Name box, name the form Form2. Click the Open button to add the form
This form will be the template for your MDI child forms.
This causes the RichTextBox control to completely fill the area of the MDI child
form, even when the form is resized.
8. Double click the New menu item to create a Click event handler for it.
9. Insert code similar to the following to create a new MDI child form when the user
clicks the New menu item.
10. In the drop-down list at the top of the Properties window, select the menu strip that
corresponds to the File menu strip and set the MdiWindowListItem property to the Window
ToolStripMenuItem.
This will enable the Window menu to maintain a list of open MDI child windows with a
check mark next to the active child window.
11. Press F5 to run the application. By selecting New from the File menu, you can create
new MDI child forms, which are kept track of in the Window menu item.