Senin, 14 Oktober 2013

Membuat Program Mencari Rata-rata Bilangan Ganjil/Genap dengan Input Nilai Awal dan Akhir Menggunakan Visual Basic

Desain Form



Source Code

Private Sub cmdkeluar_Click()
End
End Sub

Private Sub cmdulang_Click()
Txt1.SetFocus
Txt1.Text = ""
Txt2.Text = ""
Opsiganjil.Value = False
Opsigenap.Value = False
cboperulangan = "Pilih Jenis Perulangan"
lbljumlah.Caption = ""
lblrata.Caption = ""
List1.Clear
End Sub

Private Sub Cboperulangan_click()
Dim awal, akhir As String
Dim jum, rata As Double
awal = Txt1.Text
akhir = Txt2.Text
If awal = "" And akhir = "" Then
MsgBox "NILAI AWAL DAN NILAI AKHIR BELUM ANDA INPUTKAN !!!"
ElseIf awal = "" Or akhir = "" Then
MsgBox "NILAI AWAL ATAU NILAI AKHIR BELUM ANDA INPUTKAN !!!"
ElseIf Opsiganjil.Value = False And Opsigenap.Value = False Then
MsgBox "PILIHAN BILANGAN BELUM DIPILIH !!!"
ElseIf cboperulangan = "For" And Opsiganjil.Value = True Then
List1.Clear
If awal <= akhir Then
For i = awal To akhir
If i Mod 2 = 1 Then
List1.AddItem i
jum = jum + i
awal = awal + 2
n = n + 1
End If
Next i
rata = jum / n
lbljumlah.Caption = jum
lblrata.Caption = rata
ElseIf awal > akhir Then
MsgBox "nilai awal harus kurang dari nilai akhir"
End If

ElseIf cboperulangan = "Do While" And Opsiganjil.Value = True Then
List1.Clear
If awal <= akhir Then
Do
If awal Mod 2 = 1 Then
List1.AddItem (awal)
n = n + 1
jum = jum + awal
End If
awal = awal + 1
Loop While awal <= akhir
rata = jum / n
lbljumlah.Caption = jum
lblrata.Caption = rata
ElseIf awal > akhir Then
MsgBox "nilai awal harus kurang dari nilai akhir"
End If

ElseIf cboperulangan = "Do Until" And Opsiganjil.Value = True Then
List1.Clear
If awal <= akhir Then
Do
If awal Mod 2 = 1 Then
List1.AddItem (awal)
n = n + 1
jum = jum + awal
End If
awal = awal + 1
Loop Until awal > akhir
rata = jum / n
lbljumlah.Caption = jum
lblrata.Caption = rata
ElseIf awal > akhir Then
MsgBox "nilai awal harus kurang dari nilai akhir"
End If

ElseIf cboperulangan = "For" And Opsigenap.Value = True Then
List1.Clear
If awal <= akhir Then
For i = awal To akhir
If i Mod 2 = 0 Then
List1.AddItem i
jum = jum + i
m = m + i
n = n + 1
End If
Next i
rata = jum / n
lbljumlah.Caption = jum
lblrata.Caption = rata
ElseIf awal > akhir Then
MsgBox "nilai awal harus kurang dari nilai akhir"
End If

ElseIf cboperulangan = "Do While" And Opsigenap.Value = True Then
List1.Clear
If awal <= akhir Then
Do
If awal Mod 2 = 0 Then
List1.AddItem (awal)
n = n + 1
jum = jum + awal
End If
awal = awal + 1
Loop While awal <= akhir
rata = jum / n
lbljumlah.Caption = jum
lblrata.Caption = rata
ElseIf awal > akhir Then
MsgBox "nilai awal harus kurang dari nilai akhir"
End If

ElseIf cboperulangan = "Do Until" And Opsigenap.Value = True Then
List1.Clear
If awal <= akhir Then
Do
If awal Mod 2 = 0 Then
List1.AddItem (awal)
n = n + 1
jum = jum + awal
End If
awal = awal + 1
Loop Until awal > akhir
rata = jum / n
lbljumlah.Caption = jum
lblrata.Caption = rata
ElseIf awal > akhir Then
MsgBox "nilai awal harus kurang dari nilai akhir"
End If

End If
End Sub

Private Sub Form_Load()
cboperulangan.AddItem "For"
cboperulangan.AddItem "Do While"
cboperulangan.AddItem "Do Until"
End Sub

SILAHKAN DOWNLOAD PROGRAMNYA DISINI

0 komentar:

Posting Komentar

You can replace this text by going to "Layout" and then "Page Elements" section. Edit " About "

Baca Selengkapnya Di : http://indonesianblog-jmk.blogspot.com/2012/06/cara-membuat-komentar-admin-berbeda.html#ixzz2kb6khEJE