1. Program to check whether a number is odd or even.
CONTROL PROPERTIES VALUE
Text1 name Text1 Text (blank) Text2 name Text2 Text (blank) Command1 name cmdevenodd Caption Even / odd Command2 name cmdend caption End
Private Sub cmdevenodd_Click()
Dim n As Integer n = Val(Text1.Text) If (n Mod 2) = 0 Then Text2.Text = "Even number" Else Text2.Text = "Odd number" End If End Sub
Private Sub cmdend_Click()
End End Sub 1. Program to find sum of natural numbers up to a given number.
CONTROL PROPERTIES VALUE
Text1 name Text1 Text (blank) Text2 name Text2 Text (blank) Command1 name cmdnatsum Caption Sum of natural numbers Command2 name cmdend caption end
Private Sub cmdnatsum_Click()
Dim n, i, sum As Integer n = Val(Text1.Text) Print "natural numbers are" For i = 1 To n sum = sum + i print i Next i Text2.Text = sum End Sub
Private Sub cmdend_Click()
End End Sub 2. Program to find Factorial of a given number.
CONTROL PROPERTIES VALUE
Text1 name Text1 Text (blank) Text2 name Text2 Text (blank) Command1 name cmdfact Caption factorial Command2 name cmdend caption end
Private Sub cmdfact_Click()
Dim n, i, fact As Integer n = Val(Text1.Text) fact = 1 If (n < 0) Then MsgBox ("No factorial for -ve numbers") Else For i = 1 To n fact = fact * i Next i Text2.Text = fact End If End Sub Private Sub cmdend_Click() End End Sub
3. Program to find sum of individual digits of a number.
CONTROL PROPERTIES VALUE
Text1 name Text1 Text (blank) Text2 name Text2 Text (blank) Command1 name cmddigits Caption Sum of individual digits Command2 name cmdend caption end Private Sub cmddigits_Click() Dim n, sum, digit As Integer n = Val(Text1.Text) sum = 0 Do While (n <> 0) digit = n Mod 10 sum = sum + digit n = n \ 10 Loop Text2.Text = sum End Sub
Private Sub cmdend_Click()
End End Sub
2. Program to check whether a number is Palindrome or not.
CONTROL PROPERTIES VALUE
Text1 name Text1 Text (blank) Text2 name Text2 Text (blank) Command1 name cmdpal Caption Palindrome or not Command2 name cmdend caption end Private Sub cmdpal_Click() Dim digit, temp, n, rev As Integer n = Val(Text1.Text) temp = n rev = 0 Do While (n <> 0) digit = n Mod 10 rev = rev * 10 + digit n = n \ 10 Loop Text2.Text = rev If (temp = rev) Then MsgBox ("Number is a palindrome") Else MsgBox ("Number is not a palindrome") End If End Sub