Teach yourself the visual basic .net Language
Teach yourself the visual basic .net Language
A Brief History of BASIC
· The BASIC language was developed in the early 1960's at Dartmouth
College as a device for teaching programming to “ordinary” people. There is a reason it’s called BASIC:
B (eginner's)
A (All-Purpose)
S (Symbolic)
I (Instruction)
C (Code)
·
When timesharing systems were
introduced in the 1960’s, BASIC was the language of choice. Many of the first computer simulation games
(Star Trek, for example) were written in timeshare BASIC.
·
In the mid-1970's, two college
students decided that the new Altair microcomputer needed a BASIC language
interpreter. They sold their product on
cassette tape for a cost of $350. You
may have heard of these entrepreneurs:
Bill Gates and Paul Allen!
·
Every BASIC written since then
has been based on that early version.
Examples include: GW-Basic,
QBasic, QuickBasic. All the toy
computers of the early 80’s (anyone remember TI99/4A, Commodore 64, Timex,
Atari 400?) used BASIC for programming.
· Visual Basic (allowing development of Windows applications) was
first introduced in 1991. The latest
(and last) version of Visual Basic is Version 6.0, which was released in 1997.
·
Visual Basic .NET still uses
the BASIC language to write code. Visual
Basic .NET provides a long overdue enhancement to the language with many new
features. In addition, many archaic
features than have been around since Bill and Paul’s earliest efforts have
finally been retired. This chapter
provides an overview of the BASIC language used in the Visual Basic .NET
environment. If you’ve ever used another
programming language (or some version of BASIC), you will see equivalent
structures in the language of Visual Basic .NET.
Visual Basic .NET Statements
and Expressions
· The simplest (and most common) statement in Visual Basic .NET is the
assignment statement. It consists of a variable name, followed by
the assignment operator (=), followed by some sort of expression. The expression on the right hand side is
evaluated, then the variable (or property) on the left hand side of the
assignment operator is replaced by that value of the expression.
Examples:
StartTime = Now
lblExplorer.Text = "Captain
Spaulding"
BitCount = ByteCount * 8
Energy = Mass * LIGHTSPEED ^ 2
NetWorth = Assets - Liabilities
The assignment
statement stores information.
·
Statements normally take up a
single line with no terminator.
Statements can be stacked by
using a colon (:) to separate
them. Example:
StartTime = Now : EndTime = StartTime + 10
The above code
is the same as if the second statement followed the first statement. Be careful stacking statements, especially
with If/End If structures (we’ll learn about these soon). You may not get the response you desire. The only place we tend to use stacking is for
quick initialization of like variables.
·
If a statement is very long, it
may be continued to the next line using the continuation character, an underscore (_). Example:
Months = Math.Log(Final * IntRate / Deposit + 1) _
/ Math.Log(1 + IntRate)
We don’t use
continuation statements very much in these notes or in our examples. Be aware that long lines of code in the notes
many times wrap around to the next line (due to page margins).
·
Comment statements begin with
the keyword Rem or a single quote (').
For example:
Rem This is a remark
' This is also a remark
x = 2 * y ' another way to write a remark or
comment
You, as a
programmer, should decide how much to comment your code. Consider such factors as reuse, your
audience, and the legacy of your code.
In our notes and examples, we try to insert comment statements when
necessary to explain some detail.
Strict Type
Checking
·
In each assignment statement,
it is important that the type of data on both sides of the operator (=)
is the same. That is, if the variable on
the left side of the operator is an Integer, the result of the
expression on the right side should be Integer.
·
Visual Basic .NET (by default)
will try to do any conversions for you.
Sometimes, however, it ‘guesses’ incorrectly and may provide incorrect
or undesired results. To insure consistency
of data types in assignment statements, Visual Basic .NET offers, as an option,
strict type checking.
What this means is that your program will not run unless each side of an
assignment operator has the same type of data.
With strict type checking, the Intellisense feature of the Code window
will identify where there are type inconsistencies and provide suggestions on
how to correct the situation.
·
Strict type checking will force
you to write good code and eliminate many potential errors. Because of this, all examples for the
remainder of this course will use strict type checking. To turn on strict type checking, we place a
single line of code at the top of each application:
Option Strict On
This line
will go right below the Option
Explicit On line which forces us to declare each
variable we use. ..........
Teach yourself the visual basic .net Language
0 commentaires: