Visual Basic Event sample program source code Visual Basic Event
The sample Visual Basic program source code listed below illustrates on how to use the events in Visual Basic . Sampel program Visual Basic source code di bawah ini menggambarkan tentang bagaimana menggunakan peristiwa dalam Visual Basic. In object oriented programming events refers to occurrences or happening. Dalam pemrograman berorientasi objek acara mengacu pada kejadian atau peristiwa. For example when the user clicks a command button and the program will display the message “Hello World!” after clicking the button. Sebagai contoh ketika pengguna mengklik tombol perintah dan program akan menampilkan pesan "Hello World!" Setelah mengklik tombol. In that case, the event use is the click event of the command button. Dalam hal ini, penggunaan event adalah peristiwa klik tombol perintah. In our sample Visual Basic code below we have use three events . Dalam Visual Basic kita kode contoh di bawah ini kami telah menggunakan tiga acara. We use the click event of the command button and the GotFocus and LostFucos event of the text field. Kami menggunakan event klik tombol perintah dan dan LostFucos acara GotFocus bidang teks. 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.
When a Visual Basic program is run, a form and its controls appear on the screen. Ketika Visual Basic program dijalankan, bentuk dan kontrol yang muncul di layar. Normally, nothing happens until the user takes an action, such as clicking a control or pressing the Tab key. Biasanya, tidak ada yang terjadi sampai pengguna mengambil tindakan, seperti mengklik kontrol atau menekan tombol Tab. Such an action is called an event. 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.
Code consists of statements that carry out tasks. Kode terdiri dari pernyataan yang melaksanakan tugas. Visual Basic has a repertoire of over Visual Basic memiliki lebih dari repertoar
200 statements and we will use many of them in this text. 200 laporan dan kami akan menggunakan banyak dari mereka dalam teks ini. In this section, we limit ourselves to statements that change properties of objects while a program is running. Pada bagian ini, kami membatasi diri atas laporan bahwa perubahan sifat benda saat program sedang berjalan.
Properties of an object are changed in code with statements of the form Sifat obyek berubah dalam kode dengan pernyataan dalam bentuk
objectName.property = setting objectName.property = Pengaturan
where objectName is the name of the form or a control, property is one of the properties of the object, and setting is a valid setting for that object. 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:
statements laporan
End Sub End Sub
Tidak ada komentar:
Posting Komentar