Wednesday, February 17, 2016

Memberi Nama pada Objek : Visual Basic-Visual Studio 2015

Properti yang seharusnya anda tentukan pertama saat membuat objek baru adalah nama / Name. Tekan tombol F4 untuk menampilkan jendela Properties (jika belum tampil), dan gulung ke atas sampai terlihat properti (Name), seperti terlihat pada gambar berikut.


Jika properti Name tidak terlihat pada awal listbox, itu dikarenakan jendela Properties diatur untuk menampilkan properties berdasar kategori bukan urut alphabet instead of alphabetically. Anda dapat menampilkan list urut alphabet dengan cara klik tombol Alphabetical di atas grid properties.

I recommend that you keep the Properties window set to show properties in alphabetic order; doing so makes it easier to find properties that I refer to in the text. Note that the Name property always stays toward the top of the list and is called (Name). If you’re wondering why it has parentheses around it, it’s because symbols come before letters in an alphabetic sort, and this keeps the Name property at the top of the list.
Saat menyimpan sebuah project, anda juga memilih nama dan lokasi untuk menyimpan project dan file-file pendukungnya. Ketika anda pertama kali membuat objek dalam project, Visual Basic memberi sebuah nama object yang unik dan generik berdasar jenis objek. Walau nama-nama tersebut tetap berfungsi, namun kurang deskriptif secara praktis. Contoh, Visual Basic menamai form dengan nama Form1, padahal biasanya ada belasan (bahkan ratusan) forms dalam sebuah project. Akan sangat sulit untuk mengelola sebuah project jika setiap fomr dibedakan berdasar penomoran (Form2, Form3, dan seterusnya).
Agar pengelolan form lebih rapi, berikan setiap form nama yang deskriptif. Tidak hanya mengubah nama form saja tapi penting juga untuk mengubah nama file. Ubahlah nama form secara program dan juga nama file dengan langkah-langkah berikut:
  1. Klik properti Name dan ubah tulisan Form1 menjadi ViewerForm. Ketahuilah bahwa hal ini tidak mengubah nama file dari form tersebut seperti yang terlihat dalam jendela Solution Explorer, terletak di atas jendela Properties.
  2. Klik kanan pada Form1.vb dalam jendela Solution Explorer.
  3. Pilih menu Rename pada context menu yang tampil.
  4. Ubah tulisan dari Form1.vb menjadi ViewerForm.vb.
I use the Form suffix here to denote that the file is a form class. Suffixes are optional, but I find that they really help you keep things organized. 
The form’s Name property is actually changed for you automatically when you rename the file.In future examples, I will have you rename the form file so that the Name property is changed automatically. I had you set it in the Properties window here so that you could see how the Properties window works. 

No comments:

Post a Comment