Semua dipelajari mulai dari ilmu yang paling dasar

Jumat, 29 Oktober 2010

Contoh Pemrograman Visual Basic .Net

13.38 Posted by fajar No comments
Contoh program sederhana dalam bahasa Visual Basic .NET yang dipakai untuk menghitung jumlah pembayaran dari m_item buah barang dengan harga m_price per item ditambah 5% pajak penjualan:

Dim m_item, m_price, tax, total As double
m_item = double.Parse(textBox1.Text)
m_price = double.Parse(textBox2.Text)
tax = 0.05
total = m_item * m_price * (1 + tax)
label5.Text = total.ToString()
MessageBox.Show("Well Done.")

Berikut ini adalah contoh lain dari program Visual Basic yang menggunakan objek CheckBox dan ComboBox untuk menghitung jumlah kredit mata kuliah yang diambil oleh seorang mahasiswa (masing-masing mata kuliah = 3 kredit):

Dim total As Integer
total = 0 ' awal dari jumlah kredit total
If (CheckBox1.Checked = True) Then 'boleh memilih semua checkbox
total += 3
End If
If (CheckBox2.Checked = True) Then
total = total + 3
End If
If (CheckBox3.Checked = True) Then
total = total + 3
End If
If (ComboBox1.SelectedIndex = 0) Then 'hanya bisa memilih satu
total = total + 3
ElseIf (ComboBox1.SelectedIndex = 1) Then
total = total + 3
ElseIf (ComboBox1.SelectedIndex = 2) Then
total = total + 3
End If
Label3.Text = CStr(total) ' hasil kredit total yang diambil

Sumber: http://id.wikipedia.org/wiki/Visual_Basic_.NET
.

0 komentar:

Posting Komentar