Nothing Special   »   [go: up one dir, main page]

If Any Web Resources Required.: Sub Dim As New

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Practical No. 17: Understand the Concept of Class and Object of Class.

Practical No 17

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


 https://docs.microsoft.com/en-us/dotnet/visual-basic/language-
reference/statements/function-statement
 https://www.tutorialspoint.com/vb.net/vb.net_functions.htm

XI. Program Code


1. Write a program using the concept of class & object in VB.Net.
 Module Module1
Sub Main()
Dim obj As New Test 'creating a object obj for Test Class
obj.disp() 'Calling the disp method using obj
Console.ReadLine()
End Sub
End Module
Public Class Test
Sub disp()
Console.WriteLine("Welcome to VB.NET")
End Sub
End Class

XII. Results (output of the program)


Welcome to VB.NET

XIII. Practical related Questions


1. Find output in following code.
 4

2. Find Error in following code.


Module Module1
Sub Main()
Dim b As B = New B(5)
B = Display()

Dim c As C = New C(5)


B = Display()
End Sub
 Compilation error (line 3, col 0): Type 'B' is not defined.
Compilation error (line 4, col 0): 'Display' is not declared. It may be inaccessible due to its protectio
n level.
Compilation error (line 6, col 0): Type 'C' is not defined.
Compilation error (line 7, col 0): 'Display' is not declared. It may be inaccessible due to its protectio
n level.

GUI Application Development using VB.Net (22034) Page 1


Practical No. 17: Understand the Concept of Class and Object of Class.

XIV. Exercise
1. Write a program to identify Volume of Box Class, with three data members, length,
breadth and height.
 Module Module1
Sub Main()
Dim obj As Box = New Box()
Dim vol As Integer
vol = obj.volume(2, 4, 4)
Console.WriteLine("Length =" & obj.l)
Console.WriteLine("Breadth =" & obj.b)
Console.WriteLine("Height =" & obj.h)
Console.WriteLine("Volume =" & vol)
Console.ReadLine()
End Sub
Class Box
Public l, b, h As Integer
Function volume(ByVal i As Integer, ByVal j As Integer,
_ByVal k As Integer)
Dim v As Integer
l = i
b = j
h = k
v = l * b * h
Return v
End Function
End Class
End Module

Output:

2. Implement a program to accept values from Combo Box and Display average of this in
message box using class.

GUI Application Development using VB.Net (22034) Page 2


Practical No. 17: Understand the Concept of Class and Object of Class.

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs)


Handles MyBase.Load
ComboBox1.Items.Add(5)
ComboBox1.Items.Add(8)
ComboBox1.Items.Add(12)
ComboBox1.Items.Add(20)
ComboBox1.Items.Add(32)

ComboBox2.Items.Add(6)
ComboBox2.Items.Add(11)
ComboBox2.Items.Add(17)
ComboBox2.Items.Add(24)
ComboBox2.Items.Add(36)
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs)


Handles Button1.Click
Dim average As Single
average = (Val(ComboBox1.Text) + Val(ComboBox2.Text)) / 2
MsgBox("Average = " & average)
End Sub
End Class

OUTPUT:

GUI Application Development using VB.Net (22034) Page 3

You might also like