Dim b1, b2, h As Double
Private Sub btntambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntambah.Click
b1 = Val(TextBox1.Text) ‘untuk mengidentifikasikan angka yang dimasukkan pada textbox1
b2 = Val(TextBox2.Text) ‘untuk mengidentifikasikan angka yang dimasukkan pada textbox2
h = b1 + b2 ‘perhitungan antara variabel yang telah dideklarasikan
TextBox3.Text = Str(h) ‘hasil perhitungan yang akan ditampilkan pada textbox3
End Sub
Private Sub btnbagi_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnbagi.Click
b1 = Val(TextBox1.Text)
b2 = Val(TextBox2.Text)
h = b1 / b2
TextBox3.Text = Str(h)
End Sub
Private Sub btnhapus_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnhapus.Click
Me.TextBox1.Clear()
Me.TextBox2.Clear()
Me.TextBox3.Clear()
Me.TextBox1.Focus()
End Sub
Private Sub btnkali_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnkali.Click
b1 = Val(TextBox1.Text)
b2 = Val(TextBox2.Text)
h = b1 * b2
TextBox3.Text = h
End Sub
BELAJAR CLASS
- BUAT FORM
- buat class ORANG_TUA
- buat class ANAK_WANITA
- buat class ANAK_PRIA
- CODING
- Buat project baru “belajar class”
- buat form nya 1 listbox, 1 button
- buat class ORANG_TUA, ANAK_WANITA, ANAK_PRIA
- klik 2 x di button
- masukan kode :
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Obj_W As New ANAK_WANITA
Dim Obj_P As New ANAK_PRIA
With Obj_W
.Nama_Bapak = “Tri”
.Nama_Ibu = “aijhai”
.Nama_Wanita = “aiueo”
.Usia_Wanita = “20″
End With
With Obj_P
.Nama_Pria = “yudis”
.Usia_Pria = “53″
End With
With ListBox1
.Items.Add(“Nama Ayah: ” & Obj_W.Nama_Bapak)
.Items.Add(“Nama Ibu: ” & Obj_W.Nama_Ibu)
.Items.Add(“Nama Wanita :” & Obj_W.Nama_Wanita)
.Items.Add(“Usia Wanita :” & Obj_W.Usia_Wanita)
.Items.Add(“Nama Pria :” & Obj_P.Nama_Pria)
.Items.Add(“Usia Pria :” & Obj_P.Usia_Pria)
End With
End Sub
End Class
SCRIPT CLASS
Public Class ORANG_TUA
Private XBapak As String
Private XIbu As String
Public Property Nama_Bapak() As String
Get
Return XBapak
End Get
Set(ByVal value As String)
XBapak = value
End Set
End Property
Public Property Nama_Ibu() As String
Get
Return XIbu
End Get
Set(ByVal value As String)
XIbu = value
End Set
End Property
End Class
Public Class ANAK_WANITA
Inherits ORANG_TUA
Private XWanita As String
Private XUsia_W As Byte
Public Property Nama_Wanita() As String
Get
Return XWanita
End Get
Set(ByVal value As String)
XWanita = value
End Set
End Property
Public Property Usia_Wanita() As Byte
Get
Return XUsia_W
End Get
Set(ByVal value As Byte)
XUsia_W = value
End Set
End Property
End Class
Public Class ANAK_PRIA
Inherits ORANG_TUA
Private XPria As String
Private XUsia_P As Byte
Public Property Nama_Pria() As String
Get
Return XPria
End Get
Set(ByVal value As String)
XPria = value
End Set
End Property
Public Property Usia_Pria() As String
Get
Return XUsia_P
End Get
Set(ByVal value As String)
XUsia_P = value
End Set
End Property
End Class
BIKIN STOPWATCH
siapin 3 button, 1 label, 1 timer (interval 100)
Public Class Form1
Dim Mili, Sec, Min, hr As Integer
Dim Countr As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Mili = 0
Sec = 0
Min = 0
hr = 0
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Enabled = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim mYes_No As String = MsgBox(“Reset timer ?”, vbYesNo)
If mYes_No = vbYes Then
Mili = 0
Sec = 0
Min = 0
hr = 0
Label1.Text = “”
Timer1.Enabled = False
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim Mili2, Sec2, Min2, hr2 As String
Countr = Countr + 1
Mili2 = Countr
If Countr = 10 Then
Sec = Sec + 1
Countr = 0
End If
If Sec = 60 Then
Min = Min + 1
Sec = 0
End If
If Min = 60 Then
hr = hr + 1
Min = 0
End If
Sec2 = Format(Val(Sec), “00″)
Min2 = Format(Val(Min), “00″)
hr2 = Format(Val(hr), “00″)
Label1.Text = hr2 & “:” & Min2 & “:” & Sec2 & “:” & Mili2
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
End Class
Tidak ada komentar:
Posting Komentar