Monday, June 14, 2010

NUMBER APPLICATION

Buzz It
AIM:To display whole,even,odd,prime and Fibonacci numbers upto a limit


CODE

Form 1
Dim num As Long, temp As String
Private Sub clear_Click()
display.Text = ""
End Sub
Private Sub even_Click()
display.Text = ""
temp = ""
If limit.Text = "" Then
MsgBox "please enter a number"
Exit Sub
End If
For num = 2 To CLng(limit.Text) Step 2
temp = temp & Str(num)
Next num
display.Text = temp
End Sub
Private Sub exit_Click()
End
End Sub
Private Sub fibonacci_Click()
Dim a, b, c As Long, temp As String
display.Text = ""
temp = ""
a = 1: b = 0
If limit.Text = "" Then
MsgBox "please enter a number"
Exit Sub
End If

For num = 1 To CLng(limit.Text)
c=a+b
a=b
b=c
If c >= CLng(limit.Text) Then Exit For
temp = temp & Str(c)
Next num
display.Text = temp
End Sub
Private Sub odd_Click()
Dim num As Long, temp As String
display.Text = ""
temp = ""
If limit.Text = "" Then
MsgBox "please enter a number"
Exit Sub
End If
For num = 1 To CLng(limit.Text) Step 2
temp = temp & Str(num)
Next num
display.Text = temp
End Sub
Private Sub prime_Click()
Dim i, j As Long, temp As String, flag As Boolean
display.Text = ""
temp = ""
If limit.Text = "" Then
MsgBox "please enter a number "
Exit Sub
End If

For i = 2 To CLng(limit.Text)
flag = True
For j = 2 To Sqr(i)
If i Mod j = 0 Then
flag = False
Exit For
End If
Next j
If flag Then temp = temp & Str(i)
Next i
display.Text = temp
End Sub
Private Sub whole_Click()
Dim num As Long, temp As String
display.Text = ""
temp = ""
If limit.Text = "" Then
MsgBox "please enter a number"
Exit Sub
End If
For num = 1 To CLng(limit.Text)
temp = temp & Str(num)
Next num
display.Text = temp
End Sub


0 comments:

Post a Comment