Event di VB
The Visual Basic event sample program source code below is useful to those who want to learn on how to program in Visual Basic using the Click event of the command button, and GotFocus and LostFocus event of the text box control. Visual Basic program acara sampel kode sumber di bawah ini berguna bagi mereka yang ingin belajar tentang bagaimana program dalam Visual Basic menggunakan acara Klik dari tombol perintah, dan GotFocus dan peristiwa LostFocus kontrol kotak teks. It will also serve as a reference to Information Technology students who are looking for the Visual Basic event sample program source code particularly click event of command button, and GotFocus and LostFocus event of the text box. Hal ini juga akan berfungsi sebagai referensi untuk mahasiswa Teknologi Informasi yang mencari acara kode Visual Basic sampel sumber program acara khususnya klik tombol perintah, dan GotFocus dan peristiwa LostFocus dari kotak teks.
Ketika Visual Basic program dijalankan, bentuk dan kontrol yang muncul di layar. Biasanya, tidak ada yang terjadi sampai pengguna mengambil tindakan, seperti mengklik Tindakan seperti ini disebut sebuah event. The three steps to creating a Visual Basic program are as follows: Tiga langkah untuk membuat program Visual Basic adalah sebagai berikut:
1. 1. Create the interface; that is, generate, position, and size the objects. Membuat antarmuka, yaitu, menghasilkan, posisi, dan ukuran objek.
2. 2. Set properties; that is, set relevant properties for the objects. Set properti, yaitu relevan untuk mengatur properti objek.
3. 3. Write the code that executes when the events occur. Tuliskan kode yang dijalankan ketika peristiwa terjadi.
Ketika Visual Basic program dijalankan, bentuk dan kontrol yang muncul di layar. Biasanya, tidak ada yang terjadi sampai pengguna mengambil tindakan, seperti mengklik Tindakan seperti ini disebut sebuah event. The three steps to creating a Visual Basic program are as follows: Tiga langkah untuk membuat program Visual Basic adalah sebagai berikut:
1. 1. Create the interface; that is, generate, position, and size the objects. Membuat antarmuka, yaitu, menghasilkan, posisi, dan ukuran objek.
2. 2. Set properties; that is, set relevant properties for the objects. Set properti, yaitu relevan untuk mengatur properti objek.
3. 3. Write the code that executes when the events occur. Tuliskan kode yang dijalankan ketika peristiwa terjadi.
mana objectName adalah nama bentuk atau kontrol, properti merupakan salah satu sifat-sifat objek, dan pengaturan adalah pengaturan valid untuk objek tersebut. Such statements are called assignment statements. Laporan seperti ini disebut pernyataan penugasan. They assign values to properties. Mereka memberikan nilai pada properti. Here are three other assignment statements. Berikut adalah tiga pernyataan penugasan lainnya. The statement: Pernyataan itu:
txtBox.Font.Size = 12 txtBox.Font.Size = 12
sets the size of the characters in the text box named txtBox to 12. set ukuran karakter dalam kotak teks bernama txtBox sampai 12.
The statement: Pernyataan itu:
txtBox.Font.Bold = True txtBox.Font.Bold = True
converts the characters in the text box to boldface. mengubah karakter dalam kotak teks untuk huruf tebal.
The statement: Pernyataan itu:
txtBox.Text = “” txtBox.Text = ""
clears the contents of the text box; that is, it invokes the blank setting. membersihkan isi kotak teks, yaitu, ia memanggil pengaturan kosong. Most events are associated with objects. Kebanyakan acara yang berhubungan dengan objek. The event clicking cmdButton is different from the event clicking picBox. Acara mengklik cmdButton berbeda dari acara picBox mengklik. These two events are specified cmdButton_Click and picBox_Click. Kedua peristiwa ini ditentukan cmdButton_Click dan picBox_Click. The statements to be executed when an event occurs are written in a block of code called an event procedure. Laporan akan dieksekusi ketika sebuah peristiwa terjadi yang ditulis dalam blok kode yang disebut prosedur acara. The structure of an event procedure is: Struktur sebuah prosedur acara adalah:
txtBox.Font.Size = 12 txtBox.Font.Size = 12
sets the size of the characters in the text box named txtBox to 12. set ukuran karakter dalam kotak teks bernama txtBox sampai 12.
The statement: Pernyataan itu:
txtBox.Font.Bold = True txtBox.Font.Bold = True
converts the characters in the text box to boldface. mengubah karakter dalam kotak teks untuk huruf tebal.
The statement: Pernyataan itu:
txtBox.Text = “” txtBox.Text = ""
clears the contents of the text box; that is, it invokes the blank setting. membersihkan isi kotak teks, yaitu, ia memanggil pengaturan kosong. Most events are associated with objects. Kebanyakan acara yang berhubungan dengan objek. The event clicking cmdButton is different from the event clicking picBox. Acara mengklik cmdButton berbeda dari acara picBox mengklik. These two events are specified cmdButton_Click and picBox_Click. Kedua peristiwa ini ditentukan cmdButton_Click dan picBox_Click. The statements to be executed when an event occurs are written in a block of code called an event procedure. Laporan akan dieksekusi ketika sebuah peristiwa terjadi yang ditulis dalam blok kode yang disebut prosedur acara. The structure of an event procedure is: Struktur sebuah prosedur acara adalah:
Private Sub objectName_event() Private Sub objectName_event ()
statements laporan
End Sub End Sub
The word Sub in the first line signals the beginning of the event procedure, and the first line identifies the object and the event occurring to that object. Kata Sub pada baris pertama sinyal awal prosedur event, dan baris pertama mengidentifikasi objek dan peristiwa yang terjadi untuk objek tersebut. The last line signals the termination of the event procedure. Baris terakhir sinyal berakhirnya event prosedur. The statements to be executed appear between these two lines. Laporan akan dieksekusi muncul antara dua garis.
(Note: The word Private indicates that the event procedure cannot be invoked by an event from another form. This will not concern us until much later in the text. The word Sub is an abbreviation of Subprogram.) For instance, the event procedure (Catatan: Kata Swasta menunjukkan bahwa prosedur acara tidak dapat dipanggil oleh acara dari bentuk lain ini tidak akan menjadi perhatian kita sampai lama kemudian dalam teks Kata Sub merupakan singkatan dari Subprogram...) Sebagai contoh, prosedur acara
(Note: The word Private indicates that the event procedure cannot be invoked by an event from another form. This will not concern us until much later in the text. The word Sub is an abbreviation of Subprogram.) For instance, the event procedure (Catatan: Kata Swasta menunjukkan bahwa prosedur acara tidak dapat dipanggil oleh acara dari bentuk lain ini tidak akan menjadi perhatian kita sampai lama kemudian dalam teks Kata Sub merupakan singkatan dari Subprogram...) Sebagai contoh, prosedur acara
1. 1. Create the interface in Figure 2-13. Buat antarmuka pada Gambar 2-13. The Name properties of the form, text box, and command button should be set as shown in the Object column. Name sifat dari bentuk, kotak teks, tombol perintah dan harus ditetapkan seperti yang ditunjukkan pada kolom Object. The Caption property of the form should be set to Demonstration, the Text property of the text box should be made blank, and the Caption property of the command button should be set to Make Phrase Bold. Properti Caption dari form harus di set ke Demonstrasi, properti Text dari kotak teks yang harus dibuat kosong, dan properti Caption dari tombol perintah harus ditetapkan Membuat Frasa Bold.
2. 2. Double-click on the text box. Double-klik pada kotak teks. A window, called the Code window, appears. Sebuah jendela, yang disebut jendela Code, muncul. See Figure 2-14. Lihat Gambar 2-14. Just below the title bar are two drop-down list boxes. Tepat di bawah judul bar dua drop-down box. The left box is called the Object box and the right box is called the Procedure box. Kotak kiri disebut kotak Obyek dan kotak kanan disebut kotak Prosedur. (When you position the mouse pointer over one of these list boxes, its type appears.) (Bila Anda posisi pointer mouse di atas salah satu kotak daftar, jenisnya muncul
2. 2. Double-click on the text box. Double-klik pada kotak teks. A window, called the Code window, appears. Sebuah jendela, yang disebut jendela Code, muncul. See Figure 2-14. Lihat Gambar 2-14. Just below the title bar are two drop-down list boxes. Tepat di bawah judul bar dua drop-down box. The left box is called the Object box and the right box is called the Procedure box. Kotak kiri disebut kotak Obyek dan kotak kanan disebut kotak Prosedur. (When you position the mouse pointer over one of these list boxes, its type appears.) (Bila Anda posisi pointer mouse di atas salah satu kotak daftar, jenisnya muncul
0 komentar:
Posting Komentar