Quick Reference

Use the following general syntax when assigning a variable.

Dim [Variable_Name] As [Datatype] = [Value]

______________
To print the result, we use System.Console.WriteLine(C) which will give the result on the screen

______________
if-then-else

Module Module1
    Sub Main()
        Dim mikeage, ellenage As Integer
        mikeage = 30
        ellenage = 27
        if mikeage>ellenage
then System.Console.WriteLine(mikeage)
        else
        System.Console.WriteLine(ellenage)
end if
    End Sub
End Module
___________

Switch Statements

Switch Statement sample problem

___________
For Statements
For Statement example 

________
While
While Condition example
As you recall from earlier in this unit, Dim is the statement in which we declare the value of a variable. The command given here is to print the value from 0 to 40 by adding 10 at each count. The program will print 5 times, that is 0, 10, 20, 30 and 40.

_______
Do While
Do-While Condition example

______

Pause in execution:
 System.Threading.Thread.Sleep(3000)
______
Class and Object

Module Module1
    Class arithmetical
        Public Function multiply(ByVal a As Integer, ByVal b As Integer)
            Return a * b
        End Function
    End Class

    Sub Main()
        Dim objarithmetical As New arithmetical
        Console.WriteLine(objarithmetical.multiply(198, 116542))
        Console.ReadKey()

    End Sub

End Module

_______________________

Stack:

Imports System
Imports System.Collections
Module Module1
Sub Main()
Dim mystr as New Stack()
mystr.Push("S")
mystr.Push("T")
mystr.Push("A")
mystr.Push("C")
mystr.Push("K")
Do While(mystr.count>0)
Console.WriteLine(mystr.Pop())
Loop
End Sub
End Module
 

The program should return this list.
K
C
A
T
S

_____________________

Array:


Imports System
Imports System.Collections
Module Module1
Sub Main()
Dim Students as New ArrayList()
Students.Add("William")
Students.Add("Tom")
Students.Add("Harry")
For i as Integer=0 to Students.count-1
Console.WriteLine(Students(i))
next
End Sub
End Module



_______
Hashtable:


Imports System
Imports System.Collections
Module Module1
Sub Main()
Dim Employee as New HashTable()
Employee.Add("101","James")
Employee.Add("102","Peter")
Employee.Add("103","Smith")
For each k as string in Employee.keys
Console.WriteLine(k +" " +Employee(k))
next
End Sub
End Module


Output for the above program is: 
101 James
102 Peter
103 Smith

No comments:

Post a Comment