Langkah-Langkah
1. Buka
Microsoft Visual Basic 2010
2. Klik FILE ->New Project ->
Windows Forms Aplication -> pada Name isikan : WindowsAplication1-> OK
3. Buatlah
Desaint pada form1
No
|
Tools
|
Properties
|
Nilai
|
1
|
GrupBox1
|
Text
|
Jenis Bilangan
|
2
|
GrupBox2
|
Text
|
Hasil
|
3
|
GrupBox3
|
Text
|
Perhitungan
|
4
|
ComboBox
|
Items
|
|
5
|
ListBox
|
Name
|
Bilangan
|
6
|
TextBox1
|
Name
|
Txtbilsatu
|
7
|
TextBox1
|
Name
|
Txtbildua
|
8
|
TextBox1
|
Name
|
Txthasil
|
9
|
Button1
|
Text
Name
|
Input Bilangan
btnInputBil
|
10
|
Button2
|
Text
Name
|
Exit
btnExit
|
Sehingga tampilannya menjadi seperti
gambar dibawah ini :
4. Klik 2X pada Button1 (btnInputBil),
lalu isikan koding seperti berikut :
Private Sub btnInputBil_Click(sender As
System.Object, e As System.EventArgs) Handles btnInputBil.Click
Dim strGanjil, strGenap, strPrima, strFibo As Integer
proses(strGanjil, strGenap, strPrima, strFibo)
ShowSum(txtbilsatu.Text, txtbildua.Text)
End Sub
Dim strGanjil, strGenap, strPrima, strFibo As Integer
proses(strGanjil, strGenap, strPrima, strFibo)
ShowSum(txtbilsatu.Text, txtbildua.Text)
End Sub
5. Lalu tambahkan koding koding ini di
bagian halaman kodingnya, (dibawah koding no.4)
Sub ShowSum(ByVal intNum1 As Integer, ByVal intNum2 As Integer)
Dim intSum As Integer
Dim intSum As Integer
intSum = intNum1 + intNum2
txthasil.Text = intSum
End Sub
End Sub
Sub proses(ByVal strGanjil As String, ByVal strGenap As String, ByVal strPrima
As String, ByVal strFibo As String)
If (ComboBox1.SelectedIndex.Equals(0)) Then
BilGanjil()
If (ComboBox1.SelectedIndex.Equals(0)) Then
BilGanjil()
ElseIf (ComboBox1.SelectedIndex.Equals(1)) Then
BilGenap()
BilGenap()
ElseIf (ComboBox1.SelectedIndex.Equals(2)) Then
BilPrima()
BilPrima()
ElseIf (ComboBox1.SelectedIndex.Equals(3)) Then
BilFibo()
End If
End Sub
BilFibo()
End If
End Sub
Sub BilGanjil()
Dim ganjil As Integer
bilangan.Items.Clear()
ganjil = 1
Do While ganjil <= 20
bilangan.Items.Add(ganjil)
ganjil = ganjil + 2
Loop
End Sub
Dim ganjil As Integer
bilangan.Items.Clear()
ganjil = 1
Do While ganjil <= 20
bilangan.Items.Add(ganjil)
ganjil = ganjil + 2
Loop
End Sub
Sub BilGenap()
Dim genap As Integer
bilangan.Items.Clear()
genap = 0
Do While genap <= 20
bilangan.Items.Add(genap)
genap = genap + 2
Loop
End Sub
Dim genap As Integer
bilangan.Items.Clear()
genap = 0
Do While genap <= 20
bilangan.Items.Add(genap)
genap = genap + 2
Loop
End Sub
Sub BilPrima()
Dim prima As Integer
Dim prima As Integer
bilangan.Items.Clear()
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim y As Integer
Dim z As Integer
For x = 2 To 100
z = 0
For y = 2 To x
prima = x Mod y
If prima = 0 Then
z = z + 1
End If
Next y
If z <= 1 Then
bilangan.Items.Add(x)
End If
Next x
End Sub
z = 0
For y = 2 To x
prima = x Mod y
If prima = 0 Then
z = z + 1
End If
Next y
If z <= 1 Then
bilangan.Items.Add(x)
End If
Next x
End Sub
Sub BilFibo()
bilangan.Items.Clear()
Dim a As Integer = 0
Dim b As Integer = 1
Dim fib As Integer = 0
bilangan.Items.Clear()
Dim a As Integer = 0
Dim b As Integer = 1
Dim fib As Integer = 0
bilangan.Items.Add(“1″)
Do
fib = a + b
a = b
b = fib
bilangan.Items.Add(fib.ToString)
Loop While fib <= 100
End Sub
Do
fib = a + b
a = b
b = fib
bilangan.Items.Add(fib.ToString)
Loop While fib <= 100
End Sub
6. Klik 2X
pada Button2 (btnExit), lalu isikan koding seperti berikut :
Private
Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles
btnExit.Click
Me.Close()
Me.Close()
End Sub
7. Selesai, maka setelah itu jalankan programnya dengan menekan tombol F5. Maka
seperti ini lah hasil program yang kita buat. Lihat gambar. Maka hasilnya jika
kita menekan tombol “Input Bilangan” maka hasilnya akan jalan 2 2 nya.
Hasilnya :
Tidak ada komentar:
Posting Komentar