Rabu, 07 April 2010

Bilangan Prima














Coding Program Prima

Private Sub cmd_proses_Click()

If Val(Text1.Text) = 1 Then

Text2.Text = "Bukan Prima"

ElseIf Val(Text1.Text) = 2 Then

Text2.Text = "Prima"

Else

For i = 2 To Val(Text1.Text) - 1

If Val(Text1.Text) Mod i = 0 Then

Text2.Text = "Bukan Prima"

Exit For

Else

Text2.Text = "Prima"

End If

Next

End If

cmd_proses.Enabled = False

cmd_ulang.Enabled = True

End Sub

Private Sub cmd_ulang_Click()

Text1.Text = ""

Text2.Text = ""

cmd_proses.Enabled = True

cmd_ulang.Caption = False

Text1.SetFocus

End Sub

Private Sub cmd_keluar_Click()

Unload Me

End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii >= 65 And KeyAscii <= 90 Or KeyAscii >= 97 And KeyAscii <= 122 Then

KeyAscii = 0

KeyAscii = 0

End If

If KeyAscii = 13 Then

cmd_proses.SetFocus

End If

End Sub

1 komentar: