Friday, May 6, 2011

VB.net Tutorial 2 : The language

Basis 

Forms

The code is very similar to the VB6 language.
For example : making a form is pretty easy :
the instruction "inherits System.windows.forms.form" is to explain that the class we create must inherit from all elements in the class "form".

Modules

 When building a new module that code is generated.
All the code contained in the module will be inserted between "Module" and "End Module"




Commentaries

Commentaires are used to add information on the code and will not be executed and removed from the final code.

To add a comment you can use the " ' " character.
example : 'this is a commentarie

Variables

Byte :  from 0 to 255

Short : from -32768 to 32767

Integer : from -2 147 483 648 to 2 147 483 647

long : from  -9223372036854775808 to 9223372036854775807

Strings


Char : used for 1 character
String : for multiples characters
to declare a variable you just have to type : Dim variablename as type

example : Dim i as integer
Dim myvar as string
Dim today as date

Arrays

Arrays can be used to store more than one information in one variable.
to declare an array the syntax is :
Dim myarray(10) as integer
to declare an array of 10 integer
to use an element of the array type : myarray(number)

example :

myarray(2)=5
mystring(1)="helloworld"
to change the size of an array, use the "redim" keyword

example :

dim foobar(10) as array 'declare an array of 10 elements
redim foobar(15) 'changes the size of the array to 15 elements
redim preserve foobar(20 'changes the size without destroying elements

Constants

Constants are usefull to store data wich is not subjet to changes.
example : dim constant = 10

Operators

To set a value to a variable, use the "=" operator
example :
dim foo as integer
foo= 4
is equivalent to
dim foo as integer=4

Other operators :

+ : addition

- : subtraction

* : multiplication

/ : division

^ : power

= : equals

<> : not equal

< : inferior

> : superior

<= : inferior or equal

>= : superior or equal

Like : for strings

No comments:

Post a Comment