You are on page 1of 11

Functions

Public Class Form1


Function Are(ByRef Length As Integer, ByRef Width As
Integer) As Integer
Return (Length * Width)
End Function
Function charg(ByRef Area As Integer) As Decimal
Return (Area * 2)
End Function
Function Expense(ByRef Area As Integer) As Decimal
Return (Area * 0.25)
End Function

Private Sub Button1_Click(sender As Object, e As


EventArgs) Handles Button1.Click
Dim Area As Integer
Dim Len As Integer
Dim Wid As Integer
Len = InputBox("Enter Length")
Wid = InputBox("Enter Width")
Area = Are(Len, Wid)
MsgBox("The area of the farm is" & vbTab & Area)
End Sub

Private Sub Button2_Click(sender As Object, e As


EventArgs) Handles Button2.Click
Dim Charge As Decimal
Dim Area As Integer
Charge = charg(Area)
MsgBox("The charge for tilling the farm is $ " &
Charge)
End Sub

Private Sub Button3_Click(sender As Object, e As


EventArgs) Handles Button3.Click
Dim expenses As Decimal
Dim Area As Integer
expenses = Expense(Area)
MsgBox("The farm expenses are $ " & expenses)
End Sub
End Class
PROCEDURES

Public Class Form1


Sub eArea(ByRef L As Integer, ByRef H As Integer)
Dim eArea As Integer
eArea = L * H
MsgBox("The area is" & eArea)
End Sub
Private Sub Button1_Click(sender As Object, e As
EventArgs) Handles Button1.Click
Dim iL, iW As Integer
iL = InputBox("Enter length")
iW = InputBox("enter width")
eArea(iL, iW)
End Sub
End Class

Public Class Form1


Public Sub iTax(ByRef Hvalue As Decimal, ByRef Tax As
Decimal)
Dim iTax As Decimal
iTax = Hvalue * Tax
TextBoxT.Text = iTax
End Sub
Private Sub Button1_Click(sender As Object, e As
EventArgs) Handles Button1.Click
Dim hvalue1, itax1 As Decimal
hvalue1 = TextBoxH.Text
If hvalue1 > 200000 Then
itax1 = 0.02
iTax(hvalue1, itax1)
ElseIf hvalue1 > 100000 And hvalue1 <= 200000 Then
itax1 = 0.015
iTax(hvalue1, itax1)
ElseIf hvalue1 > 50000 And hvalue1 <= 100000 Then
itax1 = 0.01
iTax(hvalue1, itax1)
Else
MsgBox("The house is exempted")
End If
End Sub

Private Sub Button2_Click(sender As Object, e As


EventArgs) Handles Button2.Click
TextBoxH.Text = ""
TextBoxT.Text = ""
End Sub

Private Sub Button3_Click(sender As Object, e As


EventArgs) Handles Button3.Click
End
End Sub
End Class
CLASSES

CODE
UNDER CLASS
Public Class Person
Dim stFirstname As String
Dim stLastname As String
Dim slHeight As Single
Dim dlWeight As Double
Public Property Firstname As String
Set(ByVal value As String)
stFirstname = value
End Set
Get
Return stFirstname
End Get
End Property
Public Property Lastname As String
Set(ByVal value As String)
stLastname = value
End Set
Get
Return stLastname
End Get
End Property
Public Property height As Single
Set(ByVal value As Single)
slHeight = value
End Set
Get
Return slHeight
End Get
End Property
Public Property Weight As Double
Set(ByVal value As Double)
dlWeight = value
End Set
Get
Return dlWeight
End Get
End Property
Public Overridable Function CalculateBodyMassIndex() As
Double
Dim BodyMassIndex As Double
BodyMassIndex = dlWeight / slHeight ^ 2
Return BodyMassIndex
End Function
End Class
UNDER CMD BUTTON
Public Class Form1

Private Sub Button1_Click(sender As Object, e As


EventArgs) Handles Button1.Click
Dim P1 As New Person
P1.Firstname = TextBoxFN.Text
P1.Lastname = TextBoxLN.Text
P1.height = TextBoxH.Text
P1.Weight = TextBoxW.Text

P1.CalculateBodyMassIndex()
MsgBox(P1.Firstname & vbTab & "Body mass index is" &
vbTab & P1.CalculateBodyMassIndex)
End Sub

Private Sub Button2_Click(sender As Object, e As


EventArgs) Handles Button2.Click
TextBoxFN.Text = ""
TextBoxH.Text = ""
TextBoxLN.Text = ""
TextBoxW.Text = ""
End Sub

Private Sub Button3_Click(sender As Object, e As


EventArgs) Handles Button3.Click
End
End Sub
End Class

5)

Public Class Form1


Function GP(ByRef Hrate As Decimal, ByRef Hrs As Decimal)
As Decimal
Return (Hrate * Hrs)
End Function
Private Sub Button1_Click(sender As Object, e As
EventArgs) Handles Button1.Click
Dim Hours As Decimal
Dim Hourate As Decimal
Dim Gpay As Decimal
Hours = Val(TextBoxH.Text)
Hourate = Val(TextBoxHR.Text)
If Hours = 40 Then
Gpay = GP(Hours, Hourate)
LabelG.Text = Gpay
ElseIf Hours > 40 Then
Gpay = GP(Hours, Hourate) * 3 / 2
LabelG.Text = Gpay
Else
MsgBox("Invalid Hours")
End If
End Sub

Private Sub Button2_Click(sender As Object, e As


EventArgs) Handles Button2.Click
TextBoxH.Text = ""
TextBoxHR.Text = ""
LabelG.Text = ""
End Sub

Private Sub Button3_Click(sender As Object, e As


EventArgs) Handles Button3.Click
End
End Sub
End Class

6)
Public Class Function_2
Function ST(ByRef Ptax As Decimal, ByRef PA As Decimal) As
Decimal
Return (Ptax * PA)
End Function
Private Sub Button1_Click(sender As Object, e As
EventArgs) Handles Button1.Click
Dim PurA, SalT, TTA, ptax1 As Decimal
Dim CName As String
Dim salescode As Integer
PurA = InputBox("Enter purchase amount")
CName = InputBox("Enter Customer's Name")
salescode = InputBox("Enter sales code")
If salescode = 0 Then
MsgBox("tax exempted")
ElseIf salescode = 1 Then
ptax1 = 0.03
SalT = ST(ptax1, PurA)
TTA = SalT + PurA
LabelCN.Text = CName
LabelPA.Text = PurA
LabelST.Text = SalT
LabelTTA.Text = TTA
ElseIf salescode = 2 Then
ptax1 = 0.05
SalT = ST(ptax1, PurA)
TTA = SalT + PurA
LabelCN.Text = CName
LabelPA.Text = PurA
LabelST.Text = SalT
LabelTTA.Text = TTA
ElseIf salescode = 3 Then
ptax1 = 0.07
SalT = ST(ptax1, PurA)
TTA = SalT + PurA
LabelCN.Text = CName
LabelPA.Text = PurA
LabelST.Text = SalT
LabelTTA.Text = TTA
Else
MsgBox(" Invalid tax code ")
End If
End Sub

Private Sub Button3_Click(sender As Object, e As


EventArgs) Handles Button3.Click
End
End Sub

Private Sub Button2_Click(sender As Object, e As


EventArgs) Handles Button2.Click
LabelCN.Text = ""
LabelPA.Text = ""
LabelST.Text = ""
LabelTTA.Text = ""
End Sub
End Class

You might also like