Latihan 4 : Menggunakan Operator Aritmatika
Berikut Source Codenya :
Public Class lat4
'nadiahtami 2017230007'
Dim alas, tinggi As Integer
Dim luas As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
alas = TextBox1.Text
tinggi = TextBox2.Text
luas = (alas * tinggi) / 2
TextBox3.Text = luas
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Yakin Ingin Keluar ??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
Close()
End
End If
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True 'hanya bisa menginput angka
If (e.KeyChar = Chr(13)) Then
TextBox2.Focus()
End If
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True 'hanya bisa menginput angka
End Sub
End Class
Latihan 5 : Menggunakan Operator Logika
Berikut Source Codenya :
Public Class lat5
'nadiahtami 2017230007'
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim keyascii As Short = Asc(e.KeyChar)
If (e.KeyChar Like "[A-Z,a-z]" _
OrElse keyascii = Keys.Back _
OrElse keyascii = Keys.Space _
OrElse keyascii = Keys.Return _
OrElse keyascii = Keys.Delete) Then
keyascii = 0
End If
e.Handled = CBool(keyascii)
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
Dim keyascii As Short = Asc(e.KeyChar)
If (e.KeyChar Like "[A-Z,a-z]" _
OrElse keyascii = Keys.Back _
OrElse keyascii = Keys.Space _
OrElse keyascii = Keys.Return _
OrElse keyascii = Keys.Delete _
) Then
keyascii = 0
End If
e.Handled = CBool(keyascii)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim namadepan, namabelakang As String
namadepan = TextBox1.Text
namabelakang = TextBox2.Text
If TextBox1.Text = "" And TextBox2.Text = "" Then
MessageBox.Show("Anda Belum Memasukkan Nama Depan dan Belakang")
ElseIf TextBox1.Text = "" Or TextBox2.Text = "" Then
MessageBox.Show("Anda Belum Memasukkan Nama Depan dan Belakang")
Else
MessageBox.Show("Nama Lengkap Anda adalah " + namadepan + " " + namabelakang)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Yakin Ingin Keluar ??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
Close()
End
End If
End Sub
End Class
Komentar
Posting Komentar