Title: Microsoft Visual Basic 'NET Language
1MicrosoftVisual Basic .NETLanguage 1
2Variable
- Declaring Variable
- Dim VariableName As Type
- Dim VariableName As Type value
Example Dim var1 As String Dim Var2, Var3,
Var4 As String
Example Dim var1 As String "Hello World"
3Data Types
- Five Categories
- Numeric
- Boolean
- String
- Date
- Object
- Integrated in the common language runtime
- 2 Varieties of Data Types
- Value Types
- Reference Types
4Numeric Data Types
5Not Number Data Types.
- Boolean
- True / False
- String
- Store only text data.
- Character
- Store only one character.
- DateTime
- Store Date and Time Data.
Example Var1 01/01/2003 Var2 "Sep
1,1977" Var3 01/01/2003 62511 PM Var4
Now()
6Value Types (Numeric, Boolean, String, Date)
- Store Data in Stack Memory
Stack Memory (LastInFirstOut)
Function A Dim Var1 As String "AAA" Call
B End Function Function B Dim Var2 As String
"BBB" Call C End Function Function C Dim Var3
As String "CCC" End Function
Var3"CCC"
Var2"BBB"
Var1"AAA"
7Reference Types (Object)
- Store Variable in Stack Memory
- Store Data in Heap Memory
GC
Function A Dim Var1 As ObjA Var1 New
ObjA Var1.Data "ZZZ" End Function
Heap Memory
ObjA
Stack Memory
Data "ZZZ"
Var1
8Data Type Functions
- GetType( Variable )
- IsNumeric( Variable )
- IsDate( Variable )
- IsReference( Variable )
- Conversion Data Types
9Parse Method
- To convert a numeric string to a numeric or
others, use the Parse method - To Ignore Commas, Use the NumberStyles.AllowThousa
nds Flag
Dim MyString As String 12345 Dim MyInt As
Integer Integer.Parse(MyString) MyInt
1 Console.WriteLine(MyInt) The output to the
console is 12346
Dim MyString As String 123,456 Dim MyInt As
Integer Integer.Parse(MyString,
_ Globalization.NumberStyles.AllowThousands) Conso
le.WriteLine(MyInt) The output to the console
is 123456
10Constant
- Once a constant has been declared
- Cannot change value.
- Process faster than variable.
- Const ConstantName As Type Value
Example Const pi As Double 3.14159265358979
11Array
- Set of data which have the same type.
- Zero based.
- Declaring Array
Dim MyString (5) As String MyString(3) "Happy"
Dim str as String str MyString(3) str "Happy"
12String
- Trim method
- remove spaces
- Pad method
- Expand a specific number of characters
Dim MyString As String Big Dim TrimString
As String MyString.Trim() Console.WriteLine(Trim
String) The output to the console is Big
Dim MyString As String Hello
World! Console.WriteLine(MyString.PadLeft(20,
-)) The output to the console is
--------Hello World!
13Changing Case
- Methods that compare strings and characters are
case-sensitive - Convert the case of strings that are entered by
users before comparing them - To change the case of a string use
- String.ToUpper
- String.ToLower
Dim MyString As String hello
world! Console.WriteLine(MyString.ToUpper()) The
output to the console is HELLO WORLD!
Dim MyString As String HELLO
WORLD! Console.WriteLine(MyString.ToLower()) The
output to the console is hello world!
14Split and Join
- Split method breaks up a string into an array of
substrings - String is broken at positions indicated by the
specified separator characters parameter - If the separator parameter is Nothing, the
white-space characters are assumed to be the
separator - Join method concatenates a specified separator
between string array - A specified separator string is placed between
each element of a string array
Dim Line As String hello world Dim Words() As
String Line.Split( ) Words(0) hello and
Words(1) World
Dim MyString() As String apple, orange,
grape, pear Dim JoinString as String
String.Join(/, MyString, 0, 3) JoinString
apple/orange/grape
15Length and IndexOf
- Length Method
- Gets the number of characters in this instance
- IndexOf Method
- Reports the index of the first occurrence of a
string or one or more characters, within this
instance.
Dim MyString As String Hello
World! Console.WriteLine(MyString.Length()) The
output to the console is 12
Dim MyString As String Hello
World! Console.WriteLine(MyString.IndexOf(or)
The output to the console is 7
16Operators
- Arithmetic Operators
- - / - /
- A 2 3 B 5 C B / 2
- String Operators
-
- Message "Hello " Name
- Boolean Operators
- lt gt lt gt ltgt
- And Or Not AndAlso OrElse
- If A5 AndAlso Bgt6 Then