0% found this document useful (0 votes)
63 views7 pages

Latihan Praktik Visual Basic Dasar

The document discusses examples of Visual Basic programming practices including message boxes, multiple forms, checkboxes that calculate totals automatically, and combo boxes that calculate costs automatically.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views7 pages

Latihan Praktik Visual Basic Dasar

The document discusses examples of Visual Basic programming practices including message boxes, multiple forms, checkboxes that calculate totals automatically, and combo boxes that calculate costs automatically.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Latihan Praktik Visual Basic

1. Message Box
Buatlah sebuah form penginputan password, dimana ketika password yang diinputkan tidak sesuai,
maka akan memunculkan Message Box berupa pesan Error “Password Salah! Silakan Coba Input
Lagi” dan apabila password yang diinputkan telah sesuai, akan memunculkan Message Box berupa
Informasi “Password Sudah Benar”.

Interface

Listing

Dim password As String = "12345"


If [Link] = password Then
[Link]("Password sudah benar!", "Informasi", [Link],
[Link])
Else
[Link]("Password salah! Silakan coba input lagi.", "Error",
[Link], [Link])
[Link]()
End If
MessageBoxButtons berfungsi untuk menampilkan Message Box, sedangkan [Link], fungsinya
untuk membuat TextBox1 menjadi kosong kembali setelah dilakukan penginputan.

2. Multiple Form
Buatlah 4 Form, yang terdiri dari Form Utama, Form 1, Form 2, dan Form 3.

Interface Form Utama


Interface Form 1, Form 2, Form 3
Listing Code Form Utama

Public Class FormUtama


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
Dim form1 As New Form1()
[Link]()
[Link]()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]


Dim form2 As New Form2()
[Link]()
[Link]()
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles [Link]


Dim form3 As New Form3()
[Link]()
[Link]()
End Sub
End Class

Listing Code Form 1, 2, 3

Public Class Form1


Private Sub Back1_Click(sender As Object, e As EventArgs) Handles [Link]
Dim formUtama As New FormUtama()
[Link]()
[Link]()
End Sub

Private Sub Tutup1_Click(sender As Object, e As EventArgs) Handles [Link]


[Link]()
End Sub
End Class
3. CheckBox dan Hitung Otomatis

Aplikasi yang dibuat, beberapa listing codenya berada pada CheckBox

Interface

Listing Code

Perhatikan, terdapat Deklarasi DIM pada bagian setelah Public Class.

Public Class Form1


Dim obat As Double = 120000
Dim gigi As Double = 80000
Dim mata As Double = 100000
Dim medical As Double = 350000
Private total As Double = 0

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]


[Link] = "Rp." & 0
End Sub

Private Sub CkObat_CheckedChanged(sender As Object, e As EventArgs) Handles


[Link]
If [Link] Then
total = total + obat
Else
total = total - obat
End If
[Link] = "Rp." & total
End Sub

Private Sub CkGigi_CheckedChanged(sender As Object, e As EventArgs) Handles


[Link]
If [Link] Then
total = total + gigi
Else
total = total - gigi
End If
[Link] = "Rp." & total
End Sub

Private Sub CkMata_CheckedChanged(sender As Object, e As EventArgs) Handles


[Link]
If [Link] Then
total = total + mata
Else
total = total - mata
End If
[Link] = "Rp." & total
End Sub

Private Sub CkMedical_CheckedChanged(sender As Object, e As EventArgs) Handles


[Link]
If [Link] Then
total = total + medical
Else
total = total - medical
End If
[Link] = "Rp." & total
End Sub
End Class
4. ComboBox dan Hitung Otomatis

Aplikasi yang dibuat, listing codenya berada pada Combo Box dan Text Box.

Interface
Listing Code

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]


[Link] = [Link]
End Sub

Private Sub ComboJenis_SelectedIndexChanged(sender As Object, e As EventArgs) Handles


[Link]
If [Link] = "VIP" Then
[Link] = 850000
ElseIf [Link] = "Kelas I" Then
[Link] = 500000
ElseIf [Link] = "Kelas II" Then
[Link] = 300000
ElseIf [Link] = "Kelas III" Then
[Link] = 130000
End If
End Sub

Private Sub TeksInap_TextChanged(sender As Object, e As EventArgs) Handles


[Link]
Dim nilai2, nilai3 As Double
Dim nilai1 As Integer
nilai1 = [Link]
nilai2 = [Link]
nilai3 = nilai2 * nilai1
[Link] = nilai3
End Sub

Private Sub TeksBayar_TextChanged(sender As Object, e As EventArgs) Handles


[Link]
[Link] = Val([Link]) - [Link]
End Sub

Private Sub ButtonClose_Click(sender As Object, e As EventArgs) Handles


[Link]
[Link]()
End Sub
End Class

You might also like