Visual Basic 2008 9.0 .NET Examples and Ebook

Introduction to Visual Basic

Vorig Onderwerp

New in Visual Basic 2008 - 9.0

|

Arrays

Volgend Onderwerp

Output and Comments in Modules

Vorig Onderwerp

LINQ - Language Integrated Query

|

Variables

Volgend Onderwerp
Hello World

Hello World

Comments

Comments

Modules

Modules

Identifiers and Keywords

Identifiers and Keywords

Procedures

Procedures

Output

Output

Input

Input

Strings and Literals

Strings and Literals



Hello World


Following example will bring the text "Hello World" to the console.


Module Example                                                             ' (1)
    Sub Main()                                                             ' (2)
        ' following instruction writes some text to the console            ' (3)
        Console.WriteLine("Hello World !")                                 ' (4)
        '
        Console.ReadLine()                                                 ' (5)
    End Sub                                                                ' (6)
End Module                                                                 ' (7)
Download Broncode

Output :

 Hello World !

Klik hier om terug naar boven te gaan.  Up



Comments


Each line beginning with a single quote ( ' ) (3) is a comment line. These lines are ignored by the compiler, and will not alter the programs execution.


Visual Studio : When default settings are used, comments are shown green.


REM ( abbreviation for remark ) is an alternative for the single quote : REM This is a comment line.


Klik hier om terug naar boven te gaan.  Up



Modules


A module is a simple code block in which we write our sourcecode. Our sourcecode is written between Module (1) and End Module.


Visual Studio : To start a module in Visual Studio, you can click "Debug" and "Start Debugging".


Klik hier om terug naar boven te gaan.  Up


Identifiers and Keywords


Each module has a name, also called the identifier. For each module we can choose an identifier.
Certain rules for identifier have to followed :
- One word, no spaces can be used.
- The identifier has to be unique. For example each module in a certain projects has to have a different name.
- The characters a to z, A to Z, 0 to 9 and an underscore ( _ ) can be used.
- The identifier may not start with a number.
- The identifier can not be a reserved keyword. These are used in the language for specific constructions. The compiler wouldn't interpret these as identifiers, except when we put them between brackets. For example, 'Module' (1), 'Sub' (2) and 'End' (6)(7) are reserved words, which can not be used as an identifier. But '[Module]' would be understood by the compiler as an identifier.


Visual Studio : When default settings are used for the editor, keywords are shown in blue.


Klik hier om terug naar boven te gaan.  Up


Procedures


The above module Example has a procedure with the identifier Main.

In a procedure we can write a algorithm to perform a certain routine.

A procedure starts with Sub (2) and ends with End Sub (6).

More than one procedures can be added to a module, but the execution of the program can only start with one procedure, this is always the Main procedure.


Klik hier om terug naar boven te gaan.  Up


Output


Console.WriteLine() will write the value expressed between the parentheses to the console.


Klik hier om terug naar boven te gaan.  Up


Input


After executing the code in the Main procedure the application is ended, and the console is closed. To avoid closing the console we can put a
Console.ReadLine() at the end of the Main procedure. This will give us the opportunity to see what output we have on the console.
Console.ReadLine() will read a line from the console. A line consists of zero or more characters ended with an endline character. When the input is coming from the user, the endline is formed by pressing the "Enter" key.
Only after the user presses "Enter" the program will continue with the instructions after Console.ReadLine(). When there are no following instructions ( like in the above example ), the program ( and console ) will close.


Klik hier om terug naar boven te gaan.  Up


Strings and Literals


The above example will always bring the text "Hello World !" to the console.
This text is constant, and will not vary at runtime. To express this text ( also called "string" ), we can use constant expressions, like "string literals", which are surrounded with double quotes ( "..." ).


Visual Studio : When default settings are used, string literals are shown in red.





This version ( published on 2008-06-24 ) is printed from http://www.studyvb.com, visit the website for more recent information.

Updated On : 2008-02-11

Download Broncode

Published On : 2008-06-24

Output and Comments in Modules

Vorig Onderwerp

LINQ - Language Integrated Query

|

Variables

Volgend Onderwerp

Introduction to Visual Basic

Vorig Onderwerp

New in Visual Basic 2008 - 9.0

|

Arrays

Volgend Onderwerp
Nederlands  Nederlands

Add to favorites (IE).