Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Button1.Click Try o_person.nama = TextBox1.Text o_person.alamat = TextBox2.Text o_person.TglLahir = DateTimePicker1.Value.ToShortDateString o_person.inputdata() MessageBox.Show("input data SUKSES") TextBox1.Clear() TextBox2.Clear() TextBox3.Clear() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub
Private Sub DateTimePicker1_ValueChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DateTimePicker1.ValueChanged o_person.TglLahir = DateTimePicker1.Value TextBox3.Text = o_person.Usia End Sub
Private Sub DateTimePicker1_ValueChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DateTimePicker1.ValueChanged o_person.TglLahir = DateTimePicker1.Value TextBox3.Text = o_person.Usia End Sub
Private Sub BIODATA_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing o_person.closefile() End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click Close() End Sub End Class Skrip pada CLASS (CPerson.vb)
Imports System.IO
Public Class CPerson
Private mnama, malamat As String, tgl As Date Dim o_stream As StreamWriter = File.CreateText("d:\LIA-nae\KULIAH\PBO2\PBO- 29Nop\myfile.txt")
Public Property nama() As String
Get Return mnama End Get Set(ByVal Value As String) mnama = Value End Set End Property
Public Property alamat() As String
Get Return malamat End Get Set(ByVal Value As String) malamat = Value End Set End Property
Public Property TglLahir() As Date
Get Return tgl End Get Set(ByVal Value As Date) tgl = Value End Set End Property
Public Function Usia() As Integer
Return Today.Year - tgl.Year End Function
Public Sub inputdata()
o_stream.WriteLine(mnama) o_stream.WriteLine(malamat) o_stream.WriteLine(tgl) End Sub
Public Sub closefile()
o_stream.Close() End Sub End Class Pembahasan FAKTORIAL dan CEK PALINDROM (PBO-22 Nopember 2010)
From FAKTORIAL (Form1.vb) Form CEK PALINDROM (Form1.vb)
SKRIP pada form (Form1.vb)
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Close() End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click Dim kata As String, palindrom As Boolean, j, p As Integer Try kata = TextBox2.Text.ToUpper p = kata.Length - 1 For j = 0 To p / 2 If kata.Chars(j) = kata.Chars(p - j) Then palindrom = True Else palindrom = False Exit For End If Next Label4.Text = palindrom Catch ex As Exception
End Try End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Close() End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Close() End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click Me.Close() End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click Dim i, jml, x As Integer jml = 1 Try x = TextBox1.Text For i = x To 1 Step -1 jml = jml * i Next Label2.Text = jml Catch ex As Exception MessageBox.Show(ex.Message, "Oo..ooww...ERROR") End Try End Sub End Class
KONVERSI
Skrip pada Form Konversi (Form1.vb)
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click Dim konversi As New KonversiNilai TextBox2.Text = konversi.Konversi(TextBox1.Text) End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click Close() End Sub End Class
CLASS Konversi (KonversiNilai.vb)
Public Class KonversiNilai
Public Function Konversi(ByVal nilai As Single) As String If nilai >= 0 And nilai < 50 Then Return "E" ElseIf nilai >= 50 And nilai < 60 Then Return "D" ElseIf nilai >= 60 And nilai < 70 Then Return "C" ElseIf nilai >= 70 And nilai < 75 Then Return "C+" ElseIf nilai >= 75 And nilai < 80 Then Return "B" ElseIf nilai >= 80 And nilai < 85 Then Return "B+" ElseIf nilai >= 85 And nilai < 100 Then Return "A" End If End Function End Class