Sie sind auf Seite 1von 13

ACTIVITY 1 : CREATE A SIMPLE ARRAY

Form1.vb
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles
Button1.Click
Dim strFriends(4) As String
Dim i As Integer
strFriends(0)
strFriends(1)
strFriends(2)
strFriends(3)
strFriends(4)

=
=
=
=
=

"Ahmad"
"Bryan"
"Iffah"
"Muthu"
"Katie"

For i = 0 To 4
MessageBox.Show("The value for index " & i & " is " & strFriends(i))
Next
End Sub
End Class

Form1.Designer.vb
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(98, 191)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Run"
Me.Button1.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 261)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
End Class

Output :

ACTIVITY 2 : INVOKED SQRT METHOD


Form1.vb
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles
Button1.Click
main()
End Sub
End Class
----------------------------------------------------------------------------------Module module1
Dim answer As Double
Sub main()
answer = Math.Sqrt(121)
MsgBox("Answer is " & answer)
End Sub
End Module

OUTPUT :

ACTIVITY 3 : INVOKED POW METHOD


Public Class Form1
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles
Button2.Click
Main2()
End Sub
End Class
----------------------------------------------------------------------------------Module module1
Dim answer As Double
Sub main2()
answer = Math.Pow(5, 2)
MsgBox("Answer is " & answer)
End Sub
End Module

Output :

ACTIVITY 4 : INVOKED A SUB-PROCEDURE


Form1.vb
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles
Button1.Click
main()
End Sub
End Class
-----------------------------------------------------------------------------------Module Module1
Sub Main()
Server.AddEmUp(2, 3)
End Sub
End Module
-----------------------------------------------------------------------------------Module Server
Public Sub AddEmUp(ByVal a As Integer, ByVal b As Integer)
Dim sum As Integer
sum = a + b
MsgBox("The Sum is : " & sum)
End Sub
End Module

Output :

ACTIVITY 5 : INVOKED A FUNCTION PROCEDURE


Form1.vb
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles
Button1.Click
Main()
End Sub
End Class
-----------------------------------------------------------------------------------Module Module1
Sub Main()
Dim total As Integer
total = Server.AddEmUp(2, 3)
MsgBox("The Total of 2 and 3 is :" & total)
End Sub
End Module
-----------------------------------------------------------------------------------Module Server
Public Function AddEmUp(ByVal a As Integer, ByVal b As Integer) As Integer
Dim sum As Integer
sum = a + b
Return sum
End Function
End Module

OUTPUT :

ACTIVITY 6 : TEMPERATURE CONVERTER USING PRIVATE PROCEDURES


Form1.vb
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles
Button1.Click
TempConverter.main3()
End Sub
End Class
----------------------------------------------------------------------------------Module Tempconverter
Dim farenheit, celcius As Double
----------------------------------------------------------------------------------Sub main3()
InputFarenheit()
calculate()
display()
End Sub
-----------------------------------------------------------------------------------Private Sub InputFarenheit()
farenheit = Convert.ToDouble(InputBox("Enter the Farenheit Temperature: "))
End Sub
-----------------------------------------------------------------------------------Private Sub calculate()
celcius = 5 / 9 * (farenheit - 32)
End Sub
-----------------------------------------------------------------------------------Private Sub display()
celcius = Math.Round(celcius, 1)
MsgBox(farenheit & "F= " & celcius & " C")
End Sub
End Module

OUTPUT :

ACTIVITY 7 :
Form1.Designer.vb
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
-----------------------------------------------------------------------------------'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(12, 26)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(262, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Enter employee first name, last name, and date of birth"
'
'TextBox1

'
Me.TextBox1.Location = New System.Drawing.Point(15, 51)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(259, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "First Name"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(15, 86)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(259, 20)
Me.TextBox2.TabIndex = 2
Me.TextBox2.Text = "Last Name"
'
'DateTimePicker1
'
Me.DateTimePicker1.Location = New System.Drawing.Point(15, 121)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.Size = New System.Drawing.Size(259, 20)
Me.DateTimePicker1.TabIndex = 3
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(82, 157)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(119, 26)
Me.Button1.TabIndex = 4
Me.Button1.Text = "Display Record"
Me.Button1.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(294, 216)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.DateTimePicker1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "Person Class"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
-----------------------------------------------------------------------------------Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker
Friend WithEvents Button1 As System.Windows.Forms.Button
End Class

Output

ACTIVITY 8
Form1.vb
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles
Button1.Click
Dim Employee As New Person
Dim DOB As Date
Employee.FirstName = TextBox1.Text
Employee.LastName = TextBox2.Text
DOB = DateTimePicker1.Value.Date
MsgBox(Employee.FirstName & " " & Employee.LastName & " is " &
Employee.Age(DOB) & " year old. ")
End Sub
End Class

Person.vb
Public Class Person
Private Name1 As String
Private Name2 As String
-----------------------------------------------------------------------------------Public Property FirstName() As String
Get
Return Name1
End Get
Set(ByVal value As String)
Name1 = value
End Set
End Property
-----------------------------------------------------------------------------------Public Property LastName() As String
Get

Return Name2
End Get
Set(ByVal value As String)
Name2 = value
End Set
End Property
-----------------------------------------------------------------------------------Public Function Age(ByVal Birthday As Date) As Integer
Return Int(Now.Subtract(Birthday).Days / 365.25)
End Function
End Class

Output

Das könnte Ihnen auch gefallen