Senin, 21 Maret 2011

Membuat Form Daftar

Pada kali ini saya akan membuat sebuah Form Pendaftaran . Untuk pertama kita buat dahulu Form Utama seperti gambar di bawah ini




















Setelah selesai membuat Form di atas selanjutnya kita isi dengan Code dan Method untuk setiap Button dan TextBox.
Pertama kita Double Klik pada Form kemudian ubah Method menjadi “ Activated” Code nya seperti di bawah ini.

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Call bersih()
Call isicombo()

End Sub

Sebelumnya kita buat dulu sebuah Method dengan nama “ bersih “ bertujuan untuk membersihkan isi dari TextBox setelah selesai pengisian. Selanjutnya kita buat Method juga untuk mengisi ComboBox dengan nama “ isicombo” di bawah ini adalah Code nya yang diisi dengan menyesuiakan isi dari ComboBox

Sub bersih()
TextBox1.Text = ""

TextBox2.Text = ""

TextBox3.Text = ""

TextBox4.Text = ""

ComboBox1.Text = " Teknik Infomatika"
End Sub

Sub isicombo()
ComboBox1.Items.Add("05 Teknik Informatika")
ComboBox1.Items.Add("04 Sistem Informasi")
ComboBox1.Items.Add("02 Teknik Komputer")
ComboBox1.Items.Add("03 Komputer Akutansi ")
ComboBox1.Items.Add("01 Manajemen Informatika")

End Sub

Setelah selesai mengisi codennya di lanjutkan dengan membuat Event pada Button yang sudah di buat . Pada Button “ Tambah “ kita masukkan Codenya pertama kita buat dahulu Method dengan nama “ normal” bertujuan untuk Refresh kembali Button yang lainnya berikut codenya

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "Tambah" Then
Button1.Text = "Simpan"
Button2.Enabled = False
Button3.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
End If

End Sub

Pada Code diatas terlihat Ketika Button Tambah di Klik akan Berudah Menjadi Button Simpan .

Sub Normal()
Button1.Text = "Tambah"
Button1.Enabled = True
Button2.Text = "Ubah"
Button2.Enabled = True
Button3.Text = "Hapus"
Button3.Enabled = True
Button4.Text = "Keluar"
End Sub

Diatas terlihat pada code ada True dan False untuk “ True” setiap perintah yang benar akan di kerjakan dan untuk “False” Button menjadi tidak Aktif.

Selanjutnya berlanjut pada Button Keluar berikut Codenya

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "Batal" Then


Call Normal()
Call bersih()
Else
Me.Close()
End If
End Sub
Perintah Me.Close diatas untuk keluar dari Menu Utama sebelumnya akan memanggil Method Normal bertujuan untuk Menormalkan kembali Button menjadi Aktif dan Method Bersih bertujuan untuk membarsihkan isi dari TextBox yang telah diisi. Saat ini Menu belum berjalan sempurna karena beberapa Event belum di masukkan . Hasil Output Formnya




















Sampai Jumpa di Episode Selanjutnya ………………

Cara Membuat Modul

Pada kesempatan kali ini saya akan membuat sebuah fungsi dengan sebuah Modul yang berguna untuk membuat Variabel Public lalu buat form seperti gambar di bawah ini .




















Setelah selesai membuat Form utama kemudian pada Button 1 masukkan Source Code seperti di bawah ini .

Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
h = TextBox1.Text
b = TextBox2.Text
Call hitung()
TextBox3.Text = hasil
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call tampilnama()
TextBox4.Text = nama
End Sub

Setelah selesai memasukkan Code diatas selanjut kita membuat Modul yang di dalamnya terdapat Variabel Public yang bisa digunakan untuk semua Form berikut langkah - langkahnya : Klik Kanan pada Project kemudian Add pilih Module kemudian Pilih Add kembali.























Setelah selesai Memasukkan Modul kemudian masukkan Source Code pada Modul yang sudah di buat yang nantinya akan di panggil di Menu Utama. Untuk proses hitung yang digunakan adalah Proses perkalian.

Module Module1
'variabel public
Public nama As String, hasil, h, b As Integer
Sub tampilnama()
nama = "Farhan Abdurrahman"

End Sub
Sub hitung()
hasil = Val(h) * Val(b)

End Sub
End Module

Setelah selesai semua Source Codenya di masukan berikut hasil outputnya :

Menghitung Nilai Hasil Bagi

Pada Kesempatan kali ini saya akan membuat perhitungan bilangan yang dapat habis di bagi 9 dan 27 serta menampilkan bilangan sisa hasil bagi 3 dari pembagi 2 dari bilangan 1 sampai 100. Adapun yang pertama dilakukan adalah buat Form utama seperti di bawah ini





















Gambar 1 . Form Utama
Kemudian untuk Button Proses 1 berikut adalah Sourcodenya :
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, y, z As Integer
x = 9
y = 27

For z = 1 To Val(TextBox1.Text)
If z Mod x = 0 Then
If z Mod y = 0 Then
ListBox1.Items.Add(z)
End If

End If
Next
End Sub
Setelah Button Proses 1 selesai kemudian di lanjutkan dengan Button Proses 2 berikut Sourcodenya :
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim a As Integer
ListBox1.Items.Clear()
For a = 1 To Val(TextBox1.Text)
If a Mod 2 = 1 Then
ListBox1.Items.Add(a)
End If
Next
End Sub

Untuk hasil dari Form dan Code yang di buat sebagai berikut di bawah ini

Pindah Data Dengan Enter

Pada Kali ini saya akan membuat sebuah FORM yang di dalamnya memuat beberapa Fungsi yaitu fungsi “ENTER “ untuk pindah kolom dan Mempilkan SIngkatan terlebih dahulu buat Form sebagai berikut















Untuk Teksbox Masukan berikut Codenya
Public Class Form1
Dim jurusan As String
Dim kelas, jenjang As String, waktu As Integer
Dim d As Integer = 5
Untuk Proses Button 1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call perintah()
End Sub
Untuk Proses Butto n
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call perintah()
End Sub
Kemudian isikan Code Berikut ini untuk menampilkan hasil singkatan
Sub perintah()
Dim lo As String
If TextBox1.Text = "TI" Then
lo = "06"
TextBox2.Text = "Tekhnik Informatika"
Else
If TextBox1.Text = "SI" Then
TextBox2.Text = "Sistem Informasi"
End If
End If
End Sub
Untuk Mengisi Data 1 sampai dengan 4 pada Button Proses 3
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
ListBox1.Items.Add(TextBox3.Text + " " & TextBox4.Text & " " & TextBox5.Text & " " & TextBox6.Text & " " & TextBox7.Text)
End Sub
Sub pros3()
ListBox1.Items.Add(TextBox3.Text + "" & TextBox4.Text & "" & TextBox5.Text & "" & TextBox6.Text & "" & TextBox7.Text)
End Sub
Untuk Proses input data dengan “ Enter” dengan terlebih dahulu mengganti Method dengan Key Press. Untuk Teksbox lainnya disesuaikan dengan mengganti Teksbox menjadi 4 ,5,6 dst.
Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
If e.KeyChar = Chr(13) Then
TextBox4.Focus()
End If
End Sub

Membuat Event Pada VB.Net

Pada Kesempatan Kali ini saya akan membuat Sebuah Event Show Name Pertama buat Form seperti ini




















Kemudian Untuk Source Codenya sebagai Berikut :
Fungsi NIM
Public Class Form1
Private WithEvents mhs As New Mahasiswa("43A87006090120", "Farhan Abdurrahman")

Private Sub RefreshData() Handles mhs.UbahData
TextBox1.Text = mhs.Nim
TextBox2.Text = mhs.Nama
End Sub
Untuk Ref res Data menggunakan code
Private Sub RefreshData() Handles mhs.UbahData
TextBox1.Text = mhs.Nim
TextBox2.Text = mhs.Nama
End Sub
Kemudian masukkan Fungsi TeksBox Ubah Nama sebagai berikut :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
mhs.Nama = TextBox3.Text
End Sub
Kemudian untuk Fungsi Untuk Input NIM sebagai berikut
Public Class Mahasiswa
Public Event UbahData()
Private _nim As String
Public Property Nim() As String
Get
Return _nim
End Get
Set(ByVal value As String)
_nim = value
End Set
End Property

Kemuduian untuk Fungsi NAMA sebagai berikut :
Public Property Nama() As String
Get
Return _nama
End Get
Set(ByVal value As String)
_nama = value
RaiseEvent UbahData()
End Set
End Property

Public Sub New(ByVal nim As String, _
ByVal nama As String)
Me.Nim = nim
Me.Nama = nama
End Sub
End Class

Selasa, 22 Februari 2011

Materi VB Beserta Contohnya

Pengenalan Program Dan IDE
Mengenal Visual Basic (VB)
Visual Basic adalah salah satu bahasa pemrograman komputer. Bahasa pemrograman adalah perintahperintah yang dimengerti oleh komputer untuk melakukan tugas-tugas tertentu. Bahasa pemrograman Visual Basic, yang dikembangkan oleh Microsoft sejak tahun 1991, merupakan pengembangan dari pendahulunya yaitu bahasa pemrograman BASIC (Beginner’s All-purpose Symbolic Instruction Code) yang dikembangkan pada era 1950-an. Visual Basic merupakan salah satu Development Tool yaitu alat bantu untuk membuat berbagai macam program komputer, khususnya yang menggunakan sistem operasi Windows. Visual Basic merupakan salah satu bahasa pemrograman komputer yang mendukung object (Object Oriented Programming = OOP)
Mengenal Integrated Development Environment (IDE) VB 6
Aktifkan VB 6 melalui tombol Start > Programs > Microsoft Visual Studio 6.0 > Microsoft Visual Basic 6
�� Menubar
�� Toolbar
�� Toolbox
Bila Toolbox tidak muncul klik tombol Toolbox ( ) pada bagian Toolbar atau klik menu
View > Toolbox.
�� Jendela Form
Bila Jendela Form tidak muncul klik tombol View Object ( ) pada bagian Project Explorer atau
klik menu View > Object.
�� Jendela Code
Bila Jendela Code tidak muncul klik tombol View Code ( ) di pada bagian Project Explorer atau
klik menu View > Code.
�� Project Explorer
Bila Project Explorer tidak muncul klik tombol Project Explorer ( ) pada bagian
Toolbar atau klik menu View > Project Explorer.
�� Jendela Properties
Bila Jendela Properties tidak muncul klik tombol Properties Window ( ) pada bagian Toolbar
atau klik menu View > Properties Window.
Memahami Istilah Object, Property, Method dan Event
Dalam pemrograman berbasis obyek (OOP), anda perlu memahami istilah object, property, method dan event sebagai berikut :
Object : komponen di dalam sebuah program
Property : karakteristik yang dimiliki object
Method : aksi yang dapat dilakukan oleh object
Event : kejadian yang dapat dialami oleh object
Object : Mobil
Property :
Merek:
Toyota, Type: sedan Warna: merah
Method :
Maju,Mundur,Berhenti
Event :
Pintu dibuka, Ditabrak, Didorong
Object : Form
Property :
BackColor, BorderStyle, Caption
Method :
Hide,Move,Show
Event :
Click, Load, Resize
Implementasinya dalam sebuah aplikasi misalnya anda membuat form, maka form tersebut memiliki property, method, dan event. Sebagaimana pemrograman visual lain seperti Delphi daan Java, VB juga bersifat event driven progamming. Artinya anda dapat menyisipkan kode program pada event yang dimiliki suatu obyek

Variabel Data Type Data
Mengenal Data dan Variabel
Ketika seorang user (pengguna) menggunakan sebuah program komputer, seringkali komputermemintanya untuk memberikan informasi. Informasi ini kemudian disimpan atau diolah oleh komputer.Informasi inilah yang disebut dengan DATA.Visual Basic 6 mengenal beberapa type data, antara lain :
�� String adalah type data untuk teks (huruf, angka dan tanda baca).
�� Integer adalah type data untuk angka bulat.
�� Single adalah type data untuk angka pecahan.
�� Currency adalah type data untuk angka mata uang.
�� Date adalah type data untuk tanggal dan jam.
�� Boolean adalah type data yang bernilai TRUE atau FALSE.
Data yang disimpan di dalam memory komputer membutuhkan sebuah wadah. Wadah inilah yangdisebut dengan VARIABEL. Setiap variabel untuk menyimpan data dengan type tertentu membutuhkanalokasi jumlah memory (byte) yang berbeda.Variabel dibuat melalui penulisan deklarasi variabel di dalam kode program :Dim As Contoh : Dim nama_user As String Aturan di dalam penamaan variabel :
�� Harus diawali dengan huruf.
�� Tidak boleh menggunakan spasi. Spasi bisa diganti dengan karakter underscore (_).
�� Tidak boleh menggunakan karakter-karakter khusus (seperti : +, -, *, /, <, >, dll).
�� Tidak boleh menggunakan kata-kata kunci yang sudah dikenal oleh VB(seperti : dim, as,string, integer, dll).Sebuah variabel hanya dapat menyimpan satu nilai data sesuai dengan type datanya. Cara mengisi nilai data ke dalam sebuah variabel : = Contoh : nama_user = “krisna”Untuk type data tertentu nilai_data harus diapit tanda pembatas. Type data string dibatasi tanda petikganda : “nilai_data”. Type data date dibatasi tanda pagar : #nilai_data#. Type data lainnya tidak perlu tanda pembatas.Sebuah variabel mempunyai ruang-lingkup (scope) dan waktu-hidup (lifetime) :
�� Variabel global adalah variabel yang dapat dikenali oleh seluruh bagian program. Nilai data yangtersimpan didalamnya akan hidup terus selama program berjalan.
�� Variabel lokal adalah variabel yang hanya dikenali oleh satu bagian program saja. Nilai data yangtersimpan didalamnya hanya hidup selama bagian program tersebut dijalankan.Variabel yang nilai datanya bersifat tetap dan tidak bisa diubah disebut KONSTANTA. Penulisandeklarasi konstanta di dalam kode program :
Const As = Contoh : Const tgl_gajian As Date = #25/09/2003#

Fungsi Percabangan
Mengenal Struktur Kontrol
Perintah Percabangan Dan Penggunaan Objek
Struktur kontrol di dalam bahasa pemrograman adalah perintah dengan bentuk (struktur) tertentu yangdigunakan untuk mengatur (mengontrol) jalannya program.Visual Basic 6 mengenal dua jenis struktur kontrol, yaitu :
1. Struktur kontrol keputusan - digunakan untuk memutuskan kode program mana yang akandikerjakan berdasarkan suatu kondisi. Akan dibahas pada bab ini.
2. Struktur kontrol pengulangan - digunakan untuk melakukan pengulangan kode program. Akandibahas pada bab selanjutnya. Ada dua bentuk struktur kontrol keputusan, yaitu :
1. Struktur IF…THEN. Akan dibahas pada bab ini.
2. Struktur SELECT…CASE. Akan dibahas pada bab selanjutnya. Bentuk penulisan (syntax) struktur IF…THEN :
1. IF THEN
Bila bernilai True maka akan dikerjakan.
2. IF THEN

ELSE

END IF
Bila bernilai True maka akan dikerjakan, tetapi bila bernilai False maka yang akan dikerjakan.
1.2 Struktur Kontrol Select…Case
Bentuk penulisan (syntax) struktur SELECT…CASE :
SELECT CASE
CASE

CASE

CASE
[
CASE ELSE]
END SELECT
Bila sesuai dengan maka akan dikerjakan, dst. Tetapi bila tidak ada yang sesuai dengan s/d maka yang akan dikerjakan

Perintah Perulangan Dan Penggunaan Objek Lain
Mengenal Struktur Kontrol
Perintah Perulangan Dan Penggunaan Objek lain

Struktur kontrol di dalam bahasa pemrograman adalah perintah dengan bentuk (struktur) tertentu yang digunakan untuk mengatur (mengontrol) jalannya program. Visual Basic 6 mengenal dua jenis struktur kontrol, yaitu :
1. Struktur kontrol keputusan - digunakan untuk memutuskan kode program mana yang akandikerjakan berdasarkan suatu kondisi. Sudah dibahas pada bab lalu.
2. Struktur kontrol pengulangan - digunakan untuk melakukan pengulangan kode program. Akandibahas pada bab ini.
Ada dua bentuk struktur kontrol pengulangan (looping), yaitu :
1. Struktur FOR…NEXT.
2. Struktur DO…LOOP.
Struktur Kontrol For…Next
Bentuk penulisan (syntax) struktur For…Next :
FOR = TO [STEP ]

NEXT
�� adalah variabel (tipe: integer) yang digunakan untuk menyimpan angka pengulangan.
�� adalah nilai awal dari .
�� adalah nilai akhir dari .
�� adalah perubahan nilai setiap pengulangan. Sifatnya optional (boleh ditulisataupun tidak). Bila tidak ditulis maka nilai adalah 1.
Struktur Kontrol Do…Loop
Bentuk penulisan (syntax) struktur Do…Loop :
1. DO WHILE

LOOP
akan diulang selama bernilai TRUE. Pengulangan berhenti bila sudah bernilai FALSE.
2. DO UNTIL

LOOP
akan diulang sampai bernilai TRUE. Pengulangan berhenti bila sudah bernilai TRUE.

Pengenalan Procedure Dan Function
Apa itu Procedure ?

Procedure adalah blok kode program yang berisi perintah-perintah untuk mengerjakan tugas tertentu. Bila di dalam kode program yang kita buat ada perintah-perintah untuk melakukan tugas yang sama di beberapa tempat, maka akan lebih baik perintah-perintah tersebut dibuat dalam sebuah procedure. Kemudian, procedure itu bisa di-‘panggil’ bila diperlukan. Penggunaan procedure sangat menghemat penulisan kode program, karena kode-kode program yang sama dibeberapa tempat cukup dibuat pada satu bagian saja. Selain itu, procedure akan memudahkan perbaikan kode program bila terjadi perubahan atau kesalahan, karena perbaikan cukup dilakukan pada satu bagian saja.

Jenis-jenis Procedure
Pada VB6 ada 4 jenis procedure, yaitu :
��Procedure Sub – procedure yang tidak mengembalikan nilai setelah ‘tugas’-nya selesai.
��Procedure Function – procedure yang mengembalikan nilai setelah ‘tugas’-nya selesai.
��Procedure Event – procedure untuk suatu event pada sebuah object. Digunakan di dalam class module.
��Procedure Property – procedure untuk mengubah (let) atau mengambil (get) nilai property pada sebuah object. Digunakan di dalam class module.
Pada bab ini akan dibahas penggunaan procedure sub dan function. Procedure event dan property akan dibahas pada bab selanjutnya. Bentuk penulisan (syntax) procedure sub :
[Public | Private] Sub ([])



End Sub
Sedangkan bentuk penulisan (syntax) procedure function :
[Public | Private] Function ([]) As



End Function Pernyataan [Public | Private] menentukan ruang lingkup (scope) procedure. Sebuah procedure dengan scope public bisa digunakan dalam lingkup project. Sedangkan procedure dengan scope private hanya bisa digunakan dalam lingkup form saja.
atau dibuat sebagai pengenal procedure saat di-‘panggil’. Aturan penamaan sebuah procedure sama dengan aturan penamaan sebuah variabel. Nama sebuah procedure dibuat unik, tidak boleh ada yang sama.
merupakan serangkaian nilai dan tipe data yang dipakai oleh procedure untuk mengerjakan ‘tugas’-nya. Sebuah procedure bisa saja tidak memakai argumen sama sekali.
Pernyataan As pada procedure function menentukan tipe data nilai yang akan dikembalikan (return value) setelah ‘tugas’-nya selesai. Untuk menggunakan sebuah procedure, maka procedure tersebut harus di-‘panggil’ pada bagian tertentu dari kode program. Procedure sub di-‘panggil’ dengan pernyataan :
Call ([])
Sedangkan procedure function bisa di-‘panggil’ langsung dengan menyisipkannya di dalam kode program yang memanggilnya
Array
Apa itu Array ?
Array merupakan sekumpulan nilai data yang “dikelompokkan” dalam sebuah variabel. Array digunakan bila ada beberapa nilai data yang tipe datanya sama dan akan mendapat perlakuan yang sama pula. Misalnya, ada 10 nilai data dengan tipe string dan akan diolah dengan cara yang sama, maka akan lebih mudah jika menggunakan sebuah array dibandingkan bila menggunakan 10 variabel yang berbeda. Setiap nilai data di dalam sebuah array disebut elemen array dan masing-masing dibedakan dengan nomer indeksnya.

Menggunakan Array
Sebuah array dideklarasikan dengan cara yang sama dengan variabel, yaitu menggunakan perintah Dim, kemudian diikuti dengan tanda kurung dan jumlah
Dim nama_array(jumlah_elemen – 1) As tipe_data
Contoh :
Dim NamaSiswa(99) As String
�� array NamaSiswa akan mempunyai elemen sebanyak 100 dengannomer indeks mulai dari 0 s/d 99.
Selanjutnya untuk mengisi nilai data ke dalam array :
nama_array(no_indeks) = nilai_data
Contoh :
NamaSiswa(0) = “umar”Namasiswa(1) = “fatimah”
Untuk “mengosongkan” nilai data, bisa menggunakan struktur kontrol For…Next :
For i = 0 To 99
NamaSiswa(i) = “”
Next i
Lebih mudah bukan ?
Catatan :
�� Agar nomer indeks array dimulai dari 1 (bukan 0), bisa menggunakan perintah Option Base 1
sebelum perintah Dim-nya, contoh :
Option Base 1
Dim NamaSiswa(100) As String
�� Atau bisa juga menggunakan kata To di dalam penentuan jumlah elemen array, contoh :
Dim NamaSiswa(1 To 100) As String
�� Untuk mengetahui berapa jumlah elemen di dalam sebuah array, bisa menggunakan perintah
Ubound(nama_array), contoh :
Dim NamaSiswa(1 To 100) As String
Dim JmlElemen As Integer
JmlElemen = Ubound(NamaSiswa) �� hasilnya = 100
�� Bila jumlah elemen array yang dibutuhkan tidak diketahui atau ingin bisa diubah-ubah, maka bagian jumlah_elemen pada perintah Dim tidak perlu diisi, contoh :
Dim NamaSiswa() As String
Teknik ini biasa disebut sebagai array dinamis, biasanya untuk mengisi data yang berkembang terus, danbelum bisa ditentukan di awal jumlah elemennya.
�� Untuk mengubah jumlah elemen array digunakan perintah Redim :
Redim [Preserve] nama_array(jumlah_elemen)
Contoh :
Redim NamaSiswa(1 To 150)
�� jumlah elemen array NamaSiswa menjadi 150 dengan nomer indeks dari 1 s/d 150.

Selasa, 15 Februari 2011

Sejara Visual Basic .NET

Visual Basic .NET (VB.NET) is an object-oriented computer programming language that can be viewed as an evolution of the classic Visual Basic (VB) which is implemented on the .NET Framework. Microsoft currently supplies two major implementations of Visual Basic: Microsoft Visual Studio, which is commercial software and Microsoft Visual Studio Express, which is free of charge.
Contents
[hide]

* 1 Versions
o 1.1 Visual Basic .NET (VB 7)
o 1.2 Visual Basic .NET 2003 (VB 7.1)
o 1.3 Visual Basic 2005 (VB 8.0)
+ 1.3.1 'IsNot' operator patented
o 1.4 Visual Basic 2008 (VB 9.0)
o 1.5 Visual Basic 2010 (VB 10.0)
* 2 Relation to older versions of Visual Basic (VB6 and previous)
o 2.1 Comparative samples
* 3 Criticism
* 4 Cross-platform and open-source development
* 5 Examples
* 6 See also
* 7 References
* 8 Further reading
* 9 External links

[edit] Versions

There are four versions and five releases of Visual Basic .NET implemented by the Visual Basic Team.
[edit] Visual Basic .NET (VB 7)

The original Visual Basic .NET was released alongside Visual C# and ASP.NET in 2002. Significant changes broke backward compatibility with older versions and caused a rift within the developer community.[2]
[edit] Visual Basic .NET 2003 (VB 7.1)

Visual Basic .NET 2003 was released with version 1.1 of the .NET Framework. New features included support for the .NET Compact Framework and a better VB upgrade wizard. Improvements were also made to the performance and reliability of the .NET IDE (particularly the background compiler) and runtime. In addition, Visual Basic .NET 2003 was available in the Visual Studio .NET Academic Edition (VS03AE). VS03AE is distributed to a certain number of scholars from each country without cost.
[edit] Visual Basic 2005 (VB 8.0)

Visual Basic 2005 is the name used to refer to the Visual Basic .NET, Microsoft having decided to drop the .NET portion of the title.

For this release, Microsoft added many features, including:

* Edit and Continue
* Design-time expression evaluation.
* The My pseudo-namespace (overview, details), which provides:
o easy access to certain areas of the .NET Framework that otherwise require significant code to access
o dynamically-generated classes (notably My.Forms)
* Improvements to the VB-to-VB.NET converter [3]
* The Using keyword, simplifying the use of objects that require the Dispose pattern to free resources
* Just My Code, which when debugging hides (steps over) boilerplate code written by the Visual Studio .NET IDE and system library code
* Data Source binding, easing database client/server development

The above functions (particularly My) are intended to reinforce Visual Basic .NET's focus as a rapid application development platform and further differentiate it from C#.

Visual Basic 2005 introduced features meant to fill in the gaps between itself and other "more powerful" .NET languages, adding:

* .NET 2.0 languages features such as:
o generics [4]
o Partial classes, a method of defining some parts of a class in one file and then adding more definitions later; particularly useful for integrating user code with auto-generated code
o Nullable Types
* [5]
* Support for unsigned integer data types commonly used in other languages

[edit] 'IsNot' operator patented

One other feature of Visual Basic 2005 is the IsNot operator that makes 'If X IsNot Y' equivalent to 'If Not X Is Y', which gained notoriety[6] when it was found to be the subject of a Microsoft patent application.[7][8]
[edit] Visual Basic 2008 (VB 9.0)

Visual Basic 9.0 was released together with the Microsoft .NET Framework 3.5 on 19 November 2007.

For this release, Microsoft added many features, including:

* A true conditional operator, "If(boolean, value, value)", to replace the "IIf" function.
* Anonymous types
* Support for LINQ
* Lambda expressions
* XML Literals
* Type Inference
* Extension methods

[edit] Visual Basic 2010 (VB 10.0)

In April 2010, Microsoft released Visual Basic 2010. Microsoft had planned to use the Dynamic Language Runtime (DLR) for that release[9] but shifted to a co-evolution strategy between Visual Basic and sister language C# to bring both languages into closer parity with one another. Visual Basic's innate ability to interact dynamically with CLR and COM objects has been enhanced to work with dynamic languages built on the DLR such as IronPython and IronRuby.[10] The Visual Basic compiler was improved to infer line continuation in a set of common contexts, in many cases removing the need for the " _" line continuation character. Also, existing support of inline Functions was complemented with support for inline Subs as well as multi-line versions of both Sub and Function lambdas.[11]
[edit] Relation to older versions of Visual Basic (VB6 and previous)

Whether Visual Basic .NET should be considered as just another version of Visual Basic or a completely different language is a topic of debate. This is not obvious, as once the methods that have been moved around and that can be automatically converted are accounted for, the basic syntax of the language has not seen many "breaking" changes, just additions to support new features like structured exception handling and short-circuited expressions. Two important data type changes occurred with the move to VB.NET. Compared to VB6, the Integer data type has been doubled in length from 16 bits to 32 bits, and the Long data type has been doubled in length from 32 bits to 64 bits. This is true for all versions of VB.NET. A 16-bit integer in all versions of VB.NET is now known as a Short. Similarly, the Windows Forms GUI editor is very similar in style and function to the Visual Basic form editor.

The version numbers used for the new Visual Basic (7, 7.1, 8, 9, ...) clearly imply that it is viewed by Microsoft as still essentially the same product as the old Visual Basic.

The things that have changed significantly are the semantics—from those of an object-based programming language running on a deterministic, reference-counted engine based on COM to a fully object-oriented language backed by the .NET Framework, which consists of a combination of the Common Language Runtime (a virtual machine using generational garbage collection and a just-in-time compilation engine) and a far larger class library. The increased breadth of the latter is also a problem that VB developers have to deal with when coming to the language, although this is somewhat addressed by the My feature in Visual Studio 2005.

The changes have altered many underlying assumptions about the "right" thing to do with respect to performance and maintainability. Some functions and libraries no longer exist; others are available, but not as efficient as the "native" .NET alternatives. Even if they compile, most converted VB6 applications will require some level of refactoring to take full advantage of the new language. Documentation is available to cover changes in the syntax, debugging applications, deployment and terminology.[12]
[edit] Comparative samples

The following simple example demonstrates similarity in syntax between VB and VB.NET. Both examples pop up a message box saying "Hello, World" with an OK button.

Private Sub Command1_Click()
MsgBox "Hello, World"
End Sub

A VB.NET example, MsgBox or the MessageBox class can be used:

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Msgbox("Hello, World")
End Sub
End Class

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("Hello, World")
End Sub
End Class

* Both Visual Basic 6 and Visual Basic .NET will automatically generate the Sub and End Sub statements when the corresponding button is clicked in design view. Visual Basic .NET will also generate the necessary Class and End Class statements. The developer need only add the statement to display the "Hello, World" message box.
* Note that all procedure calls must be made with parentheses in VB.NET, whereas in VB6 there were different conventions for functions (parentheses required) and subs (no parentheses allowed, unless called using the keyword Call).
* Also note that the names Command1 and Button1 are not obligatory. However, these are default names for a command button in VB6 and VB.NET respectively.
* In VB.NET, the Handles keyword is used to make the sub Button1_Click a handler for the Click event of the object Button1. In VB6, event handler subs must have a specific name consisting of the object's name ("Command1"), an underscore ("_"), and the event's name ("Click", hence "Command1_Click").
* There is a function called MsgBox in the Microsoft.VisualBasic namespace which can be used similarly to the corresponding function in VB6. There is a controversy about which function to use as a best practice (not only restricted to showing message boxes but also regarding other features of the Microsoft.VisualBasic namespace). Some programmers prefer to do things "the .NET way", since the Framework classes have more features and are less language-specific. Others argue that using language-specific features makes code more readable (for example, using int (C#) or Integer (VB.NET) instead of System.Int32).
* In VB 2008, the inclusion of ByVal sender as Object, ByVal e as EventArgs has become optional.

The following example demonstrates a difference between VB6 and VB.NET. Both examples close the active window.

Classic VB Example:

Sub cmdClose_Click()
Unload Me
End Sub

A VB.NET example:

Sub btnClose_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
Me.Close()
End Sub

Note the 'cmd' prefix being replaced with the 'btn' prefix, conforming to the new convention previously mentioned.

Visual Basic 6 did not provide common operator shortcuts. The following are equivalent:

VB6 Example:

Sub Timer1_Timer()
Me.Height = Me.Height - 1
End Sub

VB.NET example:

Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
Me.Height -= 1
End Sub

[edit] Criticism

Long-time Visual Basic users have complained about Visual Basic .NET because initial versions dropped a large number of language constructs and user interface features that were available in VB6 (which is no longer sold by Microsoft), and changed the semantics of those that remained; for example, in VB.NET parameters are (by default) passed by value, not by reference. Detractors refer pejoratively to VB.NET as Visual Fred or DOTNOT.[13] On 8 March 2005, a petition[14] was set up in response to Microsoft's refusal to extend its mainstream support[15] for VB6.

VB.NET's supporters state that the new language is in most respects more powerful than the original, incorporating modern object oriented programming paradigms in a more natural, coherent and complete manner than was possible with earlier versions. Opponents tend to respond that although VB6 has flaws in its object model, the cost in terms of redevelopment effort is too high for any benefits that might be gained by converting to VB.NET.[citation needed]

It is simpler to decompile languages that target Common Intermediate Language (CIL), including VB.NET, compared to languages that compile to machine code. Tools such as .NET Reflector can provide a close approximation to the original code due to the large amount of metadata provided in CIL.[citation needed]

Microsoft supplies an automated VB6-to-VB.NET converter with Visual Studio .NET, which has improved over time, but it cannot convert all code, and almost all non-trivial programs will need some manual effort to compile. Most will need a significant level of code refactoring to work optimally. Visual Basic programs that are mainly algorithmic in nature can be migrated with few difficulties; those that rely heavily on such features as database support, graphics, unmanaged operations or on implementation details are more troublesome.[citation needed]

In addition, the required runtime libraries for VB6 programs are provided with Windows 98 SE and above, while VB.NET programs require the installation of the significantly larger .NET Framework. The framework is included with Windows 7, Windows Vista, Windows XP Media Center Edition, Windows XP Tablet PC Edition, Windows Server 2008 and Windows Server 2003. For other supported operating systems such as Windows 2000 or Windows XP (Home or Professional Editions), it must be separately installed.

Microsoft's response to developer dissatisfaction has focused around making it easier to move new development and shift existing codebases from VB6 to VB.NET. Their latest offering is the VBRun website[dead link], which offers code samples and articles for:

* Using VB.NET to complete tasks that were common in VB6, like creating a print preview
* Integrating VB6 and VB.NET solutions (dubbed VB Fusion)

[edit] Cross-platform and open-source development

The creation of open-source tools for VB.NET development have been slow compared to C#, although the Mono development platform provides an implementation of VB.NET-specific libraries and a VB.NET 8.0 compatible compiler written in VB.NET,[16] as well as standard framework libraries such as Windows Forms GUI library.

SharpDevelop and MonoDevelop are open-source alternative IDEs.
[edit] Examples

The following is a very simple VB.NET program, a version of the classic "Hello world" example created as a console application:

Module Module1

Sub Main()
Console.WriteLine("Hello, world!")
End Sub

End Module

The effect is to write the text Hello, world! to the command line. Each line serves a specific purpose, as follows:

Module Module1

This is a module definition, a division of code similar to a class, although modules can contain classes. Modules serve as containers of code that can be referenced from other parts of a program.[17]
It is common practice for a module and the code file, which contains it, to have the same name; however, this is not required, as a single code file may contain more than one module and/or class definition.

Sub Main()

This is the entry point where the program begins execution.[18] Sub is an abbreviation of "subroutine."

Console.WriteLine("Hello, world!")

This line performs the actual task of writing the output. Console is a system object, representing a command-line interface and granting programmatic access to the operating system's standard streams. The program calls the Console method WriteLine, which causes the string passed to it to be displayed on the console. Another common method is using MsgBox (a Message Box).[19]

This piece of code is a solution to Floyd's Triangle:

Module Module1

Sub Main()

'//input validation
Dim rows As Integer = 0
Do Until rows > 0
Console.Write("Enter a value for how many rows to be displayed: ")
If Not Integer.TryParse(Console.ReadLine(), rows) OrElse rows < 1 Then
Console.WriteLine("Allowed range is 1 and {0}", Integer.MaxValue)
End If
Loop

'//output
Dim current As Integer = 1
Dim row As Integer = 1
Do Until row = rows + 1
If current = row * (row + 1) \ 2 Then
Console.WriteLine(current)
row += 1
Else
Console.Write("{0} ", current)
End If
current += 1
Loop

'//wait for exit
Console.ReadLine()
End Sub

End Module