Вы находитесь на странице: 1из 16

// VB Program to demonstrate constant

Imports System.Console
Module Constant1
Sub Main()
Const pi = 3.14159
System.Console.WriteLine("Area=" & Str(pi * 10 * 10))
End Sub
End Module

// VB Program to demonstrate Enumerated data type


Module Module1
Enum Days
Sun = 1
Mon = 2
Tue = 3
End Enum
Sub Main()
System.Console.WriteLine("Monday =" & Days.Mon)
System.Console.ReadLine()
End Sub
End Module

// VB Program to demonstrate if else ladder


Imports System.Console
Module Module1
Sub Main()
Dim a, b As Integer
WriteLine("Enter two numbers")
a = ReadLine()
b = ReadLine()
If a > b Then
WriteLine("{0} is greater than {1}", a, b)
Else
If a < b Then
WriteLine("{1} is less than {0}", b, a)
Else
WriteLine("{0} is equal to {1}", a, b)
End If
End If
ReadLine()
End Sub
End Module

// VB Program to demonstrate select


Imports System.Console
Module Module1
Sub Main()
Dim a, b, k As Integer
WriteLine("Enter any two integers")
a = ReadLine()
b = ReadLine()
WriteLine("1.Addition")
WriteLine("2.Subtraction")
WriteLine("3.Multiplication")
WriteLine("4.Division")
WriteLine("Select the operation to be performed")
k = ReadLine()
Select Case k
Case 1
WriteLine("{0} + {1} is {2}", a, b, a + b)
Case 2
WriteLine("{0} - {1} is {2}", a, b, a - b)
Case 3
WriteLine("{0} * {1} is {2}", a, b, a * b)
Case 4
WriteLine("{0} / {1} is {2}", a, b, a / b)
Case Else
WriteLine("Invalid choice")
End Select
ReadLine()
End Sub
End Module

NOTE: select program to decide given character consonant or oval write by your
own.

// VB Program to demonstrate do loop


Module Module1
Sub Main()
Dim val As Integer = 1
Do
System.Console.WriteLine("Val {0}", val)
val = val + 1
If val = 5 Then
Exit Do
End If
Loop
System.Console.WriteLine("Do Until")
Do
System.Console.WriteLine("Val {0}", val)
val = val + 1
Loop Until val = 10
Do
System.Console.WriteLine("Val {0}", val)
val = val + 1
Loop While val < 20
System.Console.ReadKey()
End Sub
End Module

// VB Program to demonstrate while loop


Imports System.Console
Module Module1
Sub Main()
Dim n, x, y, r, s, k As Integer
WriteLine("ARMSTRONG SERIES")
k=1
While k < 1000
n=k
x=n
s=0
While n > 0
r = n Mod 10
y=r*r*r
s=s+y
n = n \ 10
End While
If x = s Then
WriteLine("{0} is an Armstrong number", x)
End If
k=k+1
End While
ReadLine()
End Sub
End Module

// VB Program to demonstrate for loop using factorial


Imports System.Console
Module Module1
Sub Main()
Dim f, n, i As Integer
WriteLine("Enter an Integer")
n = ReadLine()
f=1
For i = 1 To n
f=f*i
Next
WriteLine("Factorial of {0} is {1}", n, f)
ReadLine()
End Sub
End Module

// VB Program to demonstrate for loop ( Fibonacci series)


Imports System.Console
Module Module1
Sub Main()
Dim m, i, f1, f2, f3 As Integer
WriteLine("Enter number of terms")
m = ReadLine()
f1 = 0
f2 = 1
f3 = 0
WriteLine("Fibonacci series")
WriteLine(f1)
WriteLine(f2)
For i = 1 To m
f3 = f1 + f2
If f3 > m Then
Exit For
End If
WriteLine(f3)
f1 = f2
f2 = f3
Next i
ReadLine()
End Sub
End Module

// VB Program to demonstrate arrays


Module Module1
Sub Main()
Dim Iara() As Integer
Dim dara() = {1.1, 2.2, 3.3}
ReDim Iara(10)
System.Console.WriteLine("enter values of array")
For n As Integer = 0 To 9
Iara(n) = System.Console.ReadLine()
Next
For n As Integer = 0 To 9
System.Console.WriteLine("value= " + Str(Iara(n)))
Next
System.Console.WriteLine("values of compiletime declaration")
For n As Integer = 0 To 2
System.Console.WriteLine("value= " + Str(dara(n)))
Next
System.Console.Read()
End Sub
End Module

// VB Program to demonstrate double dimensional arrays


Imports System.Console
Module Module1
Sub Main()
Dim Dary()(), r, c As Integer
WriteLine("How many rows ")
r = ReadLine()
ReDim Dary(r - 1)
WriteLine("array length {0}", Dary.Length)
For i As Integer = 0 To Dary.Length - 1
WriteLine("How many Col for row {0}", i)
c = ReadLine()
ReDim Dary(i)(c - 1)
Next
WriteLine("Enter Val in to array")
For i As Integer = 0 To Dary.Length - 1
For j As Integer = 0 To Dary(i).Length - 1
Dary(i)(j) = ReadLine()
Next
Next
WriteLine("Array elements")
For i As Integer = 0 To r - 1
For j As Integer = 0 To Dary(i).Length - 1
Write(" " + Str(Dary(i)(j)))
Next
WriteLine()
Next
Read()
End Sub
End Module

// VB Program to demonstrate Functions


mports System.Console
Module Module1
Sub Main()
Dim a, b, c, r1, r2 As Integer
WriteLine("Enter a,b,c")
a = ReadLine()
b = ReadLine()
c = ReadLine()
r1 = Rootp(a, b, c)
r2 = Rootn(a, b, c)
WriteLine("roots {0}, {1}", r1, r2)
ReadLine()
End Sub
Function Rootp(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer) As
Integer
Return b + (System.Math.Sqrt((b ^ 2) - (4 * a * c)))
End Function
Function Rootn(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer) As
Integer
Return b - (System.Math.Sqrt((b ^ 2) - (4 * a * c)))
End Function
End Module

// Program to pass variable length arguments


Imports System.Console
Module Module1
Sub Main()
Dis_Mes("First Message", "KITS")
Dis_Mes("Second Message", "KITS", "Warangal")
Dim TextArray As String() = {"KITS", "Warangal", "1980"}
Dis_Mes("third Message", TextArray)
ReadKey()
End Sub
Sub Dis_Mes(ByVal Tit As String, ByVal ParamArray MesT() As String)
Dim inloop As Integer
WriteLine(Tit)
For inloop = 0 To UBound(MesT)
System.Console.WriteLine(MesT(inloop))
Next inloop
End Sub
End Module

// Program to demonstrate function overloading


Imports System.Console
Module Module1
Sub Main()
Fun1(1.1, 2.2)
Fun1(1, 2)
Fun1(1.2, 5)
ReadLine()
End Sub
Function Fun1(ByVal a As Integer, ByVal b As Integer)
WriteLine("Vals {0}, {1}", a, b)
Return 0
End Function
Function Fun1(ByVal r1 As Double, ByVal r2 As Double)
WriteLine("Vals {0}, {1}", r1, r2)
Return 0
End Function
End Module

// Program to demonstrate module property


Module Module1
Sub Main()
Module2.Prop1 = 8
System.Console.WriteLine("Prop 1 =" & Module2.Prop1)
System.Console.ReadLine()
End Sub
End Module
Module Module2
Private PropVal As String
Public Property Prop1() As String
Set(ByVal value As String)
PropVal = value
End Set
Get
Return PropVal
End Get
End Property
End Module

// Program to demonstrate string


Module Module1

Sub Main()
Dim strt As String = "welcome to kits"
Dim strt1 As String
Dim strt2, strt3 As String
Dim res, conv As Integer

strt1 = strt.ToUpper
System.Console.WriteLine("Ucase " & strt1)

strt2 = strt.Substring(1, 5)
System.Console.WriteLine("substring " & strt2)

res = String.Compare(strt, strt1)

System.Console.WriteLine("CompareMethod " & res)

conv = 200
strt3 = Str(conv)
res = Val(strt3)
System.Console.WriteLine("ValMethod " & res)
System.Console.ReadKey()
End Sub

End Module

// Program demonstrate exceptions


Module Module1
Sub Main()
Dim int1 = 5, int2 = 1, int3 As Integer
Try
int3 = 0
int3 = int2 / int1
System.Console.WriteLine("Result {0}", int3)
Throw New ArgumentOutOfRangeException()
Catch e As System.OverflowException
System.Console.WriteLine("Over flow Excetption Number = {0}, Over flow Excetption
Description = {1}", Err.Number, e.ToString)
Catch e As System.ArgumentOutOfRangeException
System.Console.WriteLine("ArgumentOutOfRangeException Number = {0},
ArgumentOutOfRangeException Description = {1}", Err.Number, e.ToString)
Finally
System.Console.WriteLine("Finally Block")
System.Console.ReadKey()
End Try
End Sub
End Module

Вам также может понравиться