Tuesday, May 15, 2018

PERTEMUAN KE6

MESSAGEBOX (MSGBOX)




Tujuan


Memberikan pemahaman tentang penggunaan MessageBox.

MsgBox (Kotak Pesan)

Berfungsi untuk menampilkan pesan atau komentar dalam bentuk form.

Bentuk Perintah
MsgBox(“Isi Pesan“, MsgBoxStyle, “Judul Pesan“)
















Keterangan gambar:
Œ Judul Pesan
 MsgBoxStyle
Ž Isi Pesan

Ada beberapa MsgBoxStyle, yaitu:
 

1.     MsgBoxStyle.Critical (16)                   :   tombol OK dan gambar icon Critical
 

2.     MsgBoxStyle.Question (32)               :   tombol OK dan gambar icon Question
 

3.     MsgBoxStyle.Exclamation (48)         :   tombol OK dan gambar icon Exclamation
 

4.     MsgBoxStyle.Information (64)           :    tombol OK dan gambar icon Information

5.    MsgBoxStyle.AbortRetryIgnore (2)   :    tombol Abort, Retry dan Ignore.
6.    MsgBoxStyle.OkCancel (1)                :    tombol OK dan Cancel.
7.    MsgBoxStyle.OkOnly (0)                    :    tombol OK.
8.    MsgBoxStyle. RetryCancel (5)           :    tombol Retry dan Cancel.
9.    MsgBoxStyle.YesNo (4)                      :    tombol Yes dan No.
10.  MsgBoxStyle. YesNoCancel (3)        :    tombol Yes, No dan Cancel.

Contoh 1:
Membuat Form Login dengan tampilan sbb :
Objek
Name
TextBox1
TxtPas
Button1
BtnProses








Alur Program:
-    Input Password.
-    Klik Proses
-    Jika Password benar maka akan tampil kotak pesan (MessageBox) dengan tampilan sbb:
·    Isi pesan         :  Password yang Anda Masukkan Benar
·    Judul Pesan  :  Info Login
·    MsgBoxStyle  :  Tombol OK dengan gambar icon Information.
-    Jika Password salah maka akan tampil kotak pesan (MessageBox) dengan tampilan sbb:
·    Isi pesan         :  Password yang Anda Masukkan Salah”
·    Judul Pesan  : Info Login
·    MsgBoxStyle  :  Tombol OK dengan gambar icon Critical.

Kode Program:
Kode program diketik pada Objek BtnProses (Tombol Proses)  sbb:
Private Sub BtnProses_Click(ByVal sender As System.Object, ...
    If TxtPas.Text = "rahasia" Then
        MsgBox("Password yang Anda Masukkan Benar",
               MsgBoxStyle.Information, "Info Login")
    Else
        MsgBox("Password yang Anda Masukkan Salah", 16, "Info")
    End If  
End Sub

Contoh 2:
Tambah tombol Tutup pada form Login, sehingga tampilan form menjadi seperti berikut:


Objek
Name
TextBox1
TxtPas
Button1
BtnProses










Buat Perintah untuk Tombol Tutup menggunakan MessageBox dengan tampilan sbb:
-   Isi Pesan         :   “Apakah Anda ingin menutup Form Login ini?“
-    MsgBoxStyle   :   Yes dan No dengan icon Question.
-    Judul                :   “Tutup Form Login“

Alur Program:
Jika diklik tombol Yes, maka Program akan ditutup. Jika diklik tombol No, maka Program tidak akan ditutup.

Perintah Program:
Private Sub BtnTutup_Click(ByVal sender As System.Object, ...
    Dim pesan As String
    pesan = MsgBox("Apakah Anda ingin menutup Program ini?", MsgBoxStyle.YesNo + 32, "Tutup Program")
    If pesan = vbYes Then
        End
    Else
        Exit Sub
    End If
End Sub


Latihan:
Buat Program Untuk Menampilkan Informasi Hadiah sesuai Point Reward dengan Menggunakan MessageBox.
1. Desain Program sbb:



Objek
Name
TextBox1
TxtJPR
Button1
BtnProses
Button2
BtnTutup





2. Alur Program
     -    Input Jumlah Point Reward.
     -    Klik Proses, maka akan tampil keterangan Hadiah sesuai point reward pada MessageBox.                                                                                                                                                            
          Tabel Hadiah sebagai berikut:                    
Point Reward
Hadiah
500 – 1000
Mug Cantik
1001 – 1500
Boneka Cantik
1501 – 2000
Kipas Angin
2001 – 2500
Dispenser

-     Klik Tutup, maka akan tampil MessageBox dengan dengan tampilan sbb:
·       Isi Pesan          :    Anda ingin menutup Program ini?
·       MsgBoxStyle   :    OK dan Cancel dengan icon Question.
·       Judul                 :    Tutup Program
Jika diklik tombol OK, maka Program akan ditutup. Jika diklik tombol Cancel, maka Program tidak akan ditutup.

CODING NYA
Public Class Form1

    Private Sub BtnProses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProses.Click

       Select Val(TxtProses.Text)
            Case 500 To 1000
                MsgBox("Mug Cantik", MsgBoxStyle.Information, "Info HADIAH")
            Case 1001 To 1500
                MsgBox("Boneka Cantik", MsgBoxStyle.Information, "Info HADIAH")
            Case 1501 To 2000
                MsgBox("Kipas Angin", MsgBoxStyle.Information, "Info HADIAH")
            Case 2001 To 2500
                MsgBox("Dispenser", MsgBoxStyle.Information, "Info HADIAH")
            Case Else
                MsgBox("Tidak Ada", MsgBoxStyle.Information, "Info HADIAH")


        End Select

    End Sub


    Private Sub BtnTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTutup.Click
        Dim pesan As String
        pesan = MsgBox("Apakah Anda ingin menutup Program ini?", MsgBoxStyle.YesNo + 32, "Tutup Program")
        If pesan = vbYes Then
            End
        Else
            Exit Sub
        End If

    End Sub

End Class


                                                Lihat videonya dibawah ini





1 comment:

  1. Titanium Blade - An alloyed blade
    Titanium Blade - An titanium jewelry alloyed blade with an titanium white paint outer handle. $28.99. $26.95. Description. A chrome finished blade with a 2019 ford fusion hybrid titanium metal titanium exhaust tips frame with an open comb  Rating: 4.6 ecm titanium · ‎36 reviews · ‎$28.99 · ‎In stock

    ReplyDelete