Professional Documents
Culture Documents
Imports system.console
Module Module1
Sub main()
Dim P_saj, r_saj, t_saj, si_saj As Double
console.writeline("Enter Principle = ")
P_saj = CDbl(console.readline())
End Sub
End Module
Module module1
Sub main()
Do
console.writeline("=====MENU=====")
console.writeline(" 3. Multiplication")
console.writeline(" 4. Division")
choice_saj = console.readline()
Case 1
console.writeline("Number 1 =")
num1 = console.Readline()
console.writeline("Number 2 =")
num2 = console.Readline()
Case 2
console.writeline("Number 1 =")
num1 = console.Readline()
console.writeline("Number 2 =")
num2 = console.Readline()
Case 3
console.writeline("Number 1 =")
num1 = console.Readline()
console.writeline("Number 2 =")
num2 = console.Readline()
Case 4
console.writeline("Number 1 =")
num1 = console.Readline()
console.writeline("Number 2 =")
num2 = console.Readline()
Case Else
console.writeline("Invaild")
Stop
End Select
End Sub
End Module
Module Do_While
Sub main()
Do
i_saj = i_saj + 1
End Sub
End Module
Module whileLoop
Sub main()
i_saj = i_saj + 1
End While
End Sub
End Module
3.3 For loop
Imports system.console
Module ForLoop
Sub main()
For i_saj = 1 To 10
Next
.
readkey()
End Sub
End Module
Imports system.console
Module For_Each_Next_saj
Sub main()
For i_saj = 0 To 4
console.writeline(arr(i_saj))
Next
console.writeline(j_saj)
Next
read()
End Sub
End Module
3.4 for loop with step
.
imports System.Console
Module module1_saj
Sub Main()
Next
Read()
End Sub
End Module
End Function
Function SubtractionOfTwo_saj(ByVal n1_saj As Integer, ByVal n2_saj As
Integer) As Integer
'define the local variable
Dim subtract_saj As Integer
subtract_saj = n1_saj - n2_saj
Return subtract_saj
End Function
Sub main()
Dim a_saj As Integer = 50
Dim b_saj As Integer = 20
Dim total_saj, totall_saj As Integer
Console.WriteLine("First Number is : {0}", a_saj)
Console.WriteLine("second Number is : {0}", b_saj)
total_saj = sumOfTwo_saj(a_saj, b_saj)
totall_saj = SubtractionOfTwo_saj(a_saj, b_saj)
Console.WriteLine("sum of two number is : {0}", total_saj)
Console.WriteLine("Substraction of two number is : {0}", totall_saj)
Console.ReadKey()
End Sub
End Module
4.2 fact
Imports System
Module factorial_function_saj
'create A fact() Function
Function fact_saj(ByVal num_saj As Integer) As Integer
If (num_saj = 0) Then
Return 0
ElseIf (num_saj = 1) Then
Return 1
Else
Return num_saj * fact_saj(num_saj - 1)
End If
End Function
Sub Main()
' define the local variable as integer
Dim n_saj, f_saj As Integer
Console.WriteLine("Enter the number you want to calculate")
n_saj = Console.ReadLine() 'accept a number
f_saj = fact_saj(n_saj) 'call fact() function
Console.WriteLine("Factorial is: {0}", f_saj)
Console.WriteLine("Press any key to exit.......")
Console.ReadKey()
End Sub
End Module
4.3 febbonaci
Imports System.Console
Module Module1
' ByVal means that you are passing a copy of a variable to your Subroutine.
Function Fibonacci(ByVal n As Integer) As Integer
Dim Value1 As Integer = 0
Dim Value2 As Integer = 1
' Add up numbers.
For i As Integer = 0 To n - 1
Dim tempValue As Integer = Value1
Value1 = Value2
Value2 = tempValue + Value2
Next
Return Value1
End Function
Sub Main()
For i As Integer = 0 To 20
Console.Write(Fibonacci(i))
Console.Write(" ")
Next
End Sub
End Module
Sub Main()
Dim a_saj, b_saj, rad_saj As Integer
sample() 'calling function sample
console.writeline("Plz Enter the first number = ")
a_saj = console.Readline()
console.writeline("Enter second number = ")
b_saj = console.Readline()
SumOfTwo_saj(a_saj, b_saj)
SubtractionOfTwo_saj(a_saj, b_saj)
Multiplication_saj(a_saj, b_saj)
End Sub
End Module
Sub main()
Dim n_saj(10) As Integer ' n is an array of 11 integers '
Dim i_saj, j_saj As Integer
' initialize elements of array n '
For i_saj = 0 To 10
n_saj(i_saj) = i_saj + 100 ' set element at location i to i + 100
Next i_saj
' output each array element's value '
For j_saj = 0 To 10
Console.WriteLine("Element({0}) = {1}", j_saj, n_saj(j_saj))
Next j_saj
Console.ReadKey()
End Sub
End Module
2-D Array
Imports System
Module TwodimenArray_saj
Sub Main()
' Definition of 2 Dimensional Array
Dim intArray_saj(,) As Integer = {{5, 4}, {3, 2}, {4, 7}, {4, 5}}
Console.WriteLine(" Two Dimensional Arraye in VB.NET are")
For i_saj As Integer = 0 To 3
For j_saj As Integer = 0 To 1
Console.WriteLine("intArray[{0}, {1}] = {2}", i_saj, j_saj,
intArray_saj(i_saj, j_saj))
Next j_saj
Next i_saj
End Sub
End Module
3-D Array
Imports system.console
Module Module1 'Assignment no. 5 -->Multi-D array
Sub Main()
Dim array3D_saj As Integer(,,) = New Integer(1, 1, 2) {{{1, 2, 3}, {4, 5,
6}}, {{7, 8, 9}, {10, 11, 12}}}
Console.WriteLine("---Three Dimensional Array Elements---")
Next
Next
Next
Console.WriteLine("Press Enter Key to Exit..")
Console.ReadLine()
End Sub
End Module
Imports system.console
Module Modiule1
Sub division(ByVal num1_saj As Integer, ByVal num2_saj As Integer)
Dim result_saj As Integer
Try
result_saj = num1_saj \ num2_saj
Catch e_saj As DivideByZeroException
Console.WriteLine("Exception caught: {0}", e_saj)
Finally
Console.WriteLine("Result: {0}", result_saj)
End Try
End Sub
Sub Main()
division(16, 0)
Console.ReadKey()
End Sub
End Module
7.2 User define Exception
Module exceptionProg
Public Class TempIsZeroException : Inherits ApplicationException
Public Sub New(ByVal message As String)
MyBase.New(message)
End Sub
End Class
Public Class Temperature
Dim temperature_saj As Integer = 0
Sub showTemp()
If (temperature_saj = 0) Then
Throw (New TempIsZeroException("Zero Temperature found"))
Else
Console.WriteLine("Temperature: {0}", temperature_saj)
End If
End Sub
End Class
Sub Main()
Dim temp_saj As Temperature = New Temperature()
Try
temp_saj.showTemp()
Catch e As TempIsZeroException
Console.WriteLine("TempIsZeroException: {0}", e.Message)
End Try
Console.ReadKey()
End Sub
End Module